Browse code

integration-cli: add build test for NOCACHE

This patch adds CLI integration tests to ensure that NOCACHE instructions
in Dockerfiles only apply to direct children of the original image.

Docker-DCO-1.1-Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> (github: cyphar)

cyphar authored on 2014/06/17 15:04:25
Showing 1 changed files
... ...
@@ -588,6 +588,7 @@ func TestBuildRm(t *testing.T) {
588 588
 	logDone("build - ensure --rm doesn't leave containers behind and that --rm=true is the default")
589 589
 	logDone("build - ensure --rm=false overrides the default")
590 590
 }
591
+
591 592
 func TestBuildWithVolumes(t *testing.T) {
592 593
 	name := "testbuildvolumes"
593 594
 	expected := "map[/test1:map[] /test2:map[]]"
... ...
@@ -766,6 +767,68 @@ func TestBuildEntrypoint(t *testing.T) {
766 766
 	logDone("build - entrypoint")
767 767
 }
768 768
 
769
+// #6445 ensure ONBUILD triggers aren't committed to grandchildren
770
+func TestBuildOnBuildLimitedInheritence(t *testing.T) {
771
+	name1 := "testonbuildtrigger1"
772
+	dockerfile1 := `
773
+		FROM busybox
774
+		RUN echo "GRANDPARENT"
775
+		ONBUILD RUN echo "ONBUILD PARENT"
776
+	`
777
+	ctx1, err := fakeContext(dockerfile1, nil)
778
+	if err != nil {
779
+		t.Fatal(err)
780
+	}
781
+
782
+	buildCmd := exec.Command(dockerBinary, "build", "-t", name1, ".")
783
+	buildCmd.Dir = ctx1.Dir
784
+	out1, _, err := runCommandWithOutput(buildCmd)
785
+	errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out1, err))
786
+	defer deleteImages(name1)
787
+
788
+	name2 := "testonbuildtrigger2"
789
+	dockerfile2 := `
790
+		FROM testonbuildtrigger1
791
+	`
792
+	ctx2, err := fakeContext(dockerfile2, nil)
793
+	if err != nil {
794
+		t.Fatal(err)
795
+	}
796
+
797
+	buildCmd = exec.Command(dockerBinary, "build", "-t", name2, ".")
798
+	buildCmd.Dir = ctx2.Dir
799
+	out2, _, err := runCommandWithOutput(buildCmd)
800
+	errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out2, err))
801
+	defer deleteImages(name2)
802
+
803
+	name3 := "testonbuildtrigger3"
804
+	dockerfile3 := `
805
+		FROM testonbuildtrigger2
806
+	`
807
+	ctx3, err := fakeContext(dockerfile3, nil)
808
+	if err != nil {
809
+		t.Fatal(err)
810
+	}
811
+
812
+	buildCmd = exec.Command(dockerBinary, "build", "-t", name3, ".")
813
+	buildCmd.Dir = ctx3.Dir
814
+	out3, _, err := runCommandWithOutput(buildCmd)
815
+	errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out3, err))
816
+	defer deleteImages(name3)
817
+
818
+	// ONBUILD should be run in second build.
819
+	if !strings.Contains(out2, "ONBUILD PARENT") {
820
+		t.Fatalf("ONBUILD instruction did not run in child of ONBUILD parent")
821
+	}
822
+
823
+	// ONBUILD should *not* be run in third build.
824
+	if strings.Contains(out3, "ONBUILD PARENT") {
825
+		t.Fatalf("ONBUILD instruction ran in grandchild of ONBUILD parent")
826
+	}
827
+
828
+	logDone("build - onbuild")
829
+}
830
+
769 831
 func TestBuildWithCache(t *testing.T) {
770 832
 	name := "testbuildwithcache"
771 833
 	defer deleteImages(name)