Skip to content

Commit

Permalink
Merge pull request moby#31189 from runcom/fix-build-cache-from
Browse files Browse the repository at this point in the history
image/cache: fix isValidParent logic
  • Loading branch information
LK4D4 authored Feb 21, 2017
2 parents 19795b9 + 1cf4b2b commit 093867b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion image/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 21 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := `
Expand Down

0 comments on commit 093867b

Please sign in to comment.