image/cache: fix isValidParent logic

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-02-20 17:16:11 +01:00
parent 75843d36aa
commit 1cf4b2b8bd
No known key found for this signature in database
GPG Key ID: B2BEAD150DE936B9
2 changed files with 22 additions and 1 deletions

View File

@ -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
}

View File

@ -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 := `