From a57298791c882a2a065989b3386b5b14084e8639 Mon Sep 17 00:00:00 2001 From: cyphar Date: Tue, 17 Jun 2014 16:04:25 +1000 Subject: [PATCH] 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 (github: cyphar) --- integration-cli/docker_cli_build_test.go | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 0837088322..9a360c1964 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -588,6 +588,7 @@ func TestBuildRm(t *testing.T) { logDone("build - ensure --rm doesn't leave containers behind and that --rm=true is the default") logDone("build - ensure --rm=false overrides the default") } + func TestBuildWithVolumes(t *testing.T) { name := "testbuildvolumes" expected := "map[/test1:map[] /test2:map[]]" @@ -766,6 +767,68 @@ func TestBuildEntrypoint(t *testing.T) { logDone("build - entrypoint") } +// #6445 ensure ONBUILD triggers aren't committed to grandchildren +func TestBuildOnBuildLimitedInheritence(t *testing.T) { + name1 := "testonbuildtrigger1" + dockerfile1 := ` + FROM busybox + RUN echo "GRANDPARENT" + ONBUILD RUN echo "ONBUILD PARENT" + ` + ctx1, err := fakeContext(dockerfile1, nil) + if err != nil { + t.Fatal(err) + } + + buildCmd := exec.Command(dockerBinary, "build", "-t", name1, ".") + buildCmd.Dir = ctx1.Dir + out1, _, err := runCommandWithOutput(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out1, err)) + defer deleteImages(name1) + + name2 := "testonbuildtrigger2" + dockerfile2 := ` + FROM testonbuildtrigger1 + ` + ctx2, err := fakeContext(dockerfile2, nil) + if err != nil { + t.Fatal(err) + } + + buildCmd = exec.Command(dockerBinary, "build", "-t", name2, ".") + buildCmd.Dir = ctx2.Dir + out2, _, err := runCommandWithOutput(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out2, err)) + defer deleteImages(name2) + + name3 := "testonbuildtrigger3" + dockerfile3 := ` + FROM testonbuildtrigger2 + ` + ctx3, err := fakeContext(dockerfile3, nil) + if err != nil { + t.Fatal(err) + } + + buildCmd = exec.Command(dockerBinary, "build", "-t", name3, ".") + buildCmd.Dir = ctx3.Dir + out3, _, err := runCommandWithOutput(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out3, err)) + defer deleteImages(name3) + + // ONBUILD should be run in second build. + if !strings.Contains(out2, "ONBUILD PARENT") { + t.Fatalf("ONBUILD instruction did not run in child of ONBUILD parent") + } + + // ONBUILD should *not* be run in third build. + if strings.Contains(out3, "ONBUILD PARENT") { + t.Fatalf("ONBUILD instruction ran in grandchild of ONBUILD parent") + } + + logDone("build - onbuild") +} + func TestBuildWithCache(t *testing.T) { name := "testbuildwithcache" defer deleteImages(name)