From 1e746a8a2b2f8a88903feca430f254605dcc6cc8 Mon Sep 17 00:00:00 2001 From: AnandkumarPatel Date: Tue, 24 Feb 2015 18:16:57 -0800 Subject: [PATCH 1/3] Set UtilizeCache to false on cache miss Signed-off-by: Anandkumar Patel Signed-off-by: AnandkumarPatel --- builder/internals.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/internals.go b/builder/internals.go index 9668c5f3a3..54e2fe3bea 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -512,6 +512,8 @@ func (b *Builder) probeCache() (bool, error) { return true, nil } else { log.Debugf("[BUILDER] Cache miss") + // after a miss we no longer need to probe + b.UtilizeCache = false } } return false, nil From 2420c1f03bba2c90d2406e486974cdc0c8af0cea Mon Sep 17 00:00:00 2001 From: AnandkumarPatel Date: Wed, 25 Feb 2015 10:27:32 -0800 Subject: [PATCH 2/3] Add cacheBusted flag which gets set on the first cache miss Refactor of probeCache function Signed-off-by: AnandkumarPatel --- builder/evaluator.go | 1 + builder/internals.go | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/builder/evaluator.go b/builder/evaluator.go index 3ce5f0926f..eaf3f50697 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -90,6 +90,7 @@ type Builder struct { Verbose bool UtilizeCache bool + cacheBusted bool // controls how images and containers are handled between steps. Remove bool diff --git a/builder/internals.go b/builder/internals.go index 54e2fe3bea..e554fd3026 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -502,21 +502,24 @@ func (b *Builder) processImageFrom(img *imagepkg.Image) error { // `(true, nil)`. If no image is found, it returns `(false, nil)`. If there // is any error, it returns `(false, err)`. func (b *Builder) probeCache() (bool, error) { - if b.UtilizeCache { - if cache, err := b.Daemon.ImageGetCached(b.image, b.Config); err != nil { - return false, err - } else if cache != nil { - fmt.Fprintf(b.OutStream, " ---> Using cache\n") - log.Debugf("[BUILDER] Use cached version") - b.image = cache.ID - return true, nil - } else { - log.Debugf("[BUILDER] Cache miss") - // after a miss we no longer need to probe - b.UtilizeCache = false - } + if !b.UtilizeCache || b.cacheBusted { + return false, nil } - return false, nil + + cache, err := b.Daemon.ImageGetCached(b.image, b.Config) + if err != nil { + return false, err + } + if cache == nil { + log.Debugf("[BUILDER] Cache miss") + b.cacheBusted = true + return false, nil + } + + fmt.Fprintf(b.OutStream, " ---> Using cache\n") + log.Debugf("[BUILDER] Use cached version") + b.image = cache.ID + return true, nil } func (b *Builder) create() (*daemon.Container, error) { From 1a5ea50aa81112c745030b3cf421a9baebcdb9f5 Mon Sep 17 00:00:00 2001 From: AnandkumarPatel Date: Wed, 25 Feb 2015 14:04:35 -0800 Subject: [PATCH 3/3] Remove comment and b.UtilizeCache check. Signed-off-by: AnandkumarPatel --- builder/internals.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/internals.go b/builder/internals.go index e554fd3026..f6b929f2b6 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -187,8 +187,8 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp if err != nil { return err } - // If we do not have at least one hash, never use the cache - if hit && b.UtilizeCache { + + if hit { return nil }