diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 351595966..1b2cf06ff 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -92,8 +92,8 @@ func addKanikoOptionsFlags(cmd *cobra.Command) { RootCmd.PersistentFlags().BoolVarP(&opts.Reproducible, "reproducible", "", false, "Strip timestamps out of the image to make it reproducible") RootCmd.PersistentFlags().StringVarP(&opts.Target, "target", "", "", "Set the target build stage to build") RootCmd.PersistentFlags().BoolVarP(&opts.NoPush, "no-push", "", false, "Do not push the image to the registry") - RootCmd.PersistentFlags().StringVarP(&opts.Cache, "cache", "", "", "Specify a registry to use as a cache, otherwise one will be inferred from the destination provided") - RootCmd.PersistentFlags().BoolVarP(&opts.UseCache, "use-cache", "", true, "Use cache when building image") + RootCmd.PersistentFlags().StringVarP(&opts.CacheRepo, "cache-repo", "", "", "Specify a repository to use as a cache, otherwise one will be inferred from the destination provided") + RootCmd.PersistentFlags().BoolVarP(&opts.Cache, "cache", "", false, "Use cache when building image") } // addHiddenFlags marks certain flags as hidden from the executor help text diff --git a/integration/images.go b/integration/images.go index 61fc6a7ac..cf1f90105 100644 --- a/integration/images.go +++ b/integration/images.go @@ -178,7 +178,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do } } - cacheFlag := "--use-cache=false" // build kaniko image additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...) kanikoImage := GetKanikoImage(imageRepo, dockerfile) @@ -189,7 +188,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do ExecutorImage, "-f", path.Join(buildContextPath, dockerfilesPath, dockerfile), "-d", kanikoImage, reproducibleFlag, - cacheFlag, contextFlag, contextPath}, additionalFlags...)..., ) @@ -204,10 +202,12 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do } // buildCachedImages builds the images for testing caching via kaniko where version is the nth time this image has been built -func (d *DockerFileBuilder) buildCachedImages(imageRepo, cache, dockerfilesPath string, version int) error { +func (d *DockerFileBuilder) buildCachedImages(imageRepo, cacheRepo, dockerfilesPath string, version int) error { _, ex, _, _ := runtime.Caller(0) cwd := filepath.Dir(ex) + cacheFlag := "--cache=true" + for dockerfile := range d.TestCacheDockerfiles { kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version) kanikoCmd := exec.Command("docker", @@ -218,7 +218,8 @@ func (d *DockerFileBuilder) buildCachedImages(imageRepo, cache, dockerfilesPath "-f", path.Join(buildContextPath, dockerfilesPath, dockerfile), "-d", kanikoImage, "-c", buildContextPath, - "--cache", cache})..., + cacheFlag, + "--cache-repo", cacheRepo})..., ) if _, err := RunCommandWithoutTest(kanikoCmd); err != nil { diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 198ec6651..69682ba48 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -57,7 +57,7 @@ func RetrieveLayer(opts *config.KanikoOptions, cacheKey string) (v1.Image, error // Destination returns the repo where the layer should be stored // If no cache is specified, one is inferred from the destination provided func Destination(opts *config.KanikoOptions, cacheKey string) (string, error) { - cache := opts.Cache + cache := opts.CacheRepo if cache == "" { destination := opts.Destinations[0] destRef, err := name.NewTag(destination, name.WeakValidation) diff --git a/pkg/config/options.go b/pkg/config/options.go index 3c84fa7bb..c9bad39e6 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -24,7 +24,7 @@ type KanikoOptions struct { Bucket string TarPath string Target string - Cache string + CacheRepo string Destinations multiArg BuildArgs multiArg InsecurePush bool @@ -32,5 +32,5 @@ type KanikoOptions struct { SingleSnapshot bool Reproducible bool NoPush bool - UseCache bool + Cache bool } diff --git a/pkg/executor/build.go b/pkg/executor/build.go index b4f794d0b..49313900b 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -153,7 +153,7 @@ func (s *stageBuilder) build(opts *config.KanikoOptions) error { if err != nil { return errors.Wrap(err, "getting key") } - if command.CacheCommand() && opts.UseCache { + if command.CacheCommand() && opts.Cache { image, err := cache.RetrieveLayer(opts, cacheKey) if err == nil { if err := s.extractCachedLayer(image, command.String()); err != nil { @@ -212,7 +212,7 @@ func (s *stageBuilder) build(opts *config.KanikoOptions) error { return err } // Push layer to cache now along with new config file - if command.CacheCommand() && opts.UseCache { + if command.CacheCommand() && opts.Cache { if err := pushLayerToCache(opts, cacheKey, layer, command.String()); err != nil { return err }