diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index e7ad4c498..a42925905 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -199,6 +199,7 @@ func addKanikoOptionsFlags() { 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().BoolVarP(&opts.NoPushCache, "no-push-cache", "", false, "Do not push the cache layers to the registry") 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().StringVarP(&opts.CacheDir, "cache-dir", "", "/cache", "Specify a local directory to use as a cache.") RootCmd.PersistentFlags().StringVarP(&opts.DigestFile, "digest-file", "", "", "Specify a file to save the digest of the built image to.") diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 1506f5553..db03374d2 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -420,7 +420,7 @@ func (s *stageBuilder) build() error { logrus.Debugf("build: cache key for command %v %v", command.String(), ck) // Push layer to cache (in parallel) now along with new config file - if command.ShouldCacheOutput() { + if command.ShouldCacheOutput() && ! s.opts.NoPushCache { cacheGroup.Go(func() error { return s.pushLayerToCache(s.opts, ck, tarPath, command.String()) }) diff --git a/pkg/executor/push.go b/pkg/executor/push.go index 9f75305e5..a76c2a1d2 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -78,9 +78,13 @@ var ( // push to every specified destination. func CheckPushPermissions(opts *config.KanikoOptions) error { targets := opts.Destinations - // When no push is set, whe want to check permissions for the cache repo + // When no push and no push cache are set, we don't need to check permissions + if opts.NoPush && opt.noPushCache { + targets = []string{} + } + // When no push is set, we want to check permissions for the cache repo // instead of the destinations - if opts.NoPush { + else if opts.NoPush && ! opt.noPushCache { targets = []string{opts.CacheRepo} }