From 1cf4b2b8bd92562ffe8d7cce8a705efb3ef32ba7 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Mon, 20 Feb 2017 17:16:11 +0100 Subject: [PATCH] image/cache: fix isValidParent logic Signed-off-by: Antonio Murdaca --- image/cache/cache.go | 2 +- integration-cli/docker_cli_build_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/image/cache/cache.go b/image/cache/cache.go index 4b5b764835..e074bebccd 100644 --- a/image/cache/cache.go +++ b/image/cache/cache.go @@ -187,7 +187,7 @@ func isValidParent(img, parent *image.Image) bool { if len(parent.History) >= len(img.History) { return false } - if len(parent.RootFS.DiffIDs) >= len(img.RootFS.DiffIDs) { + if len(parent.RootFS.DiffIDs) > len(img.RootFS.DiffIDs) { return false } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index b4484247c1..3aaf067533 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5421,6 +5421,27 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) { c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody") } +func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) { + dockerfile := ` + FROM busybox + RUN echo "test" + ENTRYPOINT ["sh"]` + ctx := fakeContext(c, dockerfile, map[string]string{ + "Dockerfile": dockerfile, + }) + defer ctx.Close() + + buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx)) + id1 := getIDByName(c, "build1") + + // rebuild with cache-from + result := buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + id2 := getIDByName(c, "build2") + c.Assert(id1, checker.Equals, id2) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) +} + func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { testRequires(c, DaemonIsLinux) // All tests that do save are skipped in windows dockerfile := `