From 82fe355f14f8236a7c109fc4669604942345340e Mon Sep 17 00:00:00 2001 From: Anurag Goel <59905+anurag@users.noreply.github.com> Date: Wed, 6 Feb 2019 08:16:09 -0800 Subject: [PATCH] Fix issues with layer caching, noPush and tarPath (#549) * Set TarPath to empty when pushing a layer * Fix issues with layer caching, noPush and tarPath. - Layer caching should work even when tarPath is specified, so this commit changes the value of tarPath to empty when caching layers. - When an image is built with just the tarPath and noPush is true, we should still create the tarBall (which wasn't happening before this commit). * Set no-push to false for cache layers * Remove extra log * go-imports fix --- pkg/executor/push.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/executor/push.go b/pkg/executor/push.go index 37e6a079d..0ee021f83 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -49,10 +49,6 @@ func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) { // DoPush is responsible for pushing image to the destinations specified in opts func DoPush(image v1.Image, opts *config.KanikoOptions) error { - if opts.NoPush { - logrus.Info("Skipping push to container registry due to --no-push flag") - return nil - } t := timing.Start("Total Push Time") destRefs := []name.Tag{} for _, destination := range opts.Destinations { @@ -71,6 +67,11 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error { return tarball.MultiWriteToFile(opts.TarPath, tagToImage) } + if opts.NoPush { + logrus.Info("Skipping push to container registry due to --no-push flag") + return nil + } + // continue pushing unless an error occurs for _, destRef := range destRefs { registryName := destRef.Repository.Registry.Name() @@ -135,6 +136,8 @@ func pushLayerToCache(opts *config.KanikoOptions, cacheKey string, tarPath strin return errors.Wrap(err, "appending layer onto empty image") } cacheOpts := *opts + cacheOpts.TarPath = "" // tarPath doesn't make sense for Docker layers + cacheOpts.NoPush = false // we want to push cached layers cacheOpts.Destinations = []string{cache} cacheOpts.InsecureRegistries = opts.InsecureRegistries cacheOpts.SkipTLSVerifyRegistries = opts.SkipTLSVerifyRegistries