Browse code

image/cache: fix isValidParent logic

Signed-off-by: Antonio Murdaca <runcom@redhat.com>

Antonio Murdaca authored on 2017/02/21 01:16:11
Showing 2 changed files
... ...
@@ -187,7 +187,7 @@ func isValidParent(img, parent *image.Image) bool {
187 187
 	if len(parent.History) >= len(img.History) {
188 188
 		return false
189 189
 	}
190
-	if len(parent.RootFS.DiffIDs) >= len(img.RootFS.DiffIDs) {
190
+	if len(parent.RootFS.DiffIDs) > len(img.RootFS.DiffIDs) {
191 191
 		return false
192 192
 	}
193 193
 
... ...
@@ -5421,6 +5421,27 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) {
5421 5421
 	c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody")
5422 5422
 }
5423 5423
 
5424
+func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) {
5425
+	dockerfile := `
5426
+		FROM busybox
5427
+		RUN echo "test"
5428
+		ENTRYPOINT ["sh"]`
5429
+	ctx := fakeContext(c, dockerfile, map[string]string{
5430
+		"Dockerfile": dockerfile,
5431
+	})
5432
+	defer ctx.Close()
5433
+
5434
+	buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx))
5435
+	id1 := getIDByName(c, "build1")
5436
+
5437
+	// rebuild with cache-from
5438
+	result := buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx))
5439
+	result.Assert(c, icmd.Success)
5440
+	id2 := getIDByName(c, "build2")
5441
+	c.Assert(id1, checker.Equals, id2)
5442
+	c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
5443
+}
5444
+
5424 5445
 func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
5425 5446
 	testRequires(c, DaemonIsLinux) // All tests that do save are skipped in windows
5426 5447
 	dockerfile := `