Browse code

image/cache: fix isValidParent logic

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
(cherry picked from commit 1cf4b2b8bd92562ffe8d7cce8a705efb3ef32ba7)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Antonio Murdaca authored on 2017/02/21 01:16:11
Showing 2 changed files
... ...
@@ -215,7 +215,7 @@ func isValidParent(img, parent *image.Image) bool {
215 215
 	if len(parent.History) >= len(img.History) {
216 216
 		return false
217 217
 	}
218
-	if len(parent.RootFS.DiffIDs) >= len(img.RootFS.DiffIDs) {
218
+	if len(parent.RootFS.DiffIDs) > len(img.RootFS.DiffIDs) {
219 219
 		return false
220 220
 	}
221 221
 
... ...
@@ -7081,6 +7081,27 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) {
7081 7081
 	c.Assert(stdout, checker.Not(checker.Contains), "Step 2/2 : RUN nobody")
7082 7082
 }
7083 7083
 
7084
+func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) {
7085
+	dockerfile := `
7086
+		FROM busybox
7087
+		RUN echo "test"
7088
+		ENTRYPOINT ["sh"]`
7089
+	ctx, err := fakeContext(dockerfile, map[string]string{
7090
+		"Dockerfile": dockerfile,
7091
+	})
7092
+	c.Assert(err, checker.IsNil)
7093
+	defer ctx.Close()
7094
+
7095
+	id1, err := buildImageFromContext("build1", ctx, true)
7096
+	c.Assert(err, checker.IsNil)
7097
+
7098
+	// rebuild with cache-from
7099
+	id2, out, err := buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1")
7100
+	c.Assert(err, checker.IsNil)
7101
+	c.Assert(id1, checker.Equals, id2)
7102
+	c.Assert(strings.Count(out, "Using cache"), checker.Equals, 2)
7103
+}
7104
+
7084 7105
 func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
7085 7106
 	testRequires(c, DaemonIsLinux) // All tests that do save are skipped in windows
7086 7107
 	dockerfile := `