From 10b794b3328a8b8d8bcc094710cc3b59df500253 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Tue, 7 Jan 2014 09:15:04 +0100 Subject: [PATCH 1/2] Revert "Make sure the cache lookup returns always the same result" This reverts commit 1d4b7d8fa1af95ce83f263a49ed24e686fa7cb62. Docker-DCO-1.0-Signed-off-by: Sjoerd Langkemper (github: Sjord) --- server.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 2405380ea3..67d5266a30 100644 --- a/server.go +++ b/server.go @@ -22,7 +22,6 @@ import ( "path" "path/filepath" "runtime" - "sort" "strconv" "strings" "sync" @@ -1697,13 +1696,16 @@ func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error) } // Store the tree in a map of map (map[parentId][childId]) - imageMap := make(map[string][]string) + imageMap := make(map[string]map[string]struct{}) for _, img := range images { - imageMap[img.Parent] = append(imageMap[img.Parent], img.ID) + if _, exists := imageMap[img.Parent]; !exists { + imageMap[img.Parent] = make(map[string]struct{}) + } + imageMap[img.Parent][img.ID] = struct{}{} } - sort.Strings(imageMap[imgID]) + // Loop on the children of the given image and check the config - for _, elem := range imageMap[imgID] { + for elem := range imageMap[imgID] { img, err := srv.runtime.graph.Get(elem) if err != nil { return nil, err From 46c8b11f245204e9f6e1ae764b52911c327be1a9 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Wed, 1 Jan 2014 17:38:25 +0100 Subject: [PATCH 2/2] Fix issue #3375 - Return most recent image from the cache ImageGetCached searches for an image from the cache. Instead of returning the first image it finds, it should return the most recently created image. When a build with --no-cache then adds a new image with the same parameters, it is used instead of the old, existing image. Docker-DCO-1.0-Signed-off-by: Sjoerd Langkemper (github: Sjord) --- server.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 67d5266a30..3ad5122d25 100644 --- a/server.go +++ b/server.go @@ -1705,16 +1705,19 @@ func (srv *Server) ImageGetCached(imgID string, config *Config) (*Image, error) } // Loop on the children of the given image and check the config + var match *Image for elem := range imageMap[imgID] { img, err := srv.runtime.graph.Get(elem) if err != nil { return nil, err } if CompareConfig(&img.ContainerConfig, config) { - return img, nil + if match == nil || match.Created.Before(img.Created) { + match = img + } } } - return nil, nil + return match, nil } func (srv *Server) RegisterLinks(container *Container, hostConfig *HostConfig) error {