diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index 31ff6a45ce..60ba39f8f6 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -791,6 +791,7 @@ func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time } // BuildImageCmdWithHost create a build command with the specified arguments. +// Deprecated // FIXME(vdemeester) move this away func BuildImageCmdWithHost(dockerBinary, name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd { args := []string{} diff --git a/integration-cli/docker_api_build_test.go b/integration-cli/docker_api_build_test.go index bbdb3de9b0..3a4353a87b 100644 --- a/integration-cli/docker_api_build_test.go +++ b/integration-cli/docker_api_build_test.go @@ -28,8 +28,7 @@ COPY * /tmp/ RUN find / -xdev -name ba* RUN find /tmp/` } - server, err := fakeStorage(map[string]string{"testD": testD}) - c.Assert(err, checker.IsNil) + server := fakeStorage(c, map[string]string{"testD": testD}) defer server.Close() res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json", daemonHost()) @@ -66,11 +65,9 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) { // failed to close tar archive c.Assert(tw.Close(), checker.IsNil) - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ + server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ "testT.tar": buffer, }) - c.Assert(err, checker.IsNil) - defer server.Close() res, b, err := request.SockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar", daemonHost()) @@ -115,12 +112,11 @@ RUN echo 'right' // failed to close tar archive c.Assert(tw.Close(), checker.IsNil) - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ + server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ "testT.tar": buffer, }) - c.Assert(err, checker.IsNil) - defer server.Close() + url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar" res, body, err := request.SockRequestRaw("POST", url, nil, "application/tar", daemonHost()) c.Assert(err, checker.IsNil) @@ -135,11 +131,10 @@ RUN echo 'right' } func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) { - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "dockerfile": `FROM busybox RUN echo from dockerfile`, }, false) - c.Assert(err, checker.IsNil) defer git.Close() res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost()) @@ -154,13 +149,12 @@ RUN echo from dockerfile`, } func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) { - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "baz": `FROM busybox RUN echo from baz`, "Dockerfile": `FROM busybox RUN echo from Dockerfile`, }, false) - c.Assert(err, checker.IsNil) defer git.Close() // Make sure it tries to 'dockerfile' query param value @@ -177,13 +171,12 @@ RUN echo from Dockerfile`, func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) { testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "Dockerfile": `FROM busybox RUN echo from Dockerfile`, "dockerfile": `FROM busybox RUN echo from dockerfile`, }, false) - c.Assert(err, checker.IsNil) defer git.Close() // Make sure it tries to 'dockerfile' query param value diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 8b864c530f..f2ec91adab 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1766,19 +1766,18 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { destPath := prefix + slash + "foo" var ( - err error testImg string ) if testEnv.DaemonPlatform() != "windows" { - testImg, err = buildImage("test-mount-config", ` + testImg = "test-mount-config" + buildImageSuccessfully(c, testImg, withDockerfile(` FROM busybox RUN mkdir `+destPath+` && touch `+destPath+slash+`bar CMD cat `+destPath+slash+`bar - `, true) + `)) } else { testImg = "busybox" } - c.Assert(err, checker.IsNil) type testCase struct { cfg mounttypes.Mount diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index ae2df11162..345ec77695 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -52,9 +52,8 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) { // TODO Windows to Windows CI: Investigate further why this test fails. testRequires(c, Network) testRequires(c, DaemonIsLinux) - out, err := buildImage("saveandload", "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) + buildImageSuccessfully(c, "saveandload", withDockerfile("FROM busybox\nENV FOO bar")) + id := getIDByName(c, "saveandload") res, body, err := request.SockRequestRaw("GET", "/images/"+id+"/get", nil, "", daemonHost()) c.Assert(err, checker.IsNil) @@ -77,9 +76,8 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) { testRequires(c, Network) } name := "test-api-images-delete" - out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) + buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar")) + id := getIDByName(c, name) dockerCmd(c, "tag", name, "test:tag1") @@ -101,10 +99,8 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { testRequires(c, Network) } name := "test-api-images-history" - out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - - id := strings.TrimSpace(out) + buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar")) + id := getIDByName(c, name) status, body, err := request.SockRequest("GET", "/images/"+id+"/history", nil, daemonHost()) c.Assert(err, checker.IsNil) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 88ca1984c3..d9d5c9197d 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -271,7 +271,7 @@ func (s *DockerSuite) TestBuildOnBuildLowercase(c *check.C) { onbuild run echo quux `)) - result := buildImageNew(name2, withDockerfile(fmt.Sprintf(` + result := buildImage(name2, withDockerfile(fmt.Sprintf(` FROM %s `, name))) result.Assert(c, icmd.Success) @@ -361,69 +361,45 @@ ONBUILD ENTRYPOINT ["echo"]`)) func (s *DockerSuite) TestBuildCacheAdd(c *check.C) { testRequires(c, DaemonIsLinux) // Windows doesn't have httpserver image yet name := "testbuildtwoimageswithadd" - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "robots.txt": "hello", "index.html": "world", }) - if err != nil { - c.Fatal(err) - } defer server.Close() - if _, err := buildImage(name, - fmt.Sprintf(`FROM scratch - ADD %s/robots.txt /`, server.URL()), - true); err != nil { - c.Fatal(err) - } - if err != nil { - c.Fatal(err) - } - deleteImages(name) - _, out, err := buildImageWithOut(name, - fmt.Sprintf(`FROM scratch - ADD %s/index.html /`, server.URL()), - true) - if err != nil { - c.Fatal(err) - } - if strings.Contains(out, "Using cache") { + buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(`FROM scratch + ADD %s/robots.txt /`, server.URL()))) + + result := buildImage(name, withDockerfile(fmt.Sprintf(`FROM scratch + ADD %s/index.html /`, server.URL()))) + result.Assert(c, icmd.Success) + if strings.Contains(result.Combined(), "Using cache") { c.Fatal("2nd build used cache on ADD, it shouldn't") } - } func (s *DockerSuite) TestBuildLastModified(c *check.C) { name := "testbuildlastmodified" - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "file": "hello", }) - if err != nil { - c.Fatal(err) - } defer server.Close() var out, out2 string dFmt := `FROM busybox ADD %s/file /` - dockerfile := fmt.Sprintf(dFmt, server.URL()) - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) out, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") // Build it again and make sure the mtime of the file didn't change. // Wait a few seconds to make sure the time changed enough to notice time.Sleep(2 * time.Second) - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") if out != out2 { @@ -432,19 +408,13 @@ ADD %s/file /` // Now 'touch' the file and make sure the timestamp DID change this time // Create a new fakeStorage instead of just using Add() to help windows - server, err = fakeStorage(map[string]string{ + server = fakeStorage(c, map[string]string{ "file": "hello", }) - if err != nil { - c.Fatal(err) - } defer server.Close() dockerfile = fmt.Sprintf(dFmt, server.URL()) - - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") if out == out2 { @@ -459,28 +429,21 @@ ADD %s/file /` func (s *DockerSuite) TestBuildModifyFileInFolder(c *check.C) { name := "testbuildmodifyfileinfolder" - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox RUN ["mkdir", "/test"] ADD folder/file /test/changetarget`, map[string]string{}) - if err != nil { - c.Fatal(err) - } defer ctx.Close() if err := ctx.Add("folder/file", "first"); err != nil { c.Fatal(err) } - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) if err := ctx.Add("folder/file", "second"); err != nil { c.Fatal(err) } - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id1 == id2 { c.Fatal("cache was used even though file contents in folder was changed") } @@ -504,20 +467,16 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte // Issue #3960: "ADD src ." hangs func (s *DockerSuite) TestBuildAddSingleFileToWorkdir(c *check.C) { name := "testaddsinglefiletoworkdir" - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox ADD test_file .`, map[string]string{ "test_file": "test1", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() errChan := make(chan error) go func() { - _, err := buildImageFromContext(name, ctx, true) - errChan <- err + errChan <- buildImage(name, withExternalBuildContext(ctx)).Error close(errChan) }() select { @@ -546,12 +505,9 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' func (s *DockerSuite) TestBuildCopyAddMultipleFiles(c *check.C) { testRequires(c, DaemonIsLinux) // Linux specific test - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "robots.txt": "hello", }) - if err != nil { - c.Fatal(err) - } defer server.Close() buildImageSuccessfully(c, "testcopymultiplefilestofile", withBuildContext(c, @@ -664,16 +620,13 @@ RUN find "test6" "C:/test dir/test_file6"` func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { name := "testcopywildcard" - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "robots.txt": "hello", "index.html": "world", }) - if err != nil { - c.Fatal(err) - } defer server.Close() - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox + ctx := fakeContext(c, fmt.Sprintf(`FROM busybox COPY file*.txt /tmp/ RUN ls /tmp/file1.txt /tmp/file2.txt RUN [ "mkdir", "/tmp1" ] @@ -690,21 +643,14 @@ func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { "dir/nested_dir/nest_nest_file": "2 times nested", "dirt": "dirty", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) // Now make sure we use a cache the 2nd time - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id1 != id2 { c.Fatal("didn't use the cache") @@ -734,30 +680,23 @@ func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) { func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) { name := "testcopywildcardcache" - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox COPY file1.txt /tmp/`, map[string]string{ "file1.txt": "test1", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) // Now make sure we use a cache the 2nd time even with wild cards. // Use the same context so the file is the same and the checksum will match ctx.Add("Dockerfile", `FROM busybox COPY file*.txt /tmp/`) - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id1 != id2 { c.Fatal("didn't use the cache") @@ -871,20 +810,16 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte // Issue #3960: "ADD src ." hangs - adapted for COPY func (s *DockerSuite) TestBuildCopySingleFileToWorkdir(c *check.C) { name := "testcopysinglefiletoworkdir" - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox COPY test_file .`, map[string]string{ "test_file": "test1", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() errChan := make(chan error) go func() { - _, err := buildImageFromContext(name, ctx, true) - errChan <- err + errChan <- buildImage(name, withExternalBuildContext(ctx)).Error close(errChan) }() select { @@ -985,10 +920,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) { var ( name = "test-link-absolute" ) - ctx, err := fakeContext(dockerfile, nil) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, dockerfile, nil) defer ctx.Close() tempDir, err := ioutil.TempDir("", "test-link-absolute-temp-") @@ -1049,10 +981,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) { c.Fatal(err) } - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) } @@ -1083,10 +1012,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir) nonExistingFile := filepath.Join(tempDir, targetFile) - ctx, err := fakeContext(dockerfile, nil) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, dockerfile, nil) defer ctx.Close() fooPath := filepath.Join(ctx.Dir, targetFile) @@ -1100,10 +1026,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { c.Fatal(err) } - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) } @@ -1117,18 +1040,15 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { { name := "testbuildinaccessiblefiles" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"}) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"}) defer ctx.Close() // This is used to ensure we detect inaccessible files early during build in the cli client pathToFileWithoutReadAccess := filepath.Join(ctx.Dir, "fileWithoutReadAccess") - if err = os.Chown(pathToFileWithoutReadAccess, 0, 0); err != nil { + if err := os.Chown(pathToFileWithoutReadAccess, 0, 0); err != nil { c.Fatalf("failed to chown file to root: %s", err) } - if err = os.Chmod(pathToFileWithoutReadAccess, 0700); err != nil { + if err := os.Chmod(pathToFileWithoutReadAccess, 0700); err != nil { c.Fatalf("failed to chmod file to 700: %s", err) } result := icmd.RunCmd(icmd.Cmd{ @@ -1150,22 +1070,19 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { } { name := "testbuildinaccessibledirectory" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"}) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"}) defer ctx.Close() // This is used to ensure we detect inaccessible directories early during build in the cli client pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") - if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { + if err := os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { c.Fatalf("failed to chown directory to root: %s", err) } - if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { + if err := os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { c.Fatalf("failed to chmod directory to 444: %s", err) } - if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { + if err := os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { c.Fatalf("failed to chmod file to 700: %s", err) } @@ -1189,10 +1106,7 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { } { name := "testlinksok" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", nil) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, "FROM scratch\nADD . /foo/", nil) defer ctx.Close() target := "../../../../../../../../../../../../../../../../../../../azA" @@ -1202,31 +1116,26 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { defer os.Remove(target) // This is used to ensure we don't follow links when checking if everything in the context is accessible // This test doesn't require that we run commands as an unprivileged user - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } { name := "testbuildignoredinaccessible" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", + ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{ "directoryWeCantStat/bar": "foo", ".dockerignore": "directoryWeCantStat", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() // This is used to ensure we don't try to add inaccessible files when they are ignored by a .dockerignore pattern pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") - if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { + if err := os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { c.Fatalf("failed to chown directory to root: %s", err) } - if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { + if err := os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { c.Fatalf("failed to chmod directory to 444: %s", err) } - if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { + if err := os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { c.Fatalf("failed to chmod file to 700: %s", err) } @@ -1246,7 +1155,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) { } name := "testbuildforcerm" - buildImageNew(name, withBuildFlags("--force-rm"), withBuildContext(c, + buildImage(name, withBuildFlags("--force-rm"), withBuildContext(c, withFile("Dockerfile", `FROM `+minimalBaseImage()+` RUN true RUN thiswillfail`))).Assert(c, icmd.Expected{ @@ -1542,7 +1451,7 @@ func (s *DockerSuite) TestBuildBlankName(c *check.C) { } for _, tc := range testCases { - buildImageNew(name, withDockerfile(fmt.Sprintf(`FROM busybox + buildImage(name, withDockerfile(fmt.Sprintf(`FROM busybox %s`, tc.expression))).Assert(c, icmd.Expected{ ExitCode: 1, Err: tc.expectedStderr, @@ -1624,7 +1533,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) { c.Fatalf("failed to list contents of tmp dir: %s", err) } - buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` + buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` RUN /non/existing/command`)).Assert(c, icmd.Expected{ ExitCode: 1, }) @@ -1802,11 +1711,11 @@ func (s *DockerSuite) TestBuildOnBuildLimitedInheritence(c *check.C) { ONBUILD RUN echo "ONBUILD PARENT" `)) // ONBUILD should be run in second build. - buildImageNew("testonbuildtrigger2", withDockerfile("FROM testonbuildtrigger1")).Assert(c, icmd.Expected{ + buildImage("testonbuildtrigger2", withDockerfile("FROM testonbuildtrigger1")).Assert(c, icmd.Expected{ Out: "ONBUILD PARENT", }) // ONBUILD should *not* be run in third build. - result := buildImageNew("testonbuildtrigger3", withDockerfile("FROM testonbuildtrigger2")) + result := buildImage("testonbuildtrigger3", withDockerfile("FROM testonbuildtrigger2")) result.Assert(c, icmd.Success) if strings.Contains(result.Combined(), "ONBUILD PARENT") { c.Fatalf("ONBUILD instruction ran in grandchild of ONBUILD parent") @@ -1821,14 +1730,11 @@ func (s *DockerSuite) TestBuildSameDockerfileWithAndWithoutCache(c *check.C) { EXPOSE 5432 ENTRYPOINT ["/bin/echo"]` buildImageSuccessfully(c, name, withDockerfile(dockerfile)) - id1, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id1 := getIDByName(c, name) buildImageSuccessfully(c, name, withDockerfile(dockerfile)) - id2, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id2 := getIDByName(c, name) buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) - id3, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id3 := getIDByName(c, name) if id1 != id2 { c.Fatal("The cache should have been used but hasn't.") } @@ -1844,36 +1750,27 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) { dockerfile := ` FROM busybox ADD foo /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "foo": "hello", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("Error building #1: %s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) if err := ctx.Add("foo", "bye"); err != nil { c.Fatalf("Error modifying foo: %s", err) } // Updating a file should invalidate the cache - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("Error building #2: %s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id2 == id1 { c.Fatal("Should not have used the cache") } - id3, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("Error building #3: %s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id3 := getIDByName(c, name) if id3 != id2 { c.Fatal("Should have used the cache") } @@ -1887,25 +1784,16 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check. MAINTAINER dockerio ADD foo Dockerfile /usr/lib/bla/ RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "foo": "hello", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id3, err := buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) + buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) + id3 := getIDByName(c, name) if id1 != id2 { c.Fatal("The cache should have been used but hasn't.") } @@ -1921,25 +1809,18 @@ func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) { dockerfile := ` FROM ` + minimalBaseImage() + ` COPY dir /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "dir/foo": "hello", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) // Check that adding file with similar name doesn't mess with cache if err := ctx.Add("dir_file", "hello2"); err != nil { c.Fatal(err) } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name2) if id1 != id2 { c.Fatal("The cache should have been used but wasn't") } @@ -1954,25 +1835,18 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { FROM ` + minimalBaseImage() + ` MAINTAINER dockerio ADD . /usr/lib/bla` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "foo": "hello", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) // Check that adding file invalidate cache of "ADD ." if err := ctx.Add("bar", "hello2"); err != nil { c.Fatal(err) } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name2) if id1 == id2 { c.Fatal("The cache should have been invalided but hasn't.") } @@ -1980,10 +1854,8 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { if err := ctx.Add("foo", "hello1"); err != nil { c.Fatal(err) } - id3, err := buildImageFromContext(name3, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name3, withExternalBuildContext(ctx)) + id3 := getIDByName(c, name3) if id2 == id3 { c.Fatal("The cache should have been invalided but hasn't.") } @@ -1993,10 +1865,8 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { if err := ctx.Add("foo", "hello1"); err != nil { c.Fatal(err) } - id4, err := buildImageFromContext(name4, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name4, withExternalBuildContext(ctx)) + id4 := getIDByName(c, name4) if id3 != id4 { c.Fatal("The cache should have been used but hasn't.") } @@ -2009,21 +1879,14 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { FROM ` + minimalBaseImage() + ` MAINTAINER dockerio ADD . /usr/lib/bla` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "foo": "hello", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) + buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id1 == id2 { c.Fatal("The cache should have been invalided but hasn't.") } @@ -2031,26 +1894,20 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { func (s *DockerSuite) TestBuildAddRemoteFileWithAndWithoutCache(c *check.C) { name := "testbuildaddremotefilewithcache" - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "baz": "hello", }) - if err != nil { - c.Fatal(err) - } defer server.Close() dockerfile := fmt.Sprintf(`FROM `+minimalBaseImage()+` MAINTAINER dockerio ADD %s/baz /usr/lib/baz/quux`, server.URL()) buildImageSuccessfully(c, name, withDockerfile(dockerfile)) - id1, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id1 := getIDByName(c, name) buildImageSuccessfully(c, name, withDockerfile(dockerfile)) - id2, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id2 := getIDByName(c, name) buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) - id3, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id3 := getIDByName(c, name) if id1 != id2 { c.Fatal("The cache should have been used but hasn't.") @@ -2066,29 +1923,18 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { name3 := name + "3" files := map[string]string{"baz": "hello"} - server, err := fakeStorage(files) - if err != nil { - c.Fatal(err) - } + server := fakeStorage(c, files) defer server.Close() - ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` + ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` MAINTAINER dockerio ADD %s/baz /usr/lib/baz/quux`, server.URL()), nil) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) + buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name2) if id1 != id2 { c.Fatal("The cache should have been used but wasn't - #1") } @@ -2099,23 +1945,15 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { // allow some time for clock to pass as mtime precision is only 1s time.Sleep(2 * time.Second) - server2, err := fakeStorage(files) - if err != nil { - c.Fatal(err) - } + server2 := fakeStorage(c, files) defer server2.Close() - ctx2, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` + ctx2 := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` MAINTAINER dockerio ADD %s/baz /usr/lib/baz/quux`, server2.URL()), nil) - if err != nil { - c.Fatal(err) - } defer ctx2.Close() - id3, err := buildImageFromContext(name3, ctx2, true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name3, withExternalBuildContext(ctx2)) + id3 := getIDByName(c, name3) if id1 != id3 { c.Fatal("The cache should have been used but wasn't") } @@ -2124,37 +1962,25 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { // FIXME(vdemeester) this really seems to test the same thing as before (combined) func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *check.C) { name := "testbuildaddlocalandremotefilewithcache" - server, err := fakeStorage(map[string]string{ + server := fakeStorage(c, map[string]string{ "baz": "hello", }) - if err != nil { - c.Fatal(err) - } defer server.Close() - ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` + ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` MAINTAINER dockerio ADD foo /usr/lib/bla/bar ADD %s/baz /usr/lib/baz/quux`, server.URL()), map[string]string{ "foo": "hello world", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id3, err := buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) + buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) + id3 := getIDByName(c, name) if id1 != id2 { c.Fatal("The cache should have been used but hasn't.") } @@ -2164,7 +1990,7 @@ func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *chec } func testContextTar(c *check.C, compression archive.Compression) { - ctx, err := fakeContext( + ctx := fakeContext(c, `FROM busybox ADD foo /foo CMD ["cat", "/foo"]`, @@ -2172,9 +1998,6 @@ CMD ["cat", "/foo"]`, "foo": "bar", }, ) - if err != nil { - c.Fatal(err) - } defer ctx.Close() context, err := archive.Tar(ctx.Dir, compression) if err != nil { @@ -2257,7 +2080,7 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) { expected = "foo: The system cannot find the file specified" } - buildImageNew(name, withBuildContext(c, + buildImage(name, withBuildContext(c, withFile("Dockerfile", `FROM `+minimalBaseImage()+` ADD foo /usr/local/bar`), withFile("bar", "hello"))).Assert(c, icmd.Expected{ @@ -2289,7 +2112,7 @@ func (s *DockerSuite) TestBuildInheritance(c *check.C) { func (s *DockerSuite) TestBuildFails(c *check.C) { name := "testbuildfails" - buildImageNew(name, withDockerfile(`FROM busybox + buildImage(name, withDockerfile(`FROM busybox RUN sh -c "exit 23"`)).Assert(c, icmd.Expected{ ExitCode: 23, Err: "returned a non-zero code: 23", @@ -2504,51 +2327,41 @@ func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) { } func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) { - var id1 string - var id2 string - name := "testbuilddockerignoretouchdockerfile" dockerfile := ` FROM busybox ADD . /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "Dockerfile": dockerfile, ".dockerignore": "Dockerfile\n", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - if id1, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id1 := getIDByName(c, name) - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 := getIDByName(c, name) if id1 != id2 { c.Fatalf("Didn't use the cache - 1") } // Now make sure touching Dockerfile doesn't invalidate the cache - if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { + if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { c.Fatalf("Didn't add Dockerfile: %s", err) } - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 = getIDByName(c, name) if id1 != id2 { c.Fatalf("Didn't use the cache - 2") } // One more time but just 'touch' it instead of changing the content - if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { + if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { c.Fatalf("Didn't add Dockerfile: %s", err) } - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) + id2 = getIDByName(c, name) if id1 != id2 { c.Fatalf("Didn't use the cache - 3") } @@ -2590,7 +2403,7 @@ func (s *DockerSuite) TestBuildDockerignoringOnlyDotfiles(c *check.C) { func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) { name := "testbuilddockerignorebadexclusion" - buildImageNew(name, withBuildContext(c, + buildImage(name, withBuildContext(c, withFile("Dockerfile", ` FROM busybox COPY . / @@ -2949,10 +2762,7 @@ RUN cat /existing-directory-trailing-slash/test/foo | grep Hi` }() defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTar: %v", err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } func (s *DockerSuite) TestBuildAddBrokenTar(c *check.C) { @@ -3001,9 +2811,9 @@ ADD test.tar /` }() defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err == nil { - c.Fatalf("build should have failed for TestBuildAddBrokenTar") - } + buildImage(name, withExternalBuildContext(ctx)).Assert(c, icmd.Expected{ + ExitCode: 1, + }) } func (s *DockerSuite) TestBuildAddNonTar(c *check.C) { @@ -3068,10 +2878,7 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) { defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { @@ -3128,24 +2935,18 @@ func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } func (s *DockerSuite) TestBuildFromGit(c *check.C) { name := "testbuildfromgit" - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "Dockerfile": `FROM busybox ADD first /first RUN [ -f /first ] MAINTAINER docker`, "first": "test git data", }, true) - if err != nil { - c.Fatal(err) - } defer git.Close() buildImageSuccessfully(c, name, withBuildContextPath(git.RepoURL)) @@ -3158,16 +2959,13 @@ func (s *DockerSuite) TestBuildFromGit(c *check.C) { func (s *DockerSuite) TestBuildFromGitWithContext(c *check.C) { name := "testbuildfromgit" - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "docker/Dockerfile": `FROM busybox ADD first /first RUN [ -f /first ] MAINTAINER docker`, "docker/first": "test git data", }, true) - if err != nil { - c.Fatal(err) - } defer git.Close() buildImageSuccessfully(c, name, withBuildContextPath(fmt.Sprintf("%s#master:docker", git.RepoURL))) @@ -3180,16 +2978,13 @@ func (s *DockerSuite) TestBuildFromGitWithContext(c *check.C) { func (s *DockerSuite) TestBuildFromGitwithF(c *check.C) { name := "testbuildfromgitwithf" - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "myApp/myDockerfile": `FROM busybox RUN echo hi from Dockerfile`, }, true) - if err != nil { - c.Fatal(err) - } defer git.Close() - buildImageNew(name, withBuildFlags("-f", "myApp/myDockerfile"), withBuildContextPath(git.RepoURL)).Assert(c, icmd.Expected{ + buildImage(name, withBuildFlags("-f", "myApp/myDockerfile"), withBuildContextPath(git.RepoURL)).Assert(c, icmd.Expected{ Out: "hi from Dockerfile", }) } @@ -3216,11 +3011,9 @@ func (s *DockerSuite) TestBuildFromRemoteTarball(c *check.C) { c.Fatalf("failed to close tar archive: %v", err) } - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ + server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ "testT.tar": buffer, }) - c.Assert(err, check.IsNil) - defer server.Close() buildImageSuccessfully(c, name, withBuildContextPath(server.URL()+"/testT.tar")) @@ -3279,7 +3072,7 @@ func (s *DockerSuite) TestBuildOnBuildOutput(c *check.C) { name := "testbuildonbuildparent" buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nONBUILD RUN echo foo\n")) - buildImageNew(name, withDockerfile("FROM "+name+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ + buildImage(name, withDockerfile("FROM "+name+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ Out: "# Executing 1 build trigger", }) } @@ -3287,7 +3080,7 @@ func (s *DockerSuite) TestBuildOnBuildOutput(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerSuite) TestBuildInvalidTag(c *check.C) { name := "abcd:" + stringutils.GenerateRandomAlphaOnlyString(200) - buildImageNew(name, withDockerfile("FROM "+minimalBaseImage()+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ + buildImage(name, withDockerfile("FROM "+minimalBaseImage()+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ ExitCode: 125, Err: "Error parsing reference", }) @@ -3315,10 +3108,9 @@ func (s *DockerSuite) TestBuildCmdSpaces(c *check.C) { name := "testbuildcmdspaces" buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nCMD [\"echo hi\"]\n")) - id1, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id1 := getIDByName(c, name) buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nCMD [\"echo\", \"hi\"]\n")) - id2, err := getIDByName(name) + id2 := getIDByName(c, name) if id1 == id2 { c.Fatal("Should not have resulted in the same CMD") @@ -3326,10 +3118,9 @@ func (s *DockerSuite) TestBuildCmdSpaces(c *check.C) { // Now do the same with ENTRYPOINT buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENTRYPOINT [\"echo hi\"]\n")) - id1, err = getIDByName(name) - c.Assert(err, checker.IsNil) + id1 = getIDByName(c, name) buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENTRYPOINT [\"echo\", \"hi\"]\n")) - id2, err = getIDByName(name) + id2 = getIDByName(c, name) if id1 == id2 { c.Fatal("Should not have resulted in the same ENTRYPOINT") @@ -3451,7 +3242,7 @@ func (s *DockerSuite) TestBuildVerboseOut(c *check.C) { expected = "\n123\r\n" } - buildImageNew(name, withDockerfile(`FROM busybox + buildImage(name, withDockerfile(`FROM busybox RUN echo 123`)).Assert(c, icmd.Expected{ Out: expected, }) @@ -3489,44 +3280,37 @@ func (s *DockerSuite) TestBuildLabelsCache(c *check.C) { buildImageSuccessfully(c, name, withDockerfile(`FROM busybox LABEL Vendor=Acme`)) - id1, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id1 := getIDByName(c, name) buildImageSuccessfully(c, name, withDockerfile(`FROM busybox LABEL Vendor=Acme`)) - id2, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id2 := getIDByName(c, name) if id1 != id2 { - c.Fatalf("Build 2 should have worked & used cache(%s,%s): %v", id1, id2, err) + c.Fatalf("Build 2 should have worked & used cache(%s,%s)", id1, id2) } buildImageSuccessfully(c, name, withDockerfile(`FROM busybox LABEL Vendor=Acme1`)) - id2, err = getIDByName(name) - c.Assert(err, checker.IsNil) + id2 = getIDByName(c, name) if id1 == id2 { - c.Fatalf("Build 3 should have worked & NOT used cache(%s,%s): %v", id1, id2, err) + c.Fatalf("Build 3 should have worked & NOT used cache(%s,%s)", id1, id2) } buildImageSuccessfully(c, name, withDockerfile(`FROM busybox LABEL Vendor Acme`)) - id2, err = getIDByName(name) - c.Assert(err, checker.IsNil) + id2 = getIDByName(c, name) if id1 != id2 { - c.Fatalf("Build 4 should have worked & used cache(%s,%s): %v", id1, id2, err) + c.Fatalf("Build 4 should have worked & used cache(%s,%s)", id1, id2) } // Now make sure the cache isn't used by mistake buildImageSuccessfully(c, name, withoutCache, withDockerfile(`FROM busybox LABEL f1=b1 f2=b2`)) - _, err = getIDByName(name) - c.Assert(err, checker.IsNil) buildImageSuccessfully(c, name, withDockerfile(`FROM busybox LABEL f1=b1 f2=b2`)) - id2, err = getIDByName(name) - c.Assert(err, checker.IsNil) + id2 = getIDByName(c, name) if id1 == id2 { - c.Fatalf("Build 6 should have worked & NOT used the cache(%s,%s): %q", id1, id2, err) + c.Fatalf("Build 6 should have worked & NOT used the cache(%s,%s)", id1, id2) } } @@ -3544,13 +3328,13 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) { { Name: "quiet_build_stdin_success", BuildFunc: func(name string) *icmd.Result { - return buildImageNew(name, buildFlags, withDockerfile("FROM busybox")) + return buildImage(name, buildFlags, withDockerfile("FROM busybox")) }, }, { Name: "quiet_build_ctx_success", BuildFunc: func(name string) *icmd.Result { - return buildImageNew(name, buildFlags, withBuildContext(c, + return buildImage(name, buildFlags, withBuildContext(c, withFile("Dockerfile", "FROM busybox"), withFile("quiet_build_success_fctx", "test"), )) @@ -3559,11 +3343,10 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) { { Name: "quiet_build_git_success", BuildFunc: func(name string) *icmd.Result { - git, err := newFakeGit("repo", map[string]string{ + git := newFakeGit(c, "repo", map[string]string{ "Dockerfile": "FROM busybox", }, true) - c.Assert(err, checker.IsNil) - return buildImageNew(name, buildFlags, withBuildContextPath(git.RepoURL)) + return buildImage(name, buildFlags, withBuildContextPath(git.RepoURL)) }, }, } @@ -3589,11 +3372,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailureWithNonExistImage(c *check.C) { testRequires(c, Network) testName := "quiet_build_not_exists_image" dockerfile := "FROM busybox11" - quietResult := buildImageNew(testName, withBuildFlags("-q"), withDockerfile(dockerfile)) + quietResult := buildImage(testName, withBuildFlags("-q"), withDockerfile(dockerfile)) quietResult.Assert(c, icmd.Expected{ ExitCode: 1, }) - result := buildImageNew(testName, withDockerfile(dockerfile)) + result := buildImage(testName, withDockerfile(dockerfile)) result.Assert(c, icmd.Expected{ ExitCode: 1, }) @@ -3615,11 +3398,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailure(c *check.C) { } for _, tc := range testCases { - quietResult := buildImageNew(tc.testName, withBuildFlags("-q"), withDockerfile(tc.dockerfile)) + quietResult := buildImage(tc.testName, withBuildFlags("-q"), withDockerfile(tc.dockerfile)) quietResult.Assert(c, icmd.Expected{ ExitCode: 1, }) - result := buildImageNew(tc.testName, withDockerfile(tc.dockerfile)) + result := buildImage(tc.testName, withDockerfile(tc.dockerfile)) result.Assert(c, icmd.Expected{ ExitCode: 1, }) @@ -3635,11 +3418,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) { // TODO(vdemeester) with cobra, stdout has a carriage return too much so this test should not check stdout URL := "http://something.invalid" name := "quiet_build_wrong_remote" - quietResult := buildImageNew(name, withBuildFlags("-q"), withBuildContextPath(URL)) + quietResult := buildImage(name, withBuildFlags("-q"), withBuildContextPath(URL)) quietResult.Assert(c, icmd.Expected{ ExitCode: 1, }) - result := buildImageNew(name, withBuildContextPath(URL)) + result := buildImage(name, withBuildContextPath(URL)) result.Assert(c, icmd.Expected{ ExitCode: 1, }) @@ -3652,7 +3435,7 @@ func (s *DockerSuite) TestBuildStderr(c *check.C) { // This test just makes sure that no non-error output goes // to stderr name := "testbuildstderr" - result := buildImageNew(name, withDockerfile("FROM busybox\nRUN echo one")) + result := buildImage(name, withDockerfile("FROM busybox\nRUN echo one")) result.Assert(c, icmd.Success) // Windows to non-Windows should have a security warning @@ -3671,7 +3454,7 @@ func (s *DockerSuite) TestBuildChownSingleFile(c *check.C) { name := "testbuildchownsinglefile" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY test / RUN ls -l /test @@ -3679,19 +3462,13 @@ RUN [ $(ls -l /test | awk '{print $3":"$4}') = 'root:root' ] `, map[string]string{ "test": "test", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() if err := os.Chown(filepath.Join(ctx.Dir, "test"), 4242, 4242); err != nil { c.Fatal(err) } - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) { @@ -3735,9 +3512,8 @@ func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) { }) w.Close() f.Close() - if _, err := buildImageFromContext(name, fakeContextFromDir(ctx), false); err != nil { - c.Fatal(err) - } + + buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(fakeContextFromDir(ctx))) if _, err := os.Lstat(filepath.Join(tmpdir, "inject")); err == nil { c.Fatal("symlink breakout - inject") } else if !os.IsNotExist(err) { @@ -3797,7 +3573,7 @@ CMD cat /foo/file`), // FIXME(vdemeester) part of this should be unit test, other part should be clearer func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) { - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox RUN echo from Dockerfile`, map[string]string{ "Dockerfile": "FROM busybox\nRUN echo from Dockerfile", @@ -3806,9 +3582,6 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) { "dFile": "FROM busybox\nRUN echo from dFile", "files/dFile2": "FROM busybox\nRUN echo from files/dFile2", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") @@ -3904,7 +3677,7 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { testRequires(c, DaemonIsLinux) // If Dockerfile is not present, use dockerfile - buildImageNew("test1", withBuildContext(c, + buildImage("test1", withBuildContext(c, withFile("dockerfile", `FROM busybox RUN echo from dockerfile`), )).Assert(c, icmd.Expected{ @@ -3912,7 +3685,7 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { }) // Prefer Dockerfile in place of dockerfile - buildImageNew("test1", withBuildContext(c, + buildImage("test1", withBuildContext(c, withFile("dockerfile", `FROM busybox RUN echo from dockerfile`), withFile("Dockerfile", `FROM busybox @@ -3923,26 +3696,20 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { } func (s *DockerSuite) TestBuildFromURLWithF(c *check.C) { - server, err := fakeStorage(map[string]string{"baz": `FROM busybox + server := fakeStorage(c, map[string]string{"baz": `FROM busybox RUN echo from baz COPY * /tmp/ RUN find /tmp/`}) - if err != nil { - c.Fatal(err) - } defer server.Close() - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox RUN echo from Dockerfile`, map[string]string{}) - if err != nil { - c.Fatal(err) - } defer ctx.Close() // Make sure that -f is ignored and that we don't use the Dockerfile // that's in the current dir - result := buildImageNew("test1", withBuildFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() { + result := buildImage("test1", withBuildFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() { cmd.Dir = ctx.Dir return nil }) @@ -3958,17 +3725,14 @@ RUN echo from Dockerfile`, func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) { testRequires(c, DaemonIsLinux) // TODO Windows: This test is flaky; no idea why - ctx, err := fakeContext(`FROM busybox + ctx := fakeContext(c, `FROM busybox RUN echo "from Dockerfile"`, map[string]string{}) - if err != nil { - c.Fatal(err) - } defer ctx.Close() // Make sure that -f is ignored and that we don't use the Dockerfile // that's in the current dir - result := buildImageNew("test1", withBuildFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() { + result := buildImage("test1", withBuildFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() { cmd.Dir = ctx.Dir cmd.Stdin = strings.NewReader(`FROM busybox RUN echo "from baz" @@ -4062,69 +3826,65 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) { func (s *DockerSuite) TestBuildSpaces(c *check.C) { // Test to make sure that leading/trailing spaces on a command // doesn't change the error msg we get - var ( - err1 error - err2 error - ) - name := "testspaces" - ctx, err := fakeContext("FROM busybox\nCOPY\n", + ctx := fakeContext(c, "FROM busybox\nCOPY\n", map[string]string{ "Dockerfile": "FROM busybox\nCOPY\n", }) - if err != nil { - c.Fatal(err) - } defer ctx.Close() - if _, err1 = buildImageFromContext(name, ctx, false); err1 == nil { - c.Fatal("Build 1 was supposed to fail, but didn't") - } + result1 := buildImage(name, withExternalBuildContext(ctx)) + result1.Assert(c, icmd.Expected{ + ExitCode: 1, + }) ctx.Add("Dockerfile", "FROM busybox\nCOPY ") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 2 was supposed to fail, but didn't") - } + result2 := buildImage(name, withExternalBuildContext(ctx)) + result2.Assert(c, icmd.Expected{ + ExitCode: 1, + }) removeLogTimestamps := func(s string) string { return regexp.MustCompile(`time="(.*?)"`).ReplaceAllString(s, `time=[TIMESTAMP]`) } // Skip over the times - e1 := removeLogTimestamps(err1.Error()) - e2 := removeLogTimestamps(err2.Error()) + e1 := removeLogTimestamps(result1.Error.Error()) + e2 := removeLogTimestamps(result2.Error.Error()) // Ignore whitespace since that's what were verifying doesn't change stuff if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", err1, err2) + c.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", result1.Error, result2.Error) } ctx.Add("Dockerfile", "FROM busybox\n COPY") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 3 was supposed to fail, but didn't") - } + result2 = buildImage(name, withoutCache, withExternalBuildContext(ctx)) + result2.Assert(c, icmd.Expected{ + ExitCode: 1, + }) // Skip over the times - e1 = removeLogTimestamps(err1.Error()) - e2 = removeLogTimestamps(err2.Error()) + e1 = removeLogTimestamps(result1.Error.Error()) + e2 = removeLogTimestamps(result2.Error.Error()) // Ignore whitespace since that's what were verifying doesn't change stuff if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", err1, err2) + c.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", result1.Error, result2.Error) } ctx.Add("Dockerfile", "FROM busybox\n COPY ") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 4 was supposed to fail, but didn't") - } + result2 = buildImage(name, withoutCache, withExternalBuildContext(ctx)) + result2.Assert(c, icmd.Expected{ + ExitCode: 1, + }) // Skip over the times - e1 = removeLogTimestamps(err1.Error()) - e2 = removeLogTimestamps(err2.Error()) + e1 = removeLogTimestamps(result1.Error.Error()) + e2 = removeLogTimestamps(result2.Error.Error()) // Ignore whitespace since that's what were verifying doesn't change stuff if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 4's error wasn't the same as build 1's\n1:%s\n4:%s", err1, err2) + c.Fatalf("Build 4's error wasn't the same as build 1's\n1:%s\n4:%s", result1.Error, result2.Error) } } @@ -4143,7 +3903,7 @@ RUN echo " \ expected = "\" foo \"" } - buildImageNew(name, withDockerfile(dockerfile)).Assert(c, icmd.Expected{ + buildImage(name, withDockerfile(dockerfile)).Assert(c, icmd.Expected{ Out: expected, }) } @@ -4151,7 +3911,7 @@ RUN echo " \ // #4393 func (s *DockerSuite) TestBuildVolumeFileExistsinContainer(c *check.C) { testRequires(c, DaemonIsLinux) // TODO Windows: This should error out - buildImageNew("docker-test-errcreatevolumewithfile", withDockerfile(` + buildImage("docker-test-errcreatevolumewithfile", withDockerfile(` FROM busybox RUN touch /foo VOLUME /foo @@ -4199,7 +3959,7 @@ func (s *DockerSuite) TestBuildMissingArgs(c *check.C) { dockerfile = "FROM busybox\n" + cmd } - buildImageNew("args", withDockerfile(dockerfile)).Assert(c, icmd.Expected{ + buildImage("args", withDockerfile(dockerfile)).Assert(c, icmd.Expected{ ExitCode: 1, Err: cmd + " requires", }) @@ -4209,7 +3969,7 @@ func (s *DockerSuite) TestBuildMissingArgs(c *check.C) { func (s *DockerSuite) TestBuildEmptyScratch(c *check.C) { testRequires(c, DaemonIsLinux) - buildImageNew("sc", withDockerfile("FROM scratch")).Assert(c, icmd.Expected{ + buildImage("sc", withDockerfile("FROM scratch")).Assert(c, icmd.Expected{ ExitCode: 1, Err: "No image was generated", }) @@ -4226,7 +3986,7 @@ func (s *DockerSuite) TestBuildRUNoneJSON(c *check.C) { testRequires(c, DaemonIsLinux) // No hello-world Windows image name := "testbuildrunonejson" - buildImageNew(name, withDockerfile(`FROM hello-world:frozen + buildImage(name, withDockerfile(`FROM hello-world:frozen RUN [ "/hello" ]`)).Assert(c, icmd.Expected{ Out: "Hello from Docker", }) @@ -4235,7 +3995,7 @@ RUN [ "/hello" ]`)).Assert(c, icmd.Expected{ func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) { name := "testbuildemptystringvolume" - buildImageNew(name, withDockerfile(` + buildImage(name, withDockerfile(` FROM busybox ENV foo="" VOLUME $foo @@ -4257,7 +4017,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) { if !found { c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths) } - result := buildImageNew("buildcgroupparent", + result := buildImage("buildcgroupparent", withBuildFlags("--cgroup-parent", cgroupParent), withDockerfile(` FROM busybox @@ -4277,7 +4037,7 @@ func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) { // property - there was a bug that caused it to be duplicated on the // Step X line name := "testbuildnodupoutput" - result := buildImageNew(name, withDockerfile(` + result := buildImage(name, withDockerfile(` FROM busybox RUN env`)) result.Assert(c, icmd.Success) @@ -4292,7 +4052,7 @@ func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) { func (s *DockerSuite) TestBuildStartsFromOne(c *check.C) { // Explicit check to ensure that build starts from step 1 rather than 0 name := "testbuildstartsfromone" - result := buildImageNew(name, withDockerfile(`FROM busybox`)) + result := buildImage(name, withDockerfile(`FROM busybox`)) result.Assert(c, icmd.Success) exp := "\nStep 1/1 : FROM busybox\n" if !strings.Contains(result.Combined(), exp) { @@ -4313,7 +4073,7 @@ func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) { } exp := fmt.Sprintf(`The command '%s badEXE a1 \& a2 a3' returned a non-zero code: %d`, shell, exitCode) - buildImageNew(name, withDockerfile(` + buildImage(name, withDockerfile(` FROM busybox RUN badEXE a1 \& a2 a3`)).Assert(c, icmd.Expected{ ExitCode: exitCode, @@ -4330,7 +4090,7 @@ func (s *DockerTrustSuite) TestTrustedBuild(c *check.C) { name := "testtrustedbuild" - buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ + buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ Out: fmt.Sprintf("FROM %s@sha", repoName[:len(repoName)-7]), }) @@ -4350,7 +4110,7 @@ func (s *DockerTrustSuite) TestTrustedBuildUntrustedTag(c *check.C) { name := "testtrustedbuilduntrustedtag" - buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ + buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ ExitCode: 1, Err: "does not have trust data for", }) @@ -4418,7 +4178,7 @@ func (s *DockerTrustSuite) TestTrustedBuildTagFromReleasesRole(c *check.C) { RUN [] `, otherTag) name := "testtrustedbuildreleasesrole" - buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ + buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ Out: fmt.Sprintf("FROM %s@sha", repoName), }) } @@ -4451,7 +4211,7 @@ func (s *DockerTrustSuite) TestTrustedBuildTagIgnoresOtherDelegationRoles(c *che `, otherTag) name := "testtrustedbuildotherrole" - buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ + buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ ExitCode: 1, }) } @@ -4513,7 +4273,7 @@ func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) { CMD echo $%s`, envKey, envKey, envKey) } - buildImageNew(imgName, + buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ).Assert(c, icmd.Expected{ @@ -4535,7 +4295,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgHistory(c *check.C) { envDef := "bar1" dockerfile := fmt.Sprintf(`FROM busybox ARG %s=%s`, envKey, envDef) - buildImageNew(imgName, + buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ).Assert(c, icmd.Expected{ @@ -4560,16 +4320,14 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheHit(c *check.C) { withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) - origImgID, err := getIDByName(imgName) - c.Assert(err, checker.IsNil) + origImgID := getIDByName(c, imgName) imgNameCache := "bldargtestcachehit" buildImageSuccessfully(c, imgNameCache, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) - newImgID, err := getIDByName(imgName) - c.Assert(err, checker.IsNil) + newImgID := getIDByName(c, imgName) if newImgID != origImgID { c.Fatalf("build didn't use cache! expected image id: %q built image id: %q", origImgID, newImgID) } @@ -4589,8 +4347,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissExtraArg(c *check.C) { withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) - origImgID, err := getIDByName(imgName) - c.Assert(err, checker.IsNil) + origImgID := getIDByName(c, imgName) imgNameCache := "bldargtestcachemiss" buildImageSuccessfully(c, imgNameCache, @@ -4600,8 +4357,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissExtraArg(c *check.C) { ), withDockerfile(dockerfile), ) - newImgID, err := getIDByName(imgNameCache) - c.Assert(err, checker.IsNil) + newImgID := getIDByName(c, imgNameCache) if newImgID == origImgID { c.Fatalf("build used cache, expected a miss!") @@ -4620,16 +4376,14 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissSameArgDiffVal(c *check.C) { withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) - origImgID, err := getIDByName(imgName) - c.Assert(err, checker.IsNil) + origImgID := getIDByName(c, imgName) imgNameCache := "bldargtestcachemiss" buildImageSuccessfully(c, imgNameCache, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, newEnvVal)), withDockerfile(dockerfile), ) - newImgID, err := getIDByName(imgNameCache) - c.Assert(err, checker.IsNil) + newImgID := getIDByName(c, imgNameCache) if newImgID == origImgID { c.Fatalf("build used cache, expected a miss!") } @@ -4648,7 +4402,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgOverrideArgDefinedBeforeEnv(c *check. CMD echo $%s `, envKey, envKey, envValOveride, envKey, envKey) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) @@ -4676,7 +4430,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgOverrideEnvDefinedBeforeArg(c *check. RUN echo $%s CMD echo $%s `, envKey, envValOveride, envKey, envKey, envKey) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) @@ -4793,7 +4547,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansionOverride(c *check.C) { ENV %s ${%s} RUN echo $%s CMD echo $%s`, envKey, envKey, envValOveride, envKey1, envKey, envKey1, envKey1) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) @@ -4817,7 +4571,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgUntrustedDefinedAfterUse(c *check.C) RUN echo $%s ARG %s CMD echo $%s`, envKey, envKey, envKey) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) @@ -4841,7 +4595,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgBuiltinArg(c *check.C) { RUN echo $%s CMD echo $%s`, envKey, envKey) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ) @@ -4866,7 +4620,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgDefaultOverride(c *check.C) { ENV %s $%s RUN echo $%s CMD echo $%s`, envKey, envVal, envKey, envKey, envKey, envKey) - result := buildImageNew(imgName, + result := buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envValOveride)), withDockerfile(dockerfile), ) @@ -4889,7 +4643,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) { RUN echo $%s CMD echo $%s`, envKey, envKey) warnStr := "[Warning] One or more build-args" - buildImageNew(imgName, + buildImage(imgName, withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), withDockerfile(dockerfile), ).Assert(c, icmd.Expected{ @@ -4918,7 +4672,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgEnv(c *check.C) { RUN [ "$(env | grep FOO8)" == "" ] RUN [ "$(env | grep FOO9)" == "" ] ` - result := buildImageNew("testbuildtimeargenv", + result := buildImage("testbuildtimeargenv", withBuildFlags( "--build-arg", fmt.Sprintf("FOO1=fromcmd"), "--build-arg", fmt.Sprintf("FOO2="), @@ -4998,7 +4752,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgDefintionWithNoEnvInjection(c *check. ARG %s RUN env`, envKey) - result := buildImageNew(imgName, withDockerfile(dockerfile)) + result := buildImage(imgName, withDockerfile(dockerfile)) result.Assert(c, icmd.Success) if strings.Count(result.Combined(), envKey) != 1 { c.Fatalf("unexpected number of occurrences of the arg in output: %q expected: 1", result.Combined()) @@ -5017,7 +4771,7 @@ func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) { VOLUME ` + volName + ` RUN ls /foo/oops ` - buildImageNew("test", withDockerfile(dockerFile)).Assert(c, icmd.Expected{ + buildImage("test", withDockerfile(dockerFile)).Assert(c, icmd.Expected{ ExitCode: 1, }) } @@ -5053,105 +4807,97 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) { ` buildImageSuccessfully(c, "tag1", withBuildFlags("-t", "tag2:v2", "-t", "tag1:latest", "-t", "tag1"), withDockerfile(dockerfile)) - id1, err := getIDByName("tag1") - c.Assert(err, check.IsNil) - id2, err := getIDByName("tag2:v2") - c.Assert(err, check.IsNil) + id1 := getIDByName(c, "tag1") + id2 := getIDByName(c, "tag2:v2") c.Assert(id1, check.Equals, id2) } // #17290 func (s *DockerSuite) TestBuildCacheBrokenSymlink(c *check.C) { name := "testbuildbrokensymlink" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY . ./`, map[string]string{ "foo": "bar", }) - c.Assert(err, checker.IsNil) defer ctx.Close() - err = os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) + err := os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) c.Assert(err, checker.IsNil) // warm up cache - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) // add new file to context, should invalidate cache err = ioutil.WriteFile(filepath.Join(ctx.Dir, "newfile"), []byte("foo"), 0644) c.Assert(err, checker.IsNil) - _, out, err := buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Not(checker.Contains), "Using cache") - + result := buildImage(name, withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + if strings.Contains(result.Combined(), "Using cache") { + c.Fatal("2nd build used cache on ADD, it shouldn't") + } } func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *check.C) { name := "testbuildbrokensymlink" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY asymlink target`, map[string]string{ "foo": "bar", }) - c.Assert(err, checker.IsNil) defer ctx.Close() - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) + err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) c.Assert(err, checker.IsNil) - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "target") + out, _ := dockerCmd(c, "run", "--rm", name, "cat", "target") c.Assert(out, checker.Matches, "bar") // change target file should invalidate cache err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) c.Assert(err, checker.IsNil) - id, out, err = buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), "Using cache") + result := buildImage(name, withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") - out, _ = dockerCmd(c, "run", "--rm", id, "cat", "target") + out, _ = dockerCmd(c, "run", "--rm", name, "cat", "target") c.Assert(out, checker.Matches, "baz") } func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) { name := "testbuildbrokensymlink" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY asymlink /`, map[string]string{ "foo/abc": "bar", "foo/def": "baz", }) - c.Assert(err, checker.IsNil) defer ctx.Close() - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) + err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) c.Assert(err, checker.IsNil) - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") + out, _ := dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") c.Assert(out, checker.Matches, "barbaz") // change target file should invalidate cache err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644) c.Assert(err, checker.IsNil) - id, out, err = buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), "Using cache") + result := buildImage(name, withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") - out, _ = dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") + out, _ = dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") c.Assert(out, checker.Matches, "barbax") } @@ -5160,61 +4906,56 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) { // not from the target file. func (s *DockerSuite) TestBuildSymlinkBasename(c *check.C) { name := "testbuildbrokensymlink" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY asymlink /`, map[string]string{ "foo": "bar", }) - c.Assert(err, checker.IsNil) defer ctx.Close() - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) + err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) c.Assert(err, checker.IsNil) - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "asymlink") + out, _ := dockerCmd(c, "run", "--rm", name, "cat", "asymlink") c.Assert(out, checker.Matches, "bar") - } // #17827 func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) { name := "testbuildrootsource" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM busybox COPY / /data`, map[string]string{ "foo": "bar", }) - c.Assert(err, checker.IsNil) defer ctx.Close() // warm up cache - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) // change file, should invalidate cache - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) + err := ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) c.Assert(err, checker.IsNil) - _, out, err := buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) + result := buildImage(name, withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) - c.Assert(out, checker.Not(checker.Contains), "Using cache") + c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") } // #19375 func (s *DockerSuite) TestBuildFailsGitNotCallable(c *check.C) { - buildImageNew("gitnotcallable", withEnvironmentVariales("PATH="), + buildImage("gitnotcallable", withEnvironmentVariales("PATH="), withBuildContextPath("github.com/docker/v1.10-migrator.git")).Assert(c, icmd.Expected{ ExitCode: 1, Err: "unable to prepare context: unable to find 'git': ", }) - buildImageNew("gitnotcallable", withEnvironmentVariales("PATH="), + buildImage("gitnotcallable", withEnvironmentVariales("PATH="), withBuildContextPath("https://github.com/docker/v1.10-migrator.git")).Assert(c, icmd.Expected{ ExitCode: 1, Err: "unable to prepare context: unable to find 'git': ", @@ -5541,7 +5282,7 @@ func (s *DockerSuite) TestBuildShellUpdatesConfig(c *check.C) { func (s *DockerSuite) TestBuildShellMultiple(c *check.C) { name := "testbuildshellmultiple" - result := buildImageNew(name, withDockerfile(`FROM busybox + result := buildImage(name, withDockerfile(`FROM busybox RUN echo defaultshell SHELL ["echo"] RUN echoshell @@ -5594,7 +5335,7 @@ func (s *DockerSuite) TestBuildShellInherited(c *check.C) { buildImageSuccessfully(c, name1, withDockerfile(`FROM busybox SHELL ["ls"]`)) name2 := "testbuildshellinherited2" - buildImageNew(name2, withDockerfile(`FROM `+name1+` + buildImage(name2, withDockerfile(`FROM `+name1+` RUN -l`)).Assert(c, icmd.Expected{ // ls -l has "total " followed by some number in it, ls without -l does not. Out: "total ", @@ -5605,7 +5346,7 @@ func (s *DockerSuite) TestBuildShellInherited(c *check.C) { func (s *DockerSuite) TestBuildShellNotJSON(c *check.C) { name := "testbuildshellnotjson" - buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` + buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` sHeLl exec -form`, // Casing explicit to ensure error is upper-cased. )).Assert(c, icmd.Expected{ ExitCode: 1, @@ -5618,7 +5359,7 @@ func (s *DockerSuite) TestBuildShellNotJSON(c *check.C) { func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) { testRequires(c, DaemonIsWindows) name := "testbuildshellpowershell" - buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` + buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` SHELL ["powershell", "-command"] RUN Write-Host John`)).Assert(c, icmd.Expected{ Out: "\nJohn\n", @@ -5630,7 +5371,7 @@ func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) { func (s *DockerSuite) TestBuildEscapeNotBackslashWordTest(c *check.C) { testRequires(c, DaemonIsWindows) name := "testbuildescapenotbackslashwordtesta" - buildImageNew(name, withDockerfile(`# escape= `+"`"+` + buildImage(name, withDockerfile(`# escape= `+"`"+` FROM `+minimalBaseImage()+` WORKDIR c:\windows RUN dir /w`)).Assert(c, icmd.Expected{ @@ -5638,7 +5379,7 @@ func (s *DockerSuite) TestBuildEscapeNotBackslashWordTest(c *check.C) { }) name = "testbuildescapenotbackslashwordtestb" - buildImageNew(name, withDockerfile(`# escape= `+"`"+` + buildImage(name, withDockerfile(`# escape= `+"`"+` FROM `+minimalBaseImage()+` SHELL ["powershell.exe"] WORKDIR c:\foo @@ -5673,7 +5414,7 @@ func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) { func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) { name := "testbuildstepswithprogress" totalRun := 5 - result := buildImageNew(name, withDockerfile("FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun))) + result := buildImage(name, withDockerfile("FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun))) result.Assert(c, icmd.Success) c.Assert(result.Combined(), checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun)) for i := 2; i <= 1+totalRun; i++ { @@ -5686,14 +5427,14 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) { // First test case can only detect `nobody` in runtime so all steps will show up dockerfile := "FROM busybox\nRUN nobody" - result := buildImageNew(name, withDockerfile(dockerfile)) + result := buildImage(name, withDockerfile(dockerfile)) c.Assert(result.Error, checker.NotNil) c.Assert(result.Stdout(), checker.Contains, "Step 1/2 : FROM busybox") c.Assert(result.Stdout(), checker.Contains, "Step 2/2 : RUN nobody") // Second test case `FFOM` should have been detected before build runs so no steps dockerfile = "FFOM nobody\nRUN nobody" - result = buildImageNew(name, withDockerfile(dockerfile)) + result = buildImage(name, withDockerfile(dockerfile)) c.Assert(result.Error, checker.NotNil) c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 1/2 : FROM busybox") c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody") @@ -5706,28 +5447,29 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { ENV FOO=bar ADD baz / RUN touch bax` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "Dockerfile": dockerfile, "baz": "baz", }) - c.Assert(err, checker.IsNil) defer ctx.Close() - id1, err := buildImageFromContext("build1", ctx, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx)) + id1 := getIDByName(c, "build1") // rebuild with cache-from - id2, out, err := buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) + 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(out, "Using cache"), checker.Equals, 3) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) dockerCmd(c, "rmi", "build2") // no cache match with unknown source - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=nosuchtag") - c.Assert(err, checker.IsNil) + result = buildImage("build2", withBuildFlags("--cache-from=nosuchtag"), withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + id2 = getIDByName(c, "build2") c.Assert(id1, checker.Not(checker.Equals), id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 0) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 0) dockerCmd(c, "rmi", "build2") // clear parent images @@ -5744,17 +5486,19 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { c.Assert(strings.TrimSpace(parentID), checker.Equals, "") // cache still applies without parents - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) + 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(out, "Using cache"), checker.Equals, 3) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) history1, _ := dockerCmd(c, "history", "-q", "build2") // Retry, no new intermediate images - id3, out, err := buildImageFromContextWithOut("build3", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) + result = buildImage("build3", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + id3 := getIDByName(c, "build3") c.Assert(id1, checker.Equals, id3) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) history2, _ := dockerCmd(c, "history", "-q", "build3") c.Assert(history1, checker.Equals, history2) @@ -5772,10 +5516,11 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { err = ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(dockerfile), 0644) c.Assert(err, checker.IsNil) - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) + result = buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) + result.Assert(c, icmd.Success) + id2 = getIDByName(c, "build2") c.Assert(id1, checker.Not(checker.Equals), id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 2) + c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) layers1Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1") layers2Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2") @@ -5795,7 +5540,7 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { func (s *DockerSuite) TestBuildNetNone(c *check.C) { testRequires(c, DaemonIsLinux) name := "testbuildnetnone" - buildImageNew(name, withBuildFlags("--network=none"), withDockerfile(` + buildImage(name, withBuildFlags("--network=none"), withDockerfile(` FROM busybox RUN ping -c 1 8.8.8.8 `)).Assert(c, icmd.Expected{ @@ -5833,13 +5578,11 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { // build and get the ID that we can use later for history comparison name := "test" buildImageSuccessfully(c, name, withDockerfile(dockerFile)) - origID, err := getIDByName(name) - c.Assert(err, checker.IsNil) + origID := getIDByName(c, name) // build with squash buildImageSuccessfully(c, name, withBuildFlags("--squash"), withDockerfile(dockerFile)) - id, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id := getIDByName(c, name) out, _ := dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", "cat /hello") c.Assert(strings.TrimSpace(out), checker.Equals, "hello\nworld") @@ -5867,23 +5610,23 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { func (s *DockerSuite) TestBuildContChar(c *check.C) { name := "testbuildcontchar" - buildImageNew(name, withDockerfile(`FROM busybox\`)).Assert(c, icmd.Expected{ + buildImage(name, withDockerfile(`FROM busybox\`)).Assert(c, icmd.Expected{ Out: "Step 1/1 : FROM busybox", }) - result := buildImageNew(name, withDockerfile(`FROM busybox + result := buildImage(name, withDockerfile(`FROM busybox RUN echo hi \`)) result.Assert(c, icmd.Success) c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi\n") - result = buildImageNew(name, withDockerfile(`FROM busybox + result = buildImage(name, withDockerfile(`FROM busybox RUN echo hi \\`)) result.Assert(c, icmd.Success) c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\n") - result = buildImageNew(name, withDockerfile(`FROM busybox + result = buildImage(name, withDockerfile(`FROM busybox RUN echo hi \\\`)) result.Assert(c, icmd.Success) c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") @@ -5911,7 +5654,7 @@ func (s *DockerSuite) TestBuildOpaqueDirectory(c *check.C) { func (s *DockerSuite) TestBuildWindowsUser(c *check.C) { testRequires(c, DaemonIsWindows) name := "testbuildwindowsuser" - buildImageNew(name, withDockerfile(`FROM `+testEnv.MinimalBaseImage()+` + buildImage(name, withDockerfile(`FROM `+testEnv.MinimalBaseImage()+` RUN net user user /add USER user RUN set username @@ -5987,7 +5730,7 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) { WORKDIR / ` buildImageSuccessfully(c, name, withDockerfile(dockerFile)) - result := buildImageNew(name, withDockerfile(dockerFile)) + result := buildImage(name, withDockerfile(dockerFile)) result.Assert(c, icmd.Success) c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 1) } @@ -5995,7 +5738,7 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) { name := "test_build_line_error_onbuild" - buildImageNew(name, withDockerfile(`FROM busybox + buildImage(name, withDockerfile(`FROM busybox ONBUILD `)).Assert(c, icmd.Expected{ ExitCode: 1, @@ -6006,7 +5749,7 @@ func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) { name := "test_build_line_error_unknown_instruction" - buildImageNew(name, withDockerfile(`FROM busybox + buildImage(name, withDockerfile(`FROM busybox RUN echo hello world NOINSTRUCTION echo ba RUN echo hello @@ -6020,7 +5763,7 @@ func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) { name := "test_build_line_error_with_empty_lines" - buildImageNew(name, withDockerfile(` + buildImage(name, withDockerfile(` FROM busybox RUN echo hello world @@ -6037,7 +5780,7 @@ func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) { name := "test_build_line_error_with_comments" - buildImageNew(name, withDockerfile(`FROM busybox + buildImage(name, withDockerfile(`FROM busybox # This will print hello world # and then ba RUN echo hello world diff --git a/integration-cli/docker_cli_build_unix_test.go b/integration-cli/docker_cli_build_unix_test.go index 386ca40360..f430fda235 100644 --- a/integration-cli/docker_cli_build_unix_test.go +++ b/integration-cli/docker_cli_build_unix_test.go @@ -25,13 +25,11 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { testRequires(c, cpuCfsQuota) name := "testbuildresourceconstraints" - ctx, err := fakeContext(` + ctx := fakeContext(c, ` FROM hello-world:frozen RUN ["/hello"] `, map[string]string{}) - c.Assert(err, checker.IsNil) - - _, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".") + _, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".") if err != nil { c.Fatal(err) } @@ -114,9 +112,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) { defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddChangeOwnership: %v", err) - } + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) } // Test that an infinite sleep during a build is killed if the client disconnects. @@ -137,10 +133,7 @@ func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) { defer observer.Stop() // (Note: one year, will never finish) - ctx, err := fakeContext("FROM busybox\nRUN sleep 31536000", nil) - if err != nil { - c.Fatal(err) - } + ctx := fakeContext(c, "FROM busybox\nRUN sleep 31536000", nil) defer ctx.Close() buildCmd := exec.Command(dockerBinary, "build", "-t", name, ".") diff --git a/integration-cli/docker_cli_by_digest_test.go b/integration-cli/docker_cli_by_digest_test.go index 62c72bad4d..ec3983052a 100644 --- a/integration-cli/docker_cli_by_digest_test.go +++ b/integration-cli/docker_cli_by_digest_test.go @@ -193,10 +193,9 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { // do the build name := "buildbydigest" - _, err = buildImage(name, fmt.Sprintf( + buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf( `FROM %s - CMD ["/bin/echo", "Hello World"]`, imageReference), - true) + CMD ["/bin/echo", "Hello World"]`, imageReference))) c.Assert(err, checker.IsNil) // get the build's image id @@ -417,20 +416,17 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c // build an image from it imageName1 := "images_ps_filter_test" - _, err = buildImage(imageName1, fmt.Sprintf( + buildImageSuccessfully(c, imageName1, withDockerfile(fmt.Sprintf( `FROM %s - LABEL match me 1`, imageReference), true) - c.Assert(err, checker.IsNil) + LABEL match me 1`, imageReference))) // run a container based on that dockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello") - expectedID, err := getIDByName("test1") - c.Assert(err, check.IsNil) + expectedID := getIDByName(c, "test1") // run a container based on the a descendant of that too dockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello") - expectedID1, err := getIDByName("test2") - c.Assert(err, check.IsNil) + expectedID1 := getIDByName(c, "test2") expectedIDs := []string{expectedID, expectedID1} diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go index 0d4785ae90..09c6e96127 100644 --- a/integration-cli/docker_cli_create_test.go +++ b/integration-cli/docker_cli_create_test.go @@ -204,12 +204,8 @@ func (s *DockerSuite) TestCreateLabels(c *check.C) { func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) { imageName := "testcreatebuildlabel" - _, err := buildImage(imageName, - `FROM busybox - LABEL k1=v1 k2=v2`, - true) - - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox + LABEL k1=v1 k2=v2`)) name := "test_create_labels_from_image" expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"} @@ -263,13 +259,9 @@ func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) { func (s *DockerSuite) TestCreateByImageID(c *check.C) { imageName := "testcreatebyimageid" - imageID, err := buildImage(imageName, - `FROM busybox - MAINTAINER dockerio`, - true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox + MAINTAINER dockerio`)) + imageID := getIDByName(c, imageName) truncatedImageID := stringid.TruncateID(imageID) dockerCmd(c, "create", imageID) @@ -444,16 +436,14 @@ RUN chmod 755 /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] CMD echo foobar` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "entrypoint.sh": `#!/bin/sh echo "I am an entrypoint" exec "$@"`, }) - c.Assert(err, check.IsNil) defer ctx.Close() - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo") id := strings.TrimSpace(out) diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 265f135da5..63abb233fa 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -379,11 +379,9 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) { label := "io.docker.testing=image" // Build a test image. - _, err := buildImage(name, fmt.Sprintf(` + buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(` FROM busybox:latest - LABEL %s`, label), true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) - + LABEL %s`, label))) dockerCmd(c, "tag", name, "labelfiltertest:tag1") dockerCmd(c, "tag", name, "labelfiltertest:tag2") dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") @@ -462,10 +460,10 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) { func (s *DockerSuite) TestEventsCopy(c *check.C) { // Build a test image. - id, err := buildImage("cpimg", ` + buildImageSuccessfully(c, "cpimg", withDockerfile(` FROM busybox - RUN echo HI > /file`, true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) + RUN echo HI > /file`)) + id := getIDByName(c, "cpimg") // Create an empty test file. tempFile, err := ioutil.TempFile("", "test-events-copy-") @@ -595,11 +593,9 @@ func (s *DockerSuite) TestEventsFilterType(c *check.C) { label := "io.docker.testing=image" // Build a test image. - _, err := buildImage(name, fmt.Sprintf(` + buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(` FROM busybox:latest - LABEL %s`, label), true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) - + LABEL %s`, label))) dockerCmd(c, "tag", name, "labelfiltertest:tag1") dockerCmd(c, "tag", name, "labelfiltertest:tag2") dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") diff --git a/integration-cli/docker_cli_events_unix_test.go b/integration-cli/docker_cli_events_unix_test.go index 41bd35e3ff..bbbef57ecd 100644 --- a/integration-cli/docker_cli_events_unix_test.go +++ b/integration-cli/docker_cli_events_unix_test.go @@ -310,11 +310,9 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) { defer observer.Stop() name := "testimageevents" - imageID, err := buildImage(name, - `FROM scratch - MAINTAINER "docker"`, - true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withDockerfile(`FROM scratch + MAINTAINER "docker"`)) + imageID := getIDByName(c, name) c.Assert(deleteImages(name), checker.IsNil) testActions := map[string]chan bool{ diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index bffd60b696..c8f7f99a82 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -473,13 +473,9 @@ func (s *DockerSuite) TestExecWithImageUser(c *check.C) { // Not applicable on Windows testRequires(c, DaemonIsLinux) name := "testbuilduser" - _, err := buildImage(name, - `FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd - USER dockerio`, - true) - c.Assert(err, checker.IsNil) - + USER dockerio`)) dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top") out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami") diff --git a/integration-cli/docker_cli_health_test.go b/integration-cli/docker_cli_health_test.go index e48f572cf2..911e035f8c 100644 --- a/integration-cli/docker_cli_health_test.go +++ b/integration-cli/docker_cli_health_test.go @@ -40,16 +40,12 @@ func (s *DockerSuite) TestHealth(c *check.C) { testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows imageName := "testhealth" - _, err := buildImage(imageName, - `FROM busybox + buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox RUN echo OK > /status CMD ["/bin/sleep", "120"] STOPSIGNAL SIGKILL HEALTHCHECK --interval=1s --timeout=30s \ - CMD cat /status`, - true) - - c.Check(err, check.IsNil) + CMD cat /status`)) // No health status before starting name := "test_health" @@ -91,10 +87,8 @@ func (s *DockerSuite) TestHealth(c *check.C) { dockerCmd(c, "rm", "noh") // Disable the check with a new build - _, err = buildImage("no_healthcheck", - `FROM testhealth - HEALTHCHECK NONE`, true) - c.Check(err, check.IsNil) + buildImageSuccessfully(c, "no_healthcheck", withDockerfile(`FROM testhealth + HEALTHCHECK NONE`)) out, _ = dockerCmd(c, "inspect", "--format={{.ContainerConfig.Healthcheck.Test}}", "no_healthcheck") c.Check(out, checker.Equals, "[NONE]\n") @@ -137,15 +131,12 @@ func (s *DockerSuite) TestHealth(c *check.C) { dockerCmd(c, "rm", "-f", "test") // Check JSON-format - _, err = buildImage(imageName, - `FROM busybox + buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox RUN echo OK > /status CMD ["/bin/sleep", "120"] STOPSIGNAL SIGKILL HEALTHCHECK --interval=1s --timeout=30s \ - CMD ["cat", "/my status"]`, - true) - c.Check(err, check.IsNil) + CMD ["cat", "/my status"]`)) out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", imageName) c.Check(out, checker.Equals, "[CMD cat /my status]\n") diff --git a/integration-cli/docker_cli_history_test.go b/integration-cli/docker_cli_history_test.go index bc7d269d00..621b904824 100644 --- a/integration-cli/docker_cli_history_test.go +++ b/integration-cli/docker_cli_history_test.go @@ -14,7 +14,7 @@ import ( // sort is not predictable it doesn't always fail. func (s *DockerSuite) TestBuildHistory(c *check.C) { name := "testbuildhistory" - _, err := buildImage(name, `FROM `+minimalBaseImage()+` + buildImageSuccessfully(c, name, withDockerfile(`FROM `+minimalBaseImage()+` LABEL label.A="A" LABEL label.B="B" LABEL label.C="C" @@ -40,12 +40,9 @@ LABEL label.V="V" LABEL label.W="W" LABEL label.X="X" LABEL label.Y="Y" -LABEL label.Z="Z"`, - true) +LABEL label.Z="Z"`)) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "history", "testbuildhistory") + out, _ := dockerCmd(c, "history", name) actualValues := strings.Split(out, "\n")[1:27] expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"} diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index 79a8a34b7d..61c700362e 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/integration-cli/docker_cli_images_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/pkg/stringid" + icmd "github.com/docker/docker/pkg/testutil/cmd" "github.com/go-check/check" ) @@ -45,20 +46,17 @@ func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) { } func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) { - id1, err := buildImage("order:test_a", - `FROM busybox - MAINTAINER dockerio1`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "order:test_a", withDockerfile(`FROM busybox + MAINTAINER dockerio1`)) + id1 := getIDByName(c, "order:test_a") time.Sleep(1 * time.Second) - id2, err := buildImage("order:test_c", - `FROM busybox - MAINTAINER dockerio2`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "order:test_c", withDockerfile(`FROM busybox + MAINTAINER dockerio2`)) + id2 := getIDByName(c, "order:test_c") time.Sleep(1 * time.Second) - id3, err := buildImage("order:test_b", - `FROM busybox - MAINTAINER dockerio3`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "order:test_b", withDockerfile(`FROM busybox + MAINTAINER dockerio3`)) + id3 := getIDByName(c, "order:test_b") out, _ := dockerCmd(c, "images", "-q", "--no-trunc") imgs := strings.Split(out, "\n") @@ -77,20 +75,17 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) { imageName1 := "images_filter_test1" imageName2 := "images_filter_test2" imageName3 := "images_filter_test3" - image1ID, err := buildImage(imageName1, - `FROM busybox - LABEL match me`, true) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox + LABEL match me`)) + image1ID := getIDByName(c, imageName1) - image2ID, err := buildImage(imageName2, - `FROM busybox - LABEL match="me too"`, true) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, imageName2, withDockerfile(`FROM busybox + LABEL match="me too"`)) + image2ID := getIDByName(c, imageName2) - image3ID, err := buildImage(imageName3, - `FROM busybox - LABEL nomatch me`, true) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, imageName3, withDockerfile(`FROM busybox + LABEL nomatch me`)) + image3ID := getIDByName(c, imageName3) out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match") out = strings.TrimSpace(out) @@ -117,15 +112,15 @@ func (s *DockerSuite) TestImagesFilterLabelWithCommit(c *check.C) { } func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) { - imageID1, err := buildImage("image:1", `FROM `+minimalBaseImage()+` -LABEL number=1`, true) - c.Assert(err, checker.IsNil) - imageID2, err := buildImage("image:2", `FROM `+minimalBaseImage()+` -LABEL number=2`, true) - c.Assert(err, checker.IsNil) - imageID3, err := buildImage("image:3", `FROM `+minimalBaseImage()+` -LABEL number=3`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "image:1", withDockerfile(`FROM `+minimalBaseImage()+` +LABEL number=1`)) + imageID1 := getIDByName(c, "image:1") + buildImageSuccessfully(c, "image:2", withDockerfile(`FROM `+minimalBaseImage()+` +LABEL number=2`)) + imageID2 := getIDByName(c, "image:2") + buildImageSuccessfully(c, "image:3", withDockerfile(`FROM `+minimalBaseImage()+` +LABEL number=3`)) + imageID3 := getIDByName(c, "image:3") expected := []string{imageID3, imageID2} @@ -185,13 +180,16 @@ func assertImageList(out string, expected []string) bool { return true } +// FIXME(vdemeester) should be a unit test on `docker image ls` func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) { imageName := "images_filter_test" - buildImage(imageName, - `FROM busybox + // Build a image and fail to build so that we have dangling images ? + buildImage(imageName, withDockerfile(`FROM busybox RUN touch /test/foo RUN touch /test/bar - RUN touch /test/baz`, true) + RUN touch /test/baz`)).Assert(c, icmd.Expected{ + ExitCode: 1, + }) filters := []string{ "dangling=true", @@ -250,6 +248,7 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) { } +// FIXME(vdemeester) should be a unit test for `docker image ls` func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) { out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") c.Assert(err, check.NotNil) @@ -261,32 +260,33 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) { FROM busybox MAINTAINER docker ENV foo bar` - - head, out, err := buildImageWithOut("scratch-image", dockerfile, false) - c.Assert(err, check.IsNil) + name := "scratch-image" + result := buildImage(name, withDockerfile(dockerfile)) + result.Assert(c, icmd.Success) + id := getIDByName(c, name) // this is just the output of docker build // we're interested in getting the image id of the MAINTAINER instruction // and that's located at output, line 5, from 7 to end - split := strings.Split(out, "\n") + split := strings.Split(result.Combined(), "\n") intermediate := strings.TrimSpace(split[5][7:]) - out, _ = dockerCmd(c, "images") + out, _ := dockerCmd(c, "images") // images shouldn't show non-heads images c.Assert(out, checker.Not(checker.Contains), intermediate) // images should contain final built images - c.Assert(out, checker.Contains, stringid.TruncateID(head)) + c.Assert(out, checker.Contains, stringid.TruncateID(id)) } func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) { testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch - dockerfile := ` FROM scratch MAINTAINER docker` - id, _, err := buildImageWithOut("scratch-image", dockerfile, false) - c.Assert(err, check.IsNil) + name := "scratch-image" + buildImageSuccessfully(c, name, withDockerfile(dockerfile)) + id := getIDByName(c, name) out, _ := dockerCmd(c, "images") // images should contain images built from scratch @@ -299,9 +299,10 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) { dockerfile := ` FROM busybox MAINTAINER docker` + name := "busybox-image" - id, _, err := buildImageWithOut("busybox-image", dockerfile, false) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, name, withDockerfile(dockerfile)) + id := getIDByName(c, name) out, _ := dockerCmd(c, "images") // images should contain images built from busybox diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 493b73c4a8..49b9fb170a 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -130,8 +130,7 @@ func (s *DockerSuite) TestLogsTail(c *check.C) { func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") - id, err := getIDByName("test") - c.Assert(err, check.IsNil) + id := getIDByName(c, "test") logsCmd := exec.Command(dockerBinary, "logs", "-f", id) c.Assert(logsCmd.Start(), checker.IsNil) diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 55a23703cd..16f0c22765 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -157,8 +157,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) { name := "test_size" dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") - id, err := getIDByName(name) - c.Assert(err, checker.IsNil) + id := getIDByName(c, name) runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1") var out string @@ -286,8 +285,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) { func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) { // start container dockerCmd(c, "run", "--name=a_name_to_match", "busybox") - id, err := getIDByName("a_name_to_match") - c.Assert(err, check.IsNil) + id := getIDByName(c, "a_name_to_match") // start another container runSleepingContainer(c, "--name=b_name_to_match") @@ -309,47 +307,39 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) { func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) { // Build images imageName1 := "images_ps_filter_test1" - imageID1, err := buildImage(imageName1, - `FROM busybox - LABEL match me 1`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox + LABEL match me 1`)) + imageID1 := getIDByName(c, imageName1) imageName1Tagged := "images_ps_filter_test1:tag" - imageID1Tagged, err := buildImage(imageName1Tagged, - `FROM busybox - LABEL match me 1 tagged`, true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, imageName1Tagged, withDockerfile(`FROM busybox + LABEL match me 1 tagged`)) + imageID1Tagged := getIDByName(c, imageName1Tagged) imageName2 := "images_ps_filter_test2" - imageID2, err := buildImage(imageName2, - fmt.Sprintf(`FROM %s - LABEL match me 2`, imageName1), true) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, imageName2, withDockerfile(fmt.Sprintf(`FROM %s + LABEL match me 2`, imageName1))) + imageID2 := getIDByName(c, imageName2) // start containers dockerCmd(c, "run", "--name=first", "busybox", "echo", "hello") - firstID, err := getIDByName("first") - c.Assert(err, check.IsNil) + firstID := getIDByName(c, "first") // start another container dockerCmd(c, "run", "--name=second", "busybox", "echo", "hello") - secondID, err := getIDByName("second") - c.Assert(err, check.IsNil) + secondID := getIDByName(c, "second") // start third container dockerCmd(c, "run", "--name=third", imageName1, "echo", "hello") - thirdID, err := getIDByName("third") - c.Assert(err, check.IsNil) + thirdID := getIDByName(c, "third") // start fourth container dockerCmd(c, "run", "--name=fourth", imageName1Tagged, "echo", "hello") - fourthID, err := getIDByName("fourth") - c.Assert(err, check.IsNil) + fourthID := getIDByName(c, "fourth") // start fifth container dockerCmd(c, "run", "--name=fifth", imageName2, "echo", "hello") - fifthID, err := getIDByName("fifth") - c.Assert(err, check.IsNil) + fifthID := getIDByName(c, "fifth") var filterTestSuite = []struct { filterName string @@ -410,18 +400,15 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) { // start container dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox") - firstID, err := getIDByName("first") - c.Assert(err, check.IsNil) + firstID := getIDByName(c, "first") // start another container dockerCmd(c, "run", "--name=second", "-l", "match=me too", "busybox") - secondID, err := getIDByName("second") - c.Assert(err, check.IsNil) + secondID := getIDByName(c, "second") // start third container dockerCmd(c, "run", "--name=third", "-l", "nomatch=me", "busybox") - thirdID, err := getIDByName("third") - c.Assert(err, check.IsNil) + thirdID := getIDByName(c, "third") // filter containers by exact match out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me") @@ -450,23 +437,19 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) { runSleepingContainer(c, "--name=sleep") dockerCmd(c, "run", "--name", "zero1", "busybox", "true") - firstZero, err := getIDByName("zero1") - c.Assert(err, checker.IsNil) + firstZero := getIDByName(c, "zero1") dockerCmd(c, "run", "--name", "zero2", "busybox", "true") - secondZero, err := getIDByName("zero2") - c.Assert(err, checker.IsNil) + secondZero := getIDByName(c, "zero2") out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false") c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) - firstNonZero, err := getIDByName("nonzero1") - c.Assert(err, checker.IsNil) + firstNonZero := getIDByName(c, "nonzero1") out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false") c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) - secondNonZero, err := getIDByName("nonzero2") - c.Assert(err, checker.IsNil) + secondNonZero := getIDByName(c, "nonzero2") // filter containers by exited=0 out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") @@ -671,8 +654,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) { icmd.RunCommand(dockerBinary, "tag", "busybox:latest", originalImageName).Assert(c, icmd.Success) - originalImageID, err := getIDByName(originalImageName) - c.Assert(err, checker.IsNil) + originalImageID := getIDByName(c, originalImageName) result := icmd.RunCommand(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...) result.Assert(c, icmd.Success) diff --git a/integration-cli/docker_cli_pull_local_test.go b/integration-cli/docker_cli_pull_local_test.go index c504f543f3..1c732bd135 100644 --- a/integration-cli/docker_cli_pull_local_test.go +++ b/integration-cli/docker_cli_pull_local_test.go @@ -65,14 +65,13 @@ func testConcurrentPullWholeRepo(c *check.C) { repos := []string{} for _, tag := range []string{"recent", "fresh", "todays"} { repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` + buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` FROM busybox ENTRYPOINT ["/bin/echo"] ENV FOO foo ENV BAR bar CMD echo %s - `, repo), true) - c.Assert(err, checker.IsNil) + `, repo))) dockerCmd(c, "push", repo) repos = append(repos, repo) } @@ -154,14 +153,13 @@ func testConcurrentPullMultipleTags(c *check.C) { repos := []string{} for _, tag := range []string{"recent", "fresh", "todays"} { repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` + buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` FROM busybox ENTRYPOINT ["/bin/echo"] ENV FOO foo ENV BAR bar CMD echo %s - `, repo), true) - c.Assert(err, checker.IsNil) + `, repo))) dockerCmd(c, "push", repo) repos = append(repos, repo) } @@ -209,21 +207,15 @@ func testPullIDStability(c *check.C) { derivedImage := privateRegistryURL + "/dockercli/id-stability" baseImage := "busybox" - _, err := buildImage(derivedImage, fmt.Sprintf(` + buildImageSuccessfully(c, derivedImage, withDockerfile(fmt.Sprintf(` FROM %s ENV derived true ENV asdf true RUN dd if=/dev/zero of=/file bs=1024 count=1024 CMD echo %s - `, baseImage, derivedImage), true) - if err != nil { - c.Fatal(err) - } + `, baseImage, derivedImage))) - originalID, err := getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } + originalID := getIDByName(c, derivedImage) dockerCmd(c, "push", derivedImage) // Pull @@ -232,10 +224,7 @@ func testPullIDStability(c *check.C) { c.Fatalf("repull redownloaded a layer: %s", out) } - derivedIDAfterPull, err := getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } + derivedIDAfterPull := getIDByName(c, derivedImage) if derivedIDAfterPull != originalID { c.Fatal("image's ID unexpectedly changed after a repush/repull") @@ -252,17 +241,11 @@ func testPullIDStability(c *check.C) { dockerCmd(c, "rmi", derivedImage) dockerCmd(c, "pull", derivedImage) - derivedIDAfterPull, err = getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } + derivedIDAfterPull = getIDByName(c, derivedImage) if derivedIDAfterPull != originalID { c.Fatal("image's ID unexpectedly changed after a repush/repull") } - if err != nil { - c.Fatalf("error inspecting: %v", err) - } // Make sure the image still runs out, _ = dockerCmd(c, "run", "--rm", derivedImage) @@ -283,14 +266,9 @@ func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *check.C) { func testPullNoLayers(c *check.C) { repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL) - _, err := buildImage(repoName, ` + buildImageSuccessfully(c, repoName, withDockerfile(` FROM scratch - ENV foo bar`, - true) - if err != nil { - c.Fatal(err) - } - + ENV foo bar`)) dockerCmd(c, "push", repoName) dockerCmd(c, "rmi", repoName) dockerCmd(c, "pull", repoName) diff --git a/integration-cli/docker_cli_pull_trusted_test.go b/integration-cli/docker_cli_pull_trusted_test.go index b068bb23f3..c1d6e5b55c 100644 --- a/integration-cli/docker_cli_pull_trusted_test.go +++ b/integration-cli/docker_cli_pull_trusted_test.go @@ -149,11 +149,10 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) { func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) { repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, "trusted-pull-delete") // tag the image and upload it to the private registry - _, err := buildImage(repoName, ` + buildImageSuccessfully(c, repoName, withDockerfile(` FROM busybox CMD echo trustedpulldelete - `, true) - + `)) icmd.RunCmd(icmd.Command(dockerBinary, "push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing) dockerCmd(c, "rmi", repoName) @@ -176,7 +175,7 @@ func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) { // rmi of tag should also remove the digest reference dockerCmd(c, "rmi", repoName) - _, err = inspectFieldWithError(imageByDigest, "Id") + _, err := inspectFieldWithError(imageByDigest, "Id") c.Assert(err, checker.NotNil, check.Commentf("digest reference should have been removed")) _, err = inspectFieldWithError(imageID, "Id") diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index aa1b0bd9c0..34374f8c9d 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -161,14 +161,13 @@ func testConcurrentPush(c *check.C) { repos := []string{} for _, tag := range []string{"push1", "push2", "push3"} { repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` + buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` FROM busybox ENTRYPOINT ["/bin/echo"] ENV FOO foo ENV BAR bar CMD echo %s -`, repo), true) - c.Assert(err, checker.IsNil) +`, repo))) repos = append(repos, repo) } diff --git a/integration-cli/docker_cli_restart_test.go b/integration-cli/docker_cli_restart_test.go index 6c9e6b7ca4..17a296d6b1 100644 --- a/integration-cli/docker_cli_restart_test.go +++ b/integration-cli/docker_cli_restart_test.go @@ -12,8 +12,7 @@ import ( func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar") - cleanedContainerID, err := getIDByName("test") - c.Assert(err, check.IsNil) + cleanedContainerID := getIDByName(c, "test") out, _ := dockerCmd(c, "logs", cleanedContainerID) c.Assert(out, checker.Equals, "foobar\n") @@ -21,7 +20,7 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { dockerCmd(c, "restart", cleanedContainerID) // Wait until the container has stopped - err = waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second) + err := waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second) c.Assert(err, checker.IsNil) out, _ = dockerCmd(c, "logs", cleanedContainerID) diff --git a/integration-cli/docker_cli_rm_test.go b/integration-cli/docker_cli_rm_test.go index cce7ec6177..9188ea7fc2 100644 --- a/integration-cli/docker_cli_rm_test.go +++ b/integration-cli/docker_cli_rm_test.go @@ -58,13 +58,12 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) { MAINTAINER Integration Tests` // build first dockerfile - img1, err := buildImage(img, dockerfile1, true) - c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img)) + buildImageSuccessfully(c, img, withDockerfile(dockerfile1)) + img1 := getIDByName(c, img) // run container on first image dockerCmd(c, "run", img) // rebuild dockerfile with a small addition at the end - _, err = buildImage(img, dockerfile2, true) - c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img)) + buildImageSuccessfully(c, img, withDockerfile(dockerfile2)) // try to remove the image, should not error out. out, _, err := dockerCmdWithError("rmi", img) c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out)) diff --git a/integration-cli/docker_cli_rmi_test.go b/integration-cli/docker_cli_rmi_test.go index 876664383f..60d0f1c8e9 100644 --- a/integration-cli/docker_cli_rmi_test.go +++ b/integration-cli/docker_cli_rmi_test.go @@ -147,8 +147,8 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) { // See https://github.com/docker/docker/issues/14116 func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) { dockerfile := "FROM busybox\nRUN echo test 14116\n" - imgID, err := buildImage("test-14116", dockerfile, false) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, "test-14116", withDockerfile(dockerfile)) + imgID := getIDByName(c, "test-14116") newTag := "newtag" dockerCmd(c, "tag", imgID, newTag) @@ -205,14 +205,8 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) { tag1 := imageName + ":tag1" tag2 := imageName + ":tag2" - _, err := buildImage(tag1, - `FROM busybox - MAINTAINER "docker"`, - true) - if err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, tag1, withDockerfile(`FROM busybox + MAINTAINER "docker"`)) dockerCmd(c, "tag", tag1, tag2) out, _ := dockerCmd(c, "rmi", "-f", tag2) @@ -240,8 +234,8 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) { imageIds := make([]string, 2) for i, name := range imageNames { dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name) - id, err := buildImage(name, dockerfile, false) - c.Assert(err, checker.IsNil) + buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) + id := getIDByName(c, name) imageIds[i] = id } @@ -269,9 +263,7 @@ RUN echo 0 #layer0 RUN echo 1 #layer1 RUN echo 2 #layer2 ` - _, err := buildImage(image, dockerfile, false) - c.Assert(err, checker.IsNil) - + buildImageSuccessfully(c, image, withoutCache, withDockerfile(dockerfile)) out, _ := dockerCmd(c, "history", "-q", image) ids := strings.Split(out, "\n") idToTag := ids[2] @@ -294,7 +286,7 @@ RUN echo 2 #layer2 // At this point we have 2 containers, one based on layer2 and another based on layer0. // Try to untag "tmp2" without the -f flag. - out, _, err = dockerCmdWithError("rmi", newTag) + out, _, err := dockerCmdWithError("rmi", newTag) // should not be untagged without the -f flag c.Assert(err, checker.NotNil) c.Assert(out, checker.Contains, cid[:12]) @@ -307,10 +299,9 @@ RUN echo 2 #layer2 } func (*DockerSuite) TestRmiParentImageFail(c *check.C) { - _, err := buildImage("test", ` + buildImageSuccessfully(c, "test", withDockerfile(` FROM busybox - RUN echo hello`, false) - c.Assert(err, checker.IsNil) + RUN echo hello`)) id := inspectField(c, "busybox", "ID") out, _, err := dockerCmdWithError("rmi", id) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 02ea55f177..bb3c3553f8 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -410,10 +410,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) { containerPath = "/test/test" cmd = "true" } - if _, err := buildImage(name, dockerFile, false); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withDockerfile(dockerFile)) dockerCmd(c, "run", "-v", containerPath, name, cmd) } @@ -438,10 +435,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir2(c *check.C) { containerPath = "/test/test" cmd = "true" } - if _, err := buildImage(name, dockerFile, false); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, name, withDockerfile(dockerFile)) dockerCmd(c, "run", "-v", containerPath, name, cmd) } @@ -1409,10 +1403,7 @@ func (s *DockerSuite) TestRunNonRootUserResolvName(c *check.C) { dockerCmd(c, "run", "--name=testperm", "--user=nobody", "busybox", "nslookup", "apt.dockerproject.org") - cID, err := getIDByName("testperm") - if err != nil { - c.Fatal(err) - } + cID := getIDByName(c, "testperm") fmode := (os.FileMode)(0644) finfo, err := os.Stat(containerStorageFile(cID, "resolv.conf")) @@ -1462,10 +1453,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { //1. test that a restarting container gets an updated resolv.conf dockerCmd(c, "run", "--name=first", "busybox", "true") - containerID1, err := getIDByName("first") - if err != nil { - c.Fatal(err) - } + containerID1 := getIDByName(c, "first") // replace resolv.conf with our temporary copy bytesResolvConf := []byte(tmpResolvConf) @@ -1492,10 +1480,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { //2. test that a restarting container does not receive resolv.conf updates // if it modified the container copy of the starting point resolv.conf dockerCmd(c, "run", "--name=second", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf") - containerID2, err := getIDByName("second") - if err != nil { - c.Fatal(err) - } + containerID2 := getIDByName(c, "second") //make a change to resolv.conf (in this case replacing our tmp copy with orig copy) if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { @@ -1581,10 +1566,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { // Run the container so it picks up the old settings dockerCmd(c, "run", "--name=third", "busybox", "true") - containerID3, err := getIDByName("third") - if err != nil { - c.Fatal(err) - } + containerID3 := getIDByName(c, "third") // Create a modified resolv.conf.aside and override resolv.conf with it bytesResolvConf = []byte(tmpResolvConf) @@ -1698,15 +1680,10 @@ func (s *DockerSuite) TestRunCopyVolumeUIDGID(c *check.C) { // Not applicable on Windows as it does not support uid or gid in this way testRequires(c, DaemonIsLinux) name := "testrunvolumesuidgid" - _, err := buildImage(name, - `FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd RUN echo 'dockerio:x:1001:' >> /etc/group - RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`, - true) - if err != nil { - c.Fatal(err) - } + RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`)) // Test that the uid and gid is copied from the image to the volume out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'") @@ -1722,13 +1699,8 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) { // that copies from the image to the volume. testRequires(c, DaemonIsLinux) name := "testruncopyvolumecontent" - _, err := buildImage(name, - `FROM busybox - RUN mkdir -p /hello/local && echo hello > /hello/local/world`, - true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox + RUN mkdir -p /hello/local && echo hello > /hello/local/world`)) // Test that the content is copied from the image to the volume out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello") @@ -1739,13 +1711,9 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) { func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) { name := "testrunmdcleanuponentrypoint" - if _, err := buildImage(name, - `FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox ENTRYPOINT ["echo"] - CMD ["testingpoint"]`, - true); err != nil { - c.Fatal(err) - } + CMD ["testingpoint"]`)) out, exit := dockerCmd(c, "run", "--entrypoint", "whoami", name) if exit != 0 { @@ -1879,9 +1847,7 @@ func testRunWriteSpecialFilesAndNotCommit(c *check.C, name, path string) { func eqToBaseDiff(out string, c *check.C) bool { name := "eqToBaseDiff" + stringutils.GenerateRandomAlphaOnlyString(32) dockerCmd(c, "run", "--name", name, "busybox", "echo", "hello") - cID, err := getIDByName(name) - c.Assert(err, check.IsNil) - + cID := getIDByName(c, name) baseDiff, _ := dockerCmd(c, "diff", cID) baseArr := strings.Split(baseDiff, "\n") sort.Strings(baseArr) @@ -2229,14 +2195,9 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) { // are pre-populated such as is built in the dockerfile used in this test. testRequires(c, DaemonIsLinux) prefix, slash := getPrefixAndSlashFromDaemonPlatform() - if _, err := buildImage("dataimage", - `FROM busybox + buildImageSuccessfully(c, "dataimage", withDockerfile(`FROM busybox RUN ["mkdir", "-p", "/foo"] - RUN ["touch", "/foo/bar"]`, - true); err != nil { - c.Fatal(err) - } - + RUN ["touch", "/foo/bar"]`)) dockerCmd(c, "run", "--name", "test", "-v", prefix+slash+"foo", "busybox") if out, _, err := dockerCmdWithError("run", "--volumes-from", "test", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") { @@ -2265,13 +2226,8 @@ func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) { func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) { testRequires(c, SameHostDaemon) prefix, slash := getPrefixAndSlashFromDaemonPlatform() - if _, err := buildImage("run_volumes_clean_paths", - `FROM busybox - VOLUME `+prefix+`/foo/`, - true); err != nil { - c.Fatal(err) - } - + buildImageSuccessfully(c, "run_volumes_clean_paths", withDockerfile(`FROM busybox + VOLUME `+prefix+`/foo/`)) dockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash) @@ -3444,8 +3400,7 @@ func testRunContainerWithCgroupParent(c *check.C, cgroupParent, name string) { if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) + id := getIDByName(c, name) expectedCgroup := path.Join(cgroupParent, id) found := false for _, path := range cgroupPaths { @@ -3485,8 +3440,7 @@ func testRunInvalidCgroupParent(c *check.C, cgroupParent, cleanCgroupParent, nam if len(cgroupPaths) == 0 { c.Fatalf("unexpected output - %q", string(out)) } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) + id := getIDByName(c, name) expectedCgroup := path.Join(cleanCgroupParent, id) found := false for _, path := range cgroupPaths { @@ -3919,15 +3873,10 @@ func (s *DockerSuite) TestRunInitLayerPathOwnership(c *check.C) { // Not applicable on Windows as it does not support Linux uid/gid ownership testRequires(c, DaemonIsLinux) name := "testetcfileownership" - _, err := buildImage(name, - `FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd RUN echo 'dockerio:x:1001:' >> /etc/group - RUN chown dockerio:dockerio /etc`, - true) - if err != nil { - c.Fatal(err) - } + RUN chown dockerio:dockerio /etc`)) // Test that dockerio ownership of /etc is retained at runtime out, _ := dockerCmd(c, "run", "--rm", name, "stat", "-c", "%U:%G", "/etc") @@ -4056,11 +4005,10 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) { testRequires(c, DaemonIsLinux) testImg := "testvolumecopy" - _, err := buildImage(testImg, ` + buildImageSuccessfully(c, testImg, withDockerfile(` FROM busybox RUN mkdir -p /foo && echo hello > /foo/hello - `, true) - c.Assert(err, check.IsNil) + `)) dockerCmd(c, "run", "-v", "foo:/foo", testImg) out, _ := dockerCmd(c, "run", "-v", "foo:/foo", "busybox", "cat", "/foo/hello") @@ -4136,14 +4084,9 @@ func (s *DockerSuite) TestRunVolumeWithOneCharacter(c *check.C) { func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) { testRequires(c, DaemonIsLinux) // Windows does not support copying data from image to the volume - _, err := buildImage("volumecopy", - `FROM busybox + buildImageSuccessfully(c, "volumecopy", withDockerfile(`FROM busybox RUN mkdir /foo && echo hello > /foo/bar - CMD cat /foo/bar`, - true, - ) - c.Assert(err, checker.IsNil) - + CMD cat /foo/bar`)) dockerCmd(c, "volume", "create", "test") // test with the nocopy flag @@ -4232,22 +4175,20 @@ RUN chmod 755 /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] CMD echo foobar` - ctx, err := fakeContext(dockerfile, map[string]string{ + ctx := fakeContext(c, dockerfile, map[string]string{ "entrypoint.sh": `#!/bin/sh echo "I am an entrypoint" exec "$@"`, }) - c.Assert(err, check.IsNil) defer ctx.Close() - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) + buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo") c.Assert(strings.TrimSpace(out), check.Equals, "foo") // CMD will be reset as well (the same as setting a custom entrypoint) - _, _, err = dockerCmdWithError("run", "--entrypoint=", "-t", name) + _, _, err := dockerCmdWithError("run", "--entrypoint=", "-t", name) c.Assert(err, check.NotNil) c.Assert(err.Error(), checker.Contains, "No command specified") } diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go index 172368e793..11aff09658 100644 --- a/integration-cli/docker_cli_run_unix_test.go +++ b/integration-cli/docker_cli_run_unix_test.go @@ -828,17 +828,11 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) { func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) { name := "img-with-volumes" - _, err := buildImage( - name, - ` + buildImageSuccessfully(c, name, withDockerfile(` FROM busybox VOLUME /run RUN touch /run/stuff - `, - true) - if err != nil { - c.Fatal(err) - } + `)) out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run") c.Assert(out, checker.Not(checker.Contains), "stuff") } diff --git a/integration-cli/docker_cli_save_load_test.go b/integration-cli/docker_cli_save_load_test.go index 73e19558a2..d64a0964df 100644 --- a/integration-cli/docker_cli_save_load_test.go +++ b/integration-cli/docker_cli_save_load_test.go @@ -260,12 +260,9 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) { os.Mkdir(extractionDirectory, 0777) defer os.RemoveAll(tmpDir) - _, err = buildImage(name, - `FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a - RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`, - true) - c.Assert(err, checker.IsNil, check.Commentf("%v", err)) + RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`)) out, _, err := testutil.RunCommandPipelineWithOutput( exec.Command(dockerBinary, "save", name), @@ -358,9 +355,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) { name := "saveloadnotag" - _, err := buildImage(name, "FROM busybox\nENV foo=bar", true) - c.Assert(err, checker.IsNil, check.Commentf("%v", err)) - + buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV foo=bar")) id := inspectField(c, name, "Id") // Test to make sure that save w/o name just shows imageID during load diff --git a/integration-cli/docker_cli_save_load_unix_test.go b/integration-cli/docker_cli_save_load_unix_test.go index 50b0ea6a69..715e18e60b 100644 --- a/integration-cli/docker_cli_save_load_unix_test.go +++ b/integration-cli/docker_cli_save_load_unix_test.go @@ -72,11 +72,9 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) { name := "test-load" - _, err := buildImage(name, ` - FROM busybox + buildImageSuccessfully(c, name, withDockerfile(`FROM busybox RUN touch aa - `, true) - c.Assert(err, check.IsNil) + `)) tmptar := name + ".tar" dockerCmd(c, "save", "-o", tmptar, name) diff --git a/integration-cli/docker_cli_tag_test.go b/integration-cli/docker_cli_tag_test.go index 7c3a5e2b96..7ca9dd41fe 100644 --- a/integration-cli/docker_cli_tag_test.go +++ b/integration-cli/docker_cli_tag_test.go @@ -142,13 +142,9 @@ func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) { // ensure tags cannot create ambiguity with image ids func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { - imageID, err := buildImage("notbusybox:latest", - `FROM busybox - MAINTAINER dockerio`, - true) - if err != nil { - c.Fatal(err) - } + buildImageSuccessfully(c, "notbusybox:latest", withDockerfile(`FROM busybox + MAINTAINER dockerio`)) + imageID := getIDByName(c, "notbusybox:latest") truncatedImageID := stringid.TruncateID(imageID) truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID) @@ -159,7 +155,7 @@ func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { c.Logf("Built image: %s", imageID) // test setting tag fails - _, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag) + _, _, err := dockerCmdWithError("tag", "busybox:latest", truncatedTag) if err != nil { c.Fatalf("Error tagging with an image id: %s", err) } diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 5dd1a3a0dd..ffab690cf9 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -368,52 +368,41 @@ func (f *FakeContext) Close() error { return os.RemoveAll(f.Dir) } -func fakeContextFromNewTempDir() (*FakeContext, error) { +func fakeContextFromNewTempDir(c *check.C) *FakeContext { tmp, err := ioutil.TempDir("", "fake-context") - if err != nil { - return nil, err - } + c.Assert(err, checker.IsNil) if err := os.Chmod(tmp, 0755); err != nil { - return nil, err + c.Fatal(err) } - return fakeContextFromDir(tmp), nil + return fakeContextFromDir(tmp) } func fakeContextFromDir(dir string) *FakeContext { return &FakeContext{dir} } -func fakeContextWithFiles(files map[string]string) (*FakeContext, error) { - ctx, err := fakeContextFromNewTempDir() - if err != nil { - return nil, err - } +func fakeContextWithFiles(c *check.C, files map[string]string) *FakeContext { + ctx := fakeContextFromNewTempDir(c) for file, content := range files { if err := ctx.Add(file, content); err != nil { ctx.Close() - return nil, err + c.Fatal(err) } } - return ctx, nil + return ctx } -func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error { +func fakeContextAddDockerfile(c *check.C, ctx *FakeContext, dockerfile string) { if err := ctx.Add("Dockerfile", dockerfile); err != nil { ctx.Close() - return err + c.Fatal(err) } - return nil } -func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } - if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil { - return nil, err - } - return ctx, nil +func fakeContext(c *check.C, dockerfile string, files map[string]string) *FakeContext { + ctx := fakeContextWithFiles(c, files) + fakeContextAddDockerfile(c, ctx, dockerfile) + return ctx } // FakeStorage is a static file server. It might be running locally or remotely @@ -424,34 +413,28 @@ type FakeStorage interface { CtxDir() string } -func fakeBinaryStorage(archives map[string]*bytes.Buffer) (FakeStorage, error) { - ctx, err := fakeContextFromNewTempDir() - if err != nil { - return nil, err - } +func fakeBinaryStorage(c *check.C, archives map[string]*bytes.Buffer) FakeStorage { + ctx := fakeContextFromNewTempDir(c) for name, content := range archives { if err := ctx.addFile(name, content.Bytes()); err != nil { - return nil, err + c.Fatal(err) } } - return fakeStorageWithContext(ctx) + return fakeStorageWithContext(c, ctx) } // fakeStorage returns either a local or remote (at daemon machine) file server -func fakeStorage(files map[string]string) (FakeStorage, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } - return fakeStorageWithContext(ctx) +func fakeStorage(c *check.C, files map[string]string) FakeStorage { + ctx := fakeContextWithFiles(c, files) + return fakeStorageWithContext(c, ctx) } // fakeStorageWithContext returns either a local or remote (at daemon machine) file server -func fakeStorageWithContext(ctx *FakeContext) (FakeStorage, error) { +func fakeStorageWithContext(c *check.C, ctx *FakeContext) FakeStorage { if testEnv.LocalDaemon() { - return newLocalFakeStorage(ctx) + return newLocalFakeStorage(c, ctx) } - return newRemoteFileServer(ctx) + return newRemoteFileServer(c, ctx) } // localFileStorage is a file storage on the running machine @@ -473,13 +456,13 @@ func (s *localFileStorage) Close() error { return s.FakeContext.Close() } -func newLocalFakeStorage(ctx *FakeContext) (*localFileStorage, error) { +func newLocalFakeStorage(c *check.C, ctx *FakeContext) *localFileStorage { handler := http.FileServer(http.Dir(ctx.Dir)) server := httptest.NewServer(handler) return &localFileStorage{ FakeContext: ctx, Server: server, - }, nil + } } // remoteFileServer is a containerized static file server started on the remote @@ -517,58 +500,45 @@ func (f *remoteFileServer) Close() error { return deleteContainer(false, f.container) } -func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) { +func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer { var ( image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) ) - if err := ensureHTTPServerImage(); err != nil { - return nil, err - } + c.Assert(ensureHTTPServerImage(), checker.IsNil) // Build the image - if err := fakeContextAddDockerfile(ctx, `FROM httpserver -COPY . /static`); err != nil { - return nil, fmt.Errorf("Cannot add Dockerfile to context: %v", err) - } - if _, err := buildImageFromContext(image, ctx, false); err != nil { - return nil, fmt.Errorf("failed building file storage container image: %v", err) - } + fakeContextAddDockerfile(c, ctx, `FROM httpserver +COPY . /static`) + buildImageSuccessfully(c, image, withoutCache, withExternalBuildContext(ctx)) // Start the container - runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--name", container, image) - if out, ec, err := runCommandWithOutput(runCmd); err != nil { - return nil, fmt.Errorf("failed to start file storage container. ec=%v\nout=%s\nerr=%v", ec, out, err) - } + dockerCmd(c, "run", "-d", "-P", "--name", container, image) // Find out the system assigned port - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "port", container, "80/tcp")) - if err != nil { - return nil, fmt.Errorf("failed to find container port: err=%v\nout=%s", err, out) - } - + out, _ := dockerCmd(c, "port", container, "80/tcp") fileserverHostPort := strings.Trim(out, "\n") _, port, err := net.SplitHostPort(fileserverHostPort) if err != nil { - return nil, fmt.Errorf("unable to parse file server host:port: %v", err) + c.Fatalf("unable to parse file server host:port: %v", err) } dockerHostURL, err := url.Parse(daemonHost()) if err != nil { - return nil, fmt.Errorf("unable to parse daemon host URL: %v", err) + c.Fatalf("unable to parse daemon host URL: %v", err) } host, _, err := net.SplitHostPort(dockerHostURL.Host) if err != nil { - return nil, fmt.Errorf("unable to parse docker daemon host:port: %v", err) + c.Fatalf("unable to parse docker daemon host:port: %v", err) } return &remoteFileServer{ container: container, image: image, host: fmt.Sprintf("%s:%s", host, port), - ctx: ctx}, nil + ctx: ctx} } func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) { @@ -671,51 +641,17 @@ func inspectImage(name, filter string) (string, error) { return strings.TrimSpace(out), nil } -func getIDByName(name string) (string, error) { - return inspectFieldWithError(name, "Id") -} - -// Deprecated -func buildImageCmd(name, dockerfile string, useCache bool, buildFlags ...string) *exec.Cmd { - return daemon.BuildImageCmdWithHost(dockerBinary, name, dockerfile, "", useCache, buildFlags...) -} - -// Deprecated -func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, error) { - buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return "", out, fmt.Errorf("failed to build the image: %s", out) - } - id, err := getIDByName(name) - if err != nil { - return "", out, err - } - return id, out, nil -} - -// Deprecated -func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) { - buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) - result := icmd.RunCmd(transformCmd(buildCmd)) - err := result.Error - exitCode := result.ExitCode - if err != nil || exitCode != 0 { - return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) - } - id, err := getIDByName(name) - if err != nil { - return "", result.Stdout(), result.Stderr(), err - } - return id, result.Stdout(), result.Stderr(), nil +func getIDByName(c *check.C, name string) string { + id, err := inspectFieldWithError(name, "Id") + c.Assert(err, checker.IsNil) + return id } func buildImageSuccessfully(c *check.C, name string, cmdOperators ...func(*icmd.Cmd) func()) { - buildImageNew(name, cmdOperators...).Assert(c, icmd.Success) + buildImage(name, cmdOperators...).Assert(c, icmd.Success) } -// FIXME(vdemeester) rename this buildImage once deprecated buildImage is no more -func buildImageNew(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result { +func buildImage(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result { cmd := icmd.Command(dockerBinary, "build", "-t", name) for _, op := range cmdOperators { deferFn := op(&cmd) @@ -733,11 +669,16 @@ func withBuildContextPath(path string) func(*icmd.Cmd) func() { } } -func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() { - ctx, err := fakeContextFromNewTempDir() - if err != nil { - c.Fatalf("error creating build context : %v", err) +func withExternalBuildContext(ctx *FakeContext) func(*icmd.Cmd) func() { + return func(cmd *icmd.Cmd) func() { + cmd.Dir = ctx.Dir + cmd.Command = append(cmd.Command, ".") + return nil } +} + +func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() { + ctx := fakeContextFromNewTempDir(c) for _, op := range contextOperators { if err := op(ctx); err != nil { c.Fatal(err) @@ -796,108 +737,6 @@ func withEnvironmentVariales(envs ...string) func(cmd *icmd.Cmd) func() { } } -// Deprecated -func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) { - id, _, err := buildImageWithOut(name, dockerfile, useCache, buildFlags...) - return id, err -} - -// Deprecated -func buildImageFromContext(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, error) { - id, _, err := buildImageFromContextWithOut(name, ctx, useCache, buildFlags...) - if err != nil { - return "", err - } - return id, nil -} - -// Deprecated -func buildImageFromContextWithOut(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ".") - result := icmd.RunCmd(icmd.Cmd{ - Command: append([]string{dockerBinary}, args...), - Dir: ctx.Dir, - }) - out := result.Combined() - if result.Error != nil || result.ExitCode != 0 { - return "", "", fmt.Errorf("failed to build the image: %s", out) - } - id, err := getIDByName(name) - if err != nil { - return "", "", err - } - return id, out, nil -} - -// Deprecated -func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ".") - - result := icmd.RunCmd(icmd.Cmd{ - Command: append([]string{dockerBinary}, args...), - Dir: ctx.Dir, - }) - exitCode := result.ExitCode - err := result.Error - if err != nil || exitCode != 0 { - return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) - } - id, err := getIDByName(name) - if err != nil { - return "", result.Stdout(), result.Stderr(), err - } - return id, result.Stdout(), result.Stderr(), nil -} - -// Deprecated -func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ctx.RepoURL) - result := icmd.RunCmd(icmd.Cmd{ - Command: append([]string{dockerBinary}, args...), - }) - exitCode := result.ExitCode - err := result.Error - if err != nil || exitCode != 0 { - return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) - } - id, err := getIDByName(name) - if err != nil { - return "", result.Stdout(), result.Stderr(), err - } - return id, result.Stdout(), result.Stderr(), nil -} - -// Deprecated -func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, path) - buildCmd := exec.Command(dockerBinary, args...) - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return "", fmt.Errorf("failed to build the image: %s", out) - } - return getIDByName(name) -} - type gitServer interface { URL() string Close() error @@ -927,69 +766,63 @@ func (g *fakeGit) Close() { os.RemoveAll(g.root) } -func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (*fakeGit, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } +func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalServer bool) *fakeGit { + ctx := fakeContextWithFiles(c, files) defer ctx.Close() curdir, err := os.Getwd() if err != nil { - return nil, err + c.Fatal(err) } defer os.Chdir(curdir) if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to init repo: %s (%s)", err, output) + c.Fatalf("error trying to init repo: %s (%s)", err, output) } err = os.Chdir(ctx.Dir) if err != nil { - return nil, err + c.Fatal(err) } if output, err := exec.Command("git", "config", "user.name", "Fake User").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to set 'user.name': %s (%s)", err, output) + c.Fatalf("error trying to set 'user.name': %s (%s)", err, output) } if output, err := exec.Command("git", "config", "user.email", "fake.user@example.com").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to set 'user.email': %s (%s)", err, output) + c.Fatalf("error trying to set 'user.email': %s (%s)", err, output) } if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to add files to repo: %s (%s)", err, output) + c.Fatalf("error trying to add files to repo: %s (%s)", err, output) } if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to commit to repo: %s (%s)", err, output) + c.Fatalf("error trying to commit to repo: %s (%s)", err, output) } root, err := ioutil.TempDir("", "docker-test-git-repo") if err != nil { - return nil, err + c.Fatal(err) } repoPath := filepath.Join(root, name+".git") if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil { os.RemoveAll(root) - return nil, fmt.Errorf("error trying to clone --bare: %s (%s)", err, output) + c.Fatalf("error trying to clone --bare: %s (%s)", err, output) } err = os.Chdir(repoPath) if err != nil { os.RemoveAll(root) - return nil, err + c.Fatal(err) } if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil { os.RemoveAll(root) - return nil, fmt.Errorf("error trying to git update-server-info: %s (%s)", err, output) + c.Fatalf("error trying to git update-server-info: %s (%s)", err, output) } err = os.Chdir(curdir) if err != nil { os.RemoveAll(root) - return nil, err + c.Fatal(err) } var server gitServer if !enforceLocalServer { // use fakeStorage server, which might be local or remote (at test daemon) - server, err = fakeStorageWithContext(fakeContextFromDir(root)) - if err != nil { - return nil, fmt.Errorf("cannot start fake storage: %v", err) - } + server = fakeStorageWithContext(c, fakeContextFromDir(root)) } else { // always start a local http server on CLI test machine httpServer := httptest.NewServer(http.FileServer(http.Dir(root))) @@ -999,7 +832,7 @@ func newFakeGit(name string, files map[string]string, enforceLocalServer bool) ( root: root, server: server, RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name), - }, nil + } } // Write `content` to the file at path `dst`, creating it if necessary,