From 54635c3d39611d597bf2a7f46ff3ef92c29a77ce Mon Sep 17 00:00:00 2001 From: Cole Wippern Date: Wed, 27 Nov 2019 16:25:56 -0800 Subject: [PATCH] don't exit optimize early so we record cache keys --- pkg/executor/build.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 5415579313..c1d987120e 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -141,7 +141,7 @@ func (s *stageBuilder) optimize(compositeKey CompositeCache, cfg v1.Config) erro layerCache := &cache.RegistryCache{ Opts: s.opts, } - + stopCache := false // Possibly replace commands with their cached implementations. // We walk through all the commands, running any commands that only operate on metadata. // We throw the metadata away after, but we need it to properly track command dependencies @@ -167,13 +167,14 @@ func (s *stageBuilder) optimize(compositeKey CompositeCache, cfg v1.Config) erro return err } s.finalCacheKey = ck - if command.ShouldCacheOutput() { + if command.ShouldCacheOutput() && !stopCache { img, err := layerCache.RetrieveLayer(ck) if err != nil { logrus.Debugf("Failed to retrieve layer: %s", err) logrus.Infof("No cached layer found for cmd %s", command.String()) logrus.Debugf("Key missing was: %s", compositeKey.Key()) - break + stopCache = true + continue } if cacheCmd := command.CacheCommand(img); cacheCmd != nil {