- Remove deprecated buildImage* functions
- Rename buildImageNew to buildImage
- Use *check.C in fakeContext* setup and in getIdByName
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
... | ... |
@@ -791,6 +791,7 @@ func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time |
791 | 791 |
} |
792 | 792 |
|
793 | 793 |
// BuildImageCmdWithHost create a build command with the specified arguments. |
794 |
+// Deprecated |
|
794 | 795 |
// FIXME(vdemeester) move this away |
795 | 796 |
func BuildImageCmdWithHost(dockerBinary, name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd { |
796 | 797 |
args := []string{} |
... | ... |
@@ -28,8 +28,7 @@ COPY * /tmp/ |
28 | 28 |
RUN find / -xdev -name ba* |
29 | 29 |
RUN find /tmp/` |
30 | 30 |
} |
31 |
- server, err := fakeStorage(map[string]string{"testD": testD}) |
|
32 |
- c.Assert(err, checker.IsNil) |
|
31 |
+ server := fakeStorage(c, map[string]string{"testD": testD}) |
|
33 | 32 |
defer server.Close() |
34 | 33 |
|
35 | 34 |
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) { |
66 | 66 |
// failed to close tar archive |
67 | 67 |
c.Assert(tw.Close(), checker.IsNil) |
68 | 68 |
|
69 |
- server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ |
|
69 |
+ server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ |
|
70 | 70 |
"testT.tar": buffer, |
71 | 71 |
}) |
72 |
- c.Assert(err, checker.IsNil) |
|
73 |
- |
|
74 | 72 |
defer server.Close() |
75 | 73 |
|
76 | 74 |
res, b, err := request.SockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar", daemonHost()) |
... | ... |
@@ -115,12 +112,11 @@ RUN echo 'right' |
115 | 115 |
// failed to close tar archive |
116 | 116 |
c.Assert(tw.Close(), checker.IsNil) |
117 | 117 |
|
118 |
- server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ |
|
118 |
+ server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ |
|
119 | 119 |
"testT.tar": buffer, |
120 | 120 |
}) |
121 |
- c.Assert(err, checker.IsNil) |
|
122 |
- |
|
123 | 121 |
defer server.Close() |
122 |
+ |
|
124 | 123 |
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar" |
125 | 124 |
res, body, err := request.SockRequestRaw("POST", url, nil, "application/tar", daemonHost()) |
126 | 125 |
c.Assert(err, checker.IsNil) |
... | ... |
@@ -135,11 +131,10 @@ RUN echo 'right' |
135 | 135 |
} |
136 | 136 |
|
137 | 137 |
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) { |
138 |
- git, err := newFakeGit("repo", map[string]string{ |
|
138 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
139 | 139 |
"dockerfile": `FROM busybox |
140 | 140 |
RUN echo from dockerfile`, |
141 | 141 |
}, false) |
142 |
- c.Assert(err, checker.IsNil) |
|
143 | 142 |
defer git.Close() |
144 | 143 |
|
145 | 144 |
res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost()) |
... | ... |
@@ -154,13 +149,12 @@ RUN echo from dockerfile`, |
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) { |
157 |
- git, err := newFakeGit("repo", map[string]string{ |
|
157 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
158 | 158 |
"baz": `FROM busybox |
159 | 159 |
RUN echo from baz`, |
160 | 160 |
"Dockerfile": `FROM busybox |
161 | 161 |
RUN echo from Dockerfile`, |
162 | 162 |
}, false) |
163 |
- c.Assert(err, checker.IsNil) |
|
164 | 163 |
defer git.Close() |
165 | 164 |
|
166 | 165 |
// Make sure it tries to 'dockerfile' query param value |
... | ... |
@@ -177,13 +171,12 @@ RUN echo from Dockerfile`, |
177 | 177 |
|
178 | 178 |
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) { |
179 | 179 |
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows |
180 |
- git, err := newFakeGit("repo", map[string]string{ |
|
180 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
181 | 181 |
"Dockerfile": `FROM busybox |
182 | 182 |
RUN echo from Dockerfile`, |
183 | 183 |
"dockerfile": `FROM busybox |
184 | 184 |
RUN echo from dockerfile`, |
185 | 185 |
}, false) |
186 |
- c.Assert(err, checker.IsNil) |
|
187 | 186 |
defer git.Close() |
188 | 187 |
|
189 | 188 |
// Make sure it tries to 'dockerfile' query param value |
... | ... |
@@ -1766,19 +1766,18 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { |
1766 | 1766 |
destPath := prefix + slash + "foo" |
1767 | 1767 |
|
1768 | 1768 |
var ( |
1769 |
- err error |
|
1770 | 1769 |
testImg string |
1771 | 1770 |
) |
1772 | 1771 |
if testEnv.DaemonPlatform() != "windows" { |
1773 |
- testImg, err = buildImage("test-mount-config", ` |
|
1772 |
+ testImg = "test-mount-config" |
|
1773 |
+ buildImageSuccessfully(c, testImg, withDockerfile(` |
|
1774 | 1774 |
FROM busybox |
1775 | 1775 |
RUN mkdir `+destPath+` && touch `+destPath+slash+`bar |
1776 | 1776 |
CMD cat `+destPath+slash+`bar |
1777 |
- `, true) |
|
1777 |
+ `)) |
|
1778 | 1778 |
} else { |
1779 | 1779 |
testImg = "busybox" |
1780 | 1780 |
} |
1781 |
- c.Assert(err, checker.IsNil) |
|
1782 | 1781 |
|
1783 | 1782 |
type testCase struct { |
1784 | 1783 |
cfg mounttypes.Mount |
... | ... |
@@ -52,9 +52,8 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) { |
52 | 52 |
// TODO Windows to Windows CI: Investigate further why this test fails. |
53 | 53 |
testRequires(c, Network) |
54 | 54 |
testRequires(c, DaemonIsLinux) |
55 |
- out, err := buildImage("saveandload", "FROM busybox\nENV FOO bar", false) |
|
56 |
- c.Assert(err, checker.IsNil) |
|
57 |
- id := strings.TrimSpace(out) |
|
55 |
+ buildImageSuccessfully(c, "saveandload", withDockerfile("FROM busybox\nENV FOO bar")) |
|
56 |
+ id := getIDByName(c, "saveandload") |
|
58 | 57 |
|
59 | 58 |
res, body, err := request.SockRequestRaw("GET", "/images/"+id+"/get", nil, "", daemonHost()) |
60 | 59 |
c.Assert(err, checker.IsNil) |
... | ... |
@@ -77,9 +76,8 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) { |
77 | 77 |
testRequires(c, Network) |
78 | 78 |
} |
79 | 79 |
name := "test-api-images-delete" |
80 |
- out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) |
|
81 |
- c.Assert(err, checker.IsNil) |
|
82 |
- id := strings.TrimSpace(out) |
|
80 |
+ buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar")) |
|
81 |
+ id := getIDByName(c, name) |
|
83 | 82 |
|
84 | 83 |
dockerCmd(c, "tag", name, "test:tag1") |
85 | 84 |
|
... | ... |
@@ -101,10 +99,8 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { |
101 | 101 |
testRequires(c, Network) |
102 | 102 |
} |
103 | 103 |
name := "test-api-images-history" |
104 |
- out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) |
|
105 |
- c.Assert(err, checker.IsNil) |
|
106 |
- |
|
107 |
- id := strings.TrimSpace(out) |
|
104 |
+ buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar")) |
|
105 |
+ id := getIDByName(c, name) |
|
108 | 106 |
|
109 | 107 |
status, body, err := request.SockRequest("GET", "/images/"+id+"/history", nil, daemonHost()) |
110 | 108 |
c.Assert(err, checker.IsNil) |
... | ... |
@@ -271,7 +271,7 @@ func (s *DockerSuite) TestBuildOnBuildLowercase(c *check.C) { |
271 | 271 |
onbuild run echo quux |
272 | 272 |
`)) |
273 | 273 |
|
274 |
- result := buildImageNew(name2, withDockerfile(fmt.Sprintf(` |
|
274 |
+ result := buildImage(name2, withDockerfile(fmt.Sprintf(` |
|
275 | 275 |
FROM %s |
276 | 276 |
`, name))) |
277 | 277 |
result.Assert(c, icmd.Success) |
... | ... |
@@ -361,69 +361,45 @@ ONBUILD ENTRYPOINT ["echo"]`)) |
361 | 361 |
func (s *DockerSuite) TestBuildCacheAdd(c *check.C) { |
362 | 362 |
testRequires(c, DaemonIsLinux) // Windows doesn't have httpserver image yet |
363 | 363 |
name := "testbuildtwoimageswithadd" |
364 |
- server, err := fakeStorage(map[string]string{ |
|
364 |
+ server := fakeStorage(c, map[string]string{ |
|
365 | 365 |
"robots.txt": "hello", |
366 | 366 |
"index.html": "world", |
367 | 367 |
}) |
368 |
- if err != nil { |
|
369 |
- c.Fatal(err) |
|
370 |
- } |
|
371 | 368 |
defer server.Close() |
372 | 369 |
|
373 |
- if _, err := buildImage(name, |
|
374 |
- fmt.Sprintf(`FROM scratch |
|
375 |
- ADD %s/robots.txt /`, server.URL()), |
|
376 |
- true); err != nil { |
|
377 |
- c.Fatal(err) |
|
378 |
- } |
|
379 |
- if err != nil { |
|
380 |
- c.Fatal(err) |
|
381 |
- } |
|
382 |
- deleteImages(name) |
|
383 |
- _, out, err := buildImageWithOut(name, |
|
384 |
- fmt.Sprintf(`FROM scratch |
|
385 |
- ADD %s/index.html /`, server.URL()), |
|
386 |
- true) |
|
387 |
- if err != nil { |
|
388 |
- c.Fatal(err) |
|
389 |
- } |
|
390 |
- if strings.Contains(out, "Using cache") { |
|
370 |
+ buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(`FROM scratch |
|
371 |
+ ADD %s/robots.txt /`, server.URL()))) |
|
372 |
+ |
|
373 |
+ result := buildImage(name, withDockerfile(fmt.Sprintf(`FROM scratch |
|
374 |
+ ADD %s/index.html /`, server.URL()))) |
|
375 |
+ result.Assert(c, icmd.Success) |
|
376 |
+ if strings.Contains(result.Combined(), "Using cache") { |
|
391 | 377 |
c.Fatal("2nd build used cache on ADD, it shouldn't") |
392 | 378 |
} |
393 |
- |
|
394 | 379 |
} |
395 | 380 |
|
396 | 381 |
func (s *DockerSuite) TestBuildLastModified(c *check.C) { |
397 | 382 |
name := "testbuildlastmodified" |
398 | 383 |
|
399 |
- server, err := fakeStorage(map[string]string{ |
|
384 |
+ server := fakeStorage(c, map[string]string{ |
|
400 | 385 |
"file": "hello", |
401 | 386 |
}) |
402 |
- if err != nil { |
|
403 |
- c.Fatal(err) |
|
404 |
- } |
|
405 | 387 |
defer server.Close() |
406 | 388 |
|
407 | 389 |
var out, out2 string |
408 | 390 |
|
409 | 391 |
dFmt := `FROM busybox |
410 | 392 |
ADD %s/file /` |
411 |
- |
|
412 | 393 |
dockerfile := fmt.Sprintf(dFmt, server.URL()) |
413 | 394 |
|
414 |
- if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { |
|
415 |
- c.Fatal(err) |
|
416 |
- } |
|
417 |
- |
|
395 |
+ buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
|
418 | 396 |
out, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
419 | 397 |
|
420 | 398 |
// Build it again and make sure the mtime of the file didn't change. |
421 | 399 |
// Wait a few seconds to make sure the time changed enough to notice |
422 | 400 |
time.Sleep(2 * time.Second) |
423 | 401 |
|
424 |
- if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { |
|
425 |
- c.Fatal(err) |
|
426 |
- } |
|
402 |
+ buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
|
427 | 403 |
out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
428 | 404 |
|
429 | 405 |
if out != out2 { |
... | ... |
@@ -432,19 +408,13 @@ ADD %s/file /` |
432 | 432 |
|
433 | 433 |
// Now 'touch' the file and make sure the timestamp DID change this time |
434 | 434 |
// Create a new fakeStorage instead of just using Add() to help windows |
435 |
- server, err = fakeStorage(map[string]string{ |
|
435 |
+ server = fakeStorage(c, map[string]string{ |
|
436 | 436 |
"file": "hello", |
437 | 437 |
}) |
438 |
- if err != nil { |
|
439 |
- c.Fatal(err) |
|
440 |
- } |
|
441 | 438 |
defer server.Close() |
442 | 439 |
|
443 | 440 |
dockerfile = fmt.Sprintf(dFmt, server.URL()) |
444 |
- |
|
445 |
- if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { |
|
446 |
- c.Fatal(err) |
|
447 |
- } |
|
441 |
+ buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
|
448 | 442 |
out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
449 | 443 |
|
450 | 444 |
if out == out2 { |
... | ... |
@@ -459,28 +429,21 @@ ADD %s/file /` |
459 | 459 |
func (s *DockerSuite) TestBuildModifyFileInFolder(c *check.C) { |
460 | 460 |
name := "testbuildmodifyfileinfolder" |
461 | 461 |
|
462 |
- ctx, err := fakeContext(`FROM busybox |
|
462 |
+ ctx := fakeContext(c, `FROM busybox |
|
463 | 463 |
RUN ["mkdir", "/test"] |
464 | 464 |
ADD folder/file /test/changetarget`, |
465 | 465 |
map[string]string{}) |
466 |
- if err != nil { |
|
467 |
- c.Fatal(err) |
|
468 |
- } |
|
469 | 466 |
defer ctx.Close() |
470 | 467 |
if err := ctx.Add("folder/file", "first"); err != nil { |
471 | 468 |
c.Fatal(err) |
472 | 469 |
} |
473 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
474 |
- if err != nil { |
|
475 |
- c.Fatal(err) |
|
476 |
- } |
|
470 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
471 |
+ id1 := getIDByName(c, name) |
|
477 | 472 |
if err := ctx.Add("folder/file", "second"); err != nil { |
478 | 473 |
c.Fatal(err) |
479 | 474 |
} |
480 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
481 |
- if err != nil { |
|
482 |
- c.Fatal(err) |
|
483 |
- } |
|
475 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
476 |
+ id2 := getIDByName(c, name) |
|
484 | 477 |
if id1 == id2 { |
485 | 478 |
c.Fatal("cache was used even though file contents in folder was changed") |
486 | 479 |
} |
... | ... |
@@ -504,20 +467,16 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte |
504 | 504 |
// Issue #3960: "ADD src ." hangs |
505 | 505 |
func (s *DockerSuite) TestBuildAddSingleFileToWorkdir(c *check.C) { |
506 | 506 |
name := "testaddsinglefiletoworkdir" |
507 |
- ctx, err := fakeContext(`FROM busybox |
|
507 |
+ ctx := fakeContext(c, `FROM busybox |
|
508 | 508 |
ADD test_file .`, |
509 | 509 |
map[string]string{ |
510 | 510 |
"test_file": "test1", |
511 | 511 |
}) |
512 |
- if err != nil { |
|
513 |
- c.Fatal(err) |
|
514 |
- } |
|
515 | 512 |
defer ctx.Close() |
516 | 513 |
|
517 | 514 |
errChan := make(chan error) |
518 | 515 |
go func() { |
519 |
- _, err := buildImageFromContext(name, ctx, true) |
|
520 |
- errChan <- err |
|
516 |
+ errChan <- buildImage(name, withExternalBuildContext(ctx)).Error |
|
521 | 517 |
close(errChan) |
522 | 518 |
}() |
523 | 519 |
select { |
... | ... |
@@ -546,12 +505,9 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' |
546 | 546 |
|
547 | 547 |
func (s *DockerSuite) TestBuildCopyAddMultipleFiles(c *check.C) { |
548 | 548 |
testRequires(c, DaemonIsLinux) // Linux specific test |
549 |
- server, err := fakeStorage(map[string]string{ |
|
549 |
+ server := fakeStorage(c, map[string]string{ |
|
550 | 550 |
"robots.txt": "hello", |
551 | 551 |
}) |
552 |
- if err != nil { |
|
553 |
- c.Fatal(err) |
|
554 |
- } |
|
555 | 552 |
defer server.Close() |
556 | 553 |
|
557 | 554 |
buildImageSuccessfully(c, "testcopymultiplefilestofile", withBuildContext(c, |
... | ... |
@@ -664,16 +620,13 @@ RUN find "test6" "C:/test dir/test_file6"` |
664 | 664 |
|
665 | 665 |
func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { |
666 | 666 |
name := "testcopywildcard" |
667 |
- server, err := fakeStorage(map[string]string{ |
|
667 |
+ server := fakeStorage(c, map[string]string{ |
|
668 | 668 |
"robots.txt": "hello", |
669 | 669 |
"index.html": "world", |
670 | 670 |
}) |
671 |
- if err != nil { |
|
672 |
- c.Fatal(err) |
|
673 |
- } |
|
674 | 671 |
defer server.Close() |
675 | 672 |
|
676 |
- ctx, err := fakeContext(fmt.Sprintf(`FROM busybox |
|
673 |
+ ctx := fakeContext(c, fmt.Sprintf(`FROM busybox |
|
677 | 674 |
COPY file*.txt /tmp/ |
678 | 675 |
RUN ls /tmp/file1.txt /tmp/file2.txt |
679 | 676 |
RUN [ "mkdir", "/tmp1" ] |
... | ... |
@@ -690,21 +643,14 @@ func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { |
690 | 690 |
"dir/nested_dir/nest_nest_file": "2 times nested", |
691 | 691 |
"dirt": "dirty", |
692 | 692 |
}) |
693 |
- if err != nil { |
|
694 |
- c.Fatal(err) |
|
695 |
- } |
|
696 | 693 |
defer ctx.Close() |
697 | 694 |
|
698 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
699 |
- if err != nil { |
|
700 |
- c.Fatal(err) |
|
701 |
- } |
|
695 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
696 |
+ id1 := getIDByName(c, name) |
|
702 | 697 |
|
703 | 698 |
// Now make sure we use a cache the 2nd time |
704 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
705 |
- if err != nil { |
|
706 |
- c.Fatal(err) |
|
707 |
- } |
|
699 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
700 |
+ id2 := getIDByName(c, name) |
|
708 | 701 |
|
709 | 702 |
if id1 != id2 { |
710 | 703 |
c.Fatal("didn't use the cache") |
... | ... |
@@ -734,30 +680,23 @@ func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) { |
734 | 734 |
|
735 | 735 |
func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) { |
736 | 736 |
name := "testcopywildcardcache" |
737 |
- ctx, err := fakeContext(`FROM busybox |
|
737 |
+ ctx := fakeContext(c, `FROM busybox |
|
738 | 738 |
COPY file1.txt /tmp/`, |
739 | 739 |
map[string]string{ |
740 | 740 |
"file1.txt": "test1", |
741 | 741 |
}) |
742 |
- if err != nil { |
|
743 |
- c.Fatal(err) |
|
744 |
- } |
|
745 | 742 |
defer ctx.Close() |
746 | 743 |
|
747 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
748 |
- if err != nil { |
|
749 |
- c.Fatal(err) |
|
750 |
- } |
|
744 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
745 |
+ id1 := getIDByName(c, name) |
|
751 | 746 |
|
752 | 747 |
// Now make sure we use a cache the 2nd time even with wild cards. |
753 | 748 |
// Use the same context so the file is the same and the checksum will match |
754 | 749 |
ctx.Add("Dockerfile", `FROM busybox |
755 | 750 |
COPY file*.txt /tmp/`) |
756 | 751 |
|
757 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
758 |
- if err != nil { |
|
759 |
- c.Fatal(err) |
|
760 |
- } |
|
752 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
753 |
+ id2 := getIDByName(c, name) |
|
761 | 754 |
|
762 | 755 |
if id1 != id2 { |
763 | 756 |
c.Fatal("didn't use the cache") |
... | ... |
@@ -871,20 +810,16 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte |
871 | 871 |
// Issue #3960: "ADD src ." hangs - adapted for COPY |
872 | 872 |
func (s *DockerSuite) TestBuildCopySingleFileToWorkdir(c *check.C) { |
873 | 873 |
name := "testcopysinglefiletoworkdir" |
874 |
- ctx, err := fakeContext(`FROM busybox |
|
874 |
+ ctx := fakeContext(c, `FROM busybox |
|
875 | 875 |
COPY test_file .`, |
876 | 876 |
map[string]string{ |
877 | 877 |
"test_file": "test1", |
878 | 878 |
}) |
879 |
- if err != nil { |
|
880 |
- c.Fatal(err) |
|
881 |
- } |
|
882 | 879 |
defer ctx.Close() |
883 | 880 |
|
884 | 881 |
errChan := make(chan error) |
885 | 882 |
go func() { |
886 |
- _, err := buildImageFromContext(name, ctx, true) |
|
887 |
- errChan <- err |
|
883 |
+ errChan <- buildImage(name, withExternalBuildContext(ctx)).Error |
|
888 | 884 |
close(errChan) |
889 | 885 |
}() |
890 | 886 |
select { |
... | ... |
@@ -985,10 +920,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) { |
985 | 985 |
var ( |
986 | 986 |
name = "test-link-absolute" |
987 | 987 |
) |
988 |
- ctx, err := fakeContext(dockerfile, nil) |
|
989 |
- if err != nil { |
|
990 |
- c.Fatal(err) |
|
991 |
- } |
|
988 |
+ ctx := fakeContext(c, dockerfile, nil) |
|
992 | 989 |
defer ctx.Close() |
993 | 990 |
|
994 | 991 |
tempDir, err := ioutil.TempDir("", "test-link-absolute-temp-") |
... | ... |
@@ -1049,10 +981,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) { |
1049 | 1049 |
c.Fatal(err) |
1050 | 1050 |
} |
1051 | 1051 |
|
1052 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
1053 |
- c.Fatal(err) |
|
1054 |
- } |
|
1055 |
- |
|
1052 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1056 | 1053 |
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { |
1057 | 1054 |
c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) |
1058 | 1055 |
} |
... | ... |
@@ -1083,10 +1012,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { |
1083 | 1083 |
dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir) |
1084 | 1084 |
nonExistingFile := filepath.Join(tempDir, targetFile) |
1085 | 1085 |
|
1086 |
- ctx, err := fakeContext(dockerfile, nil) |
|
1087 |
- if err != nil { |
|
1088 |
- c.Fatal(err) |
|
1089 |
- } |
|
1086 |
+ ctx := fakeContext(c, dockerfile, nil) |
|
1090 | 1087 |
defer ctx.Close() |
1091 | 1088 |
fooPath := filepath.Join(ctx.Dir, targetFile) |
1092 | 1089 |
|
... | ... |
@@ -1100,10 +1026,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { |
1100 | 1100 |
c.Fatal(err) |
1101 | 1101 |
} |
1102 | 1102 |
|
1103 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
1104 |
- c.Fatal(err) |
|
1105 |
- } |
|
1106 |
- |
|
1103 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1107 | 1104 |
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { |
1108 | 1105 |
c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) |
1109 | 1106 |
} |
... | ... |
@@ -1117,18 +1040,15 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { |
1117 | 1117 |
|
1118 | 1118 |
{ |
1119 | 1119 |
name := "testbuildinaccessiblefiles" |
1120 |
- ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"}) |
|
1121 |
- if err != nil { |
|
1122 |
- c.Fatal(err) |
|
1123 |
- } |
|
1120 |
+ ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"}) |
|
1124 | 1121 |
defer ctx.Close() |
1125 | 1122 |
// This is used to ensure we detect inaccessible files early during build in the cli client |
1126 | 1123 |
pathToFileWithoutReadAccess := filepath.Join(ctx.Dir, "fileWithoutReadAccess") |
1127 | 1124 |
|
1128 |
- if err = os.Chown(pathToFileWithoutReadAccess, 0, 0); err != nil { |
|
1125 |
+ if err := os.Chown(pathToFileWithoutReadAccess, 0, 0); err != nil { |
|
1129 | 1126 |
c.Fatalf("failed to chown file to root: %s", err) |
1130 | 1127 |
} |
1131 |
- if err = os.Chmod(pathToFileWithoutReadAccess, 0700); err != nil { |
|
1128 |
+ if err := os.Chmod(pathToFileWithoutReadAccess, 0700); err != nil { |
|
1132 | 1129 |
c.Fatalf("failed to chmod file to 700: %s", err) |
1133 | 1130 |
} |
1134 | 1131 |
result := icmd.RunCmd(icmd.Cmd{ |
... | ... |
@@ -1150,22 +1070,19 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { |
1150 | 1150 |
} |
1151 | 1151 |
{ |
1152 | 1152 |
name := "testbuildinaccessibledirectory" |
1153 |
- ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"}) |
|
1154 |
- if err != nil { |
|
1155 |
- c.Fatal(err) |
|
1156 |
- } |
|
1153 |
+ ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"}) |
|
1157 | 1154 |
defer ctx.Close() |
1158 | 1155 |
// This is used to ensure we detect inaccessible directories early during build in the cli client |
1159 | 1156 |
pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") |
1160 | 1157 |
pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") |
1161 | 1158 |
|
1162 |
- if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { |
|
1159 |
+ if err := os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { |
|
1163 | 1160 |
c.Fatalf("failed to chown directory to root: %s", err) |
1164 | 1161 |
} |
1165 |
- if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { |
|
1162 |
+ if err := os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { |
|
1166 | 1163 |
c.Fatalf("failed to chmod directory to 444: %s", err) |
1167 | 1164 |
} |
1168 |
- if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { |
|
1165 |
+ if err := os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { |
|
1169 | 1166 |
c.Fatalf("failed to chmod file to 700: %s", err) |
1170 | 1167 |
} |
1171 | 1168 |
|
... | ... |
@@ -1189,10 +1106,7 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { |
1189 | 1189 |
} |
1190 | 1190 |
{ |
1191 | 1191 |
name := "testlinksok" |
1192 |
- ctx, err := fakeContext("FROM scratch\nADD . /foo/", nil) |
|
1193 |
- if err != nil { |
|
1194 |
- c.Fatal(err) |
|
1195 |
- } |
|
1192 |
+ ctx := fakeContext(c, "FROM scratch\nADD . /foo/", nil) |
|
1196 | 1193 |
defer ctx.Close() |
1197 | 1194 |
|
1198 | 1195 |
target := "../../../../../../../../../../../../../../../../../../../azA" |
... | ... |
@@ -1202,31 +1116,26 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { |
1202 | 1202 |
defer os.Remove(target) |
1203 | 1203 |
// This is used to ensure we don't follow links when checking if everything in the context is accessible |
1204 | 1204 |
// This test doesn't require that we run commands as an unprivileged user |
1205 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
1206 |
- c.Fatal(err) |
|
1207 |
- } |
|
1205 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1208 | 1206 |
} |
1209 | 1207 |
{ |
1210 | 1208 |
name := "testbuildignoredinaccessible" |
1211 |
- ctx, err := fakeContext("FROM scratch\nADD . /foo/", |
|
1209 |
+ ctx := fakeContext(c, "FROM scratch\nADD . /foo/", |
|
1212 | 1210 |
map[string]string{ |
1213 | 1211 |
"directoryWeCantStat/bar": "foo", |
1214 | 1212 |
".dockerignore": "directoryWeCantStat", |
1215 | 1213 |
}) |
1216 |
- if err != nil { |
|
1217 |
- c.Fatal(err) |
|
1218 |
- } |
|
1219 | 1214 |
defer ctx.Close() |
1220 | 1215 |
// This is used to ensure we don't try to add inaccessible files when they are ignored by a .dockerignore pattern |
1221 | 1216 |
pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") |
1222 | 1217 |
pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") |
1223 |
- if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { |
|
1218 |
+ if err := os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { |
|
1224 | 1219 |
c.Fatalf("failed to chown directory to root: %s", err) |
1225 | 1220 |
} |
1226 |
- if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { |
|
1221 |
+ if err := os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { |
|
1227 | 1222 |
c.Fatalf("failed to chmod directory to 444: %s", err) |
1228 | 1223 |
} |
1229 |
- if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { |
|
1224 |
+ if err := os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { |
|
1230 | 1225 |
c.Fatalf("failed to chmod file to 700: %s", err) |
1231 | 1226 |
} |
1232 | 1227 |
|
... | ... |
@@ -1246,7 +1155,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) { |
1246 | 1246 |
} |
1247 | 1247 |
name := "testbuildforcerm" |
1248 | 1248 |
|
1249 |
- buildImageNew(name, withBuildFlags("--force-rm"), withBuildContext(c, |
|
1249 |
+ buildImage(name, withBuildFlags("--force-rm"), withBuildContext(c, |
|
1250 | 1250 |
withFile("Dockerfile", `FROM `+minimalBaseImage()+` |
1251 | 1251 |
RUN true |
1252 | 1252 |
RUN thiswillfail`))).Assert(c, icmd.Expected{ |
... | ... |
@@ -1542,7 +1451,7 @@ func (s *DockerSuite) TestBuildBlankName(c *check.C) { |
1542 | 1542 |
} |
1543 | 1543 |
|
1544 | 1544 |
for _, tc := range testCases { |
1545 |
- buildImageNew(name, withDockerfile(fmt.Sprintf(`FROM busybox |
|
1545 |
+ buildImage(name, withDockerfile(fmt.Sprintf(`FROM busybox |
|
1546 | 1546 |
%s`, tc.expression))).Assert(c, icmd.Expected{ |
1547 | 1547 |
ExitCode: 1, |
1548 | 1548 |
Err: tc.expectedStderr, |
... | ... |
@@ -1624,7 +1533,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) { |
1624 | 1624 |
c.Fatalf("failed to list contents of tmp dir: %s", err) |
1625 | 1625 |
} |
1626 | 1626 |
|
1627 |
- buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
1627 |
+ buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
1628 | 1628 |
RUN /non/existing/command`)).Assert(c, icmd.Expected{ |
1629 | 1629 |
ExitCode: 1, |
1630 | 1630 |
}) |
... | ... |
@@ -1802,11 +1711,11 @@ func (s *DockerSuite) TestBuildOnBuildLimitedInheritence(c *check.C) { |
1802 | 1802 |
ONBUILD RUN echo "ONBUILD PARENT" |
1803 | 1803 |
`)) |
1804 | 1804 |
// ONBUILD should be run in second build. |
1805 |
- buildImageNew("testonbuildtrigger2", withDockerfile("FROM testonbuildtrigger1")).Assert(c, icmd.Expected{ |
|
1805 |
+ buildImage("testonbuildtrigger2", withDockerfile("FROM testonbuildtrigger1")).Assert(c, icmd.Expected{ |
|
1806 | 1806 |
Out: "ONBUILD PARENT", |
1807 | 1807 |
}) |
1808 | 1808 |
// ONBUILD should *not* be run in third build. |
1809 |
- result := buildImageNew("testonbuildtrigger3", withDockerfile("FROM testonbuildtrigger2")) |
|
1809 |
+ result := buildImage("testonbuildtrigger3", withDockerfile("FROM testonbuildtrigger2")) |
|
1810 | 1810 |
result.Assert(c, icmd.Success) |
1811 | 1811 |
if strings.Contains(result.Combined(), "ONBUILD PARENT") { |
1812 | 1812 |
c.Fatalf("ONBUILD instruction ran in grandchild of ONBUILD parent") |
... | ... |
@@ -1821,14 +1730,11 @@ func (s *DockerSuite) TestBuildSameDockerfileWithAndWithoutCache(c *check.C) { |
1821 | 1821 |
EXPOSE 5432 |
1822 | 1822 |
ENTRYPOINT ["/bin/echo"]` |
1823 | 1823 |
buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
1824 |
- id1, err := getIDByName(name) |
|
1825 |
- c.Assert(err, checker.IsNil) |
|
1824 |
+ id1 := getIDByName(c, name) |
|
1826 | 1825 |
buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
1827 |
- id2, err := getIDByName(name) |
|
1828 |
- c.Assert(err, checker.IsNil) |
|
1826 |
+ id2 := getIDByName(c, name) |
|
1829 | 1827 |
buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
1830 |
- id3, err := getIDByName(name) |
|
1831 |
- c.Assert(err, checker.IsNil) |
|
1828 |
+ id3 := getIDByName(c, name) |
|
1832 | 1829 |
if id1 != id2 { |
1833 | 1830 |
c.Fatal("The cache should have been used but hasn't.") |
1834 | 1831 |
} |
... | ... |
@@ -1844,36 +1750,27 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) { |
1844 | 1844 |
dockerfile := ` |
1845 | 1845 |
FROM busybox |
1846 | 1846 |
ADD foo /tmp/` |
1847 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
1847 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
1848 | 1848 |
"foo": "hello", |
1849 | 1849 |
}) |
1850 |
- if err != nil { |
|
1851 |
- c.Fatal(err) |
|
1852 |
- } |
|
1853 | 1850 |
defer ctx.Close() |
1854 | 1851 |
|
1855 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
1856 |
- if err != nil { |
|
1857 |
- c.Fatalf("Error building #1: %s", err) |
|
1858 |
- } |
|
1852 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1853 |
+ id1 := getIDByName(c, name) |
|
1859 | 1854 |
|
1860 | 1855 |
if err := ctx.Add("foo", "bye"); err != nil { |
1861 | 1856 |
c.Fatalf("Error modifying foo: %s", err) |
1862 | 1857 |
} |
1863 | 1858 |
|
1864 | 1859 |
// Updating a file should invalidate the cache |
1865 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
1866 |
- if err != nil { |
|
1867 |
- c.Fatalf("Error building #2: %s", err) |
|
1868 |
- } |
|
1860 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1861 |
+ id2 := getIDByName(c, name) |
|
1869 | 1862 |
if id2 == id1 { |
1870 | 1863 |
c.Fatal("Should not have used the cache") |
1871 | 1864 |
} |
1872 | 1865 |
|
1873 |
- id3, err := buildImageFromContext(name, ctx, true) |
|
1874 |
- if err != nil { |
|
1875 |
- c.Fatalf("Error building #3: %s", err) |
|
1876 |
- } |
|
1866 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1867 |
+ id3 := getIDByName(c, name) |
|
1877 | 1868 |
if id3 != id2 { |
1878 | 1869 |
c.Fatal("Should have used the cache") |
1879 | 1870 |
} |
... | ... |
@@ -1887,25 +1784,16 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check. |
1887 | 1887 |
MAINTAINER dockerio |
1888 | 1888 |
ADD foo Dockerfile /usr/lib/bla/ |
1889 | 1889 |
RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"` |
1890 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
1890 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
1891 | 1891 |
"foo": "hello", |
1892 | 1892 |
}) |
1893 |
- if err != nil { |
|
1894 |
- c.Fatal(err) |
|
1895 |
- } |
|
1896 | 1893 |
defer ctx.Close() |
1897 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
1898 |
- if err != nil { |
|
1899 |
- c.Fatal(err) |
|
1900 |
- } |
|
1901 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
1902 |
- if err != nil { |
|
1903 |
- c.Fatal(err) |
|
1904 |
- } |
|
1905 |
- id3, err := buildImageFromContext(name, ctx, false) |
|
1906 |
- if err != nil { |
|
1907 |
- c.Fatal(err) |
|
1908 |
- } |
|
1894 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1895 |
+ id1 := getIDByName(c, name) |
|
1896 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1897 |
+ id2 := getIDByName(c, name) |
|
1898 |
+ buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) |
|
1899 |
+ id3 := getIDByName(c, name) |
|
1909 | 1900 |
if id1 != id2 { |
1910 | 1901 |
c.Fatal("The cache should have been used but hasn't.") |
1911 | 1902 |
} |
... | ... |
@@ -1921,25 +1809,18 @@ func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) { |
1921 | 1921 |
dockerfile := ` |
1922 | 1922 |
FROM ` + minimalBaseImage() + ` |
1923 | 1923 |
COPY dir /tmp/` |
1924 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
1924 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
1925 | 1925 |
"dir/foo": "hello", |
1926 | 1926 |
}) |
1927 |
- if err != nil { |
|
1928 |
- c.Fatal(err) |
|
1929 |
- } |
|
1930 | 1927 |
defer ctx.Close() |
1931 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
1932 |
- if err != nil { |
|
1933 |
- c.Fatal(err) |
|
1934 |
- } |
|
1928 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1929 |
+ id1 := getIDByName(c, name) |
|
1935 | 1930 |
// Check that adding file with similar name doesn't mess with cache |
1936 | 1931 |
if err := ctx.Add("dir_file", "hello2"); err != nil { |
1937 | 1932 |
c.Fatal(err) |
1938 | 1933 |
} |
1939 |
- id2, err := buildImageFromContext(name2, ctx, true) |
|
1940 |
- if err != nil { |
|
1941 |
- c.Fatal(err) |
|
1942 |
- } |
|
1934 |
+ buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
1935 |
+ id2 := getIDByName(c, name2) |
|
1943 | 1936 |
if id1 != id2 { |
1944 | 1937 |
c.Fatal("The cache should have been used but wasn't") |
1945 | 1938 |
} |
... | ... |
@@ -1954,25 +1835,18 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { |
1954 | 1954 |
FROM ` + minimalBaseImage() + ` |
1955 | 1955 |
MAINTAINER dockerio |
1956 | 1956 |
ADD . /usr/lib/bla` |
1957 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
1957 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
1958 | 1958 |
"foo": "hello", |
1959 | 1959 |
}) |
1960 |
- if err != nil { |
|
1961 |
- c.Fatal(err) |
|
1962 |
- } |
|
1963 | 1960 |
defer ctx.Close() |
1964 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
1965 |
- if err != nil { |
|
1966 |
- c.Fatal(err) |
|
1967 |
- } |
|
1961 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
1962 |
+ id1 := getIDByName(c, name) |
|
1968 | 1963 |
// Check that adding file invalidate cache of "ADD ." |
1969 | 1964 |
if err := ctx.Add("bar", "hello2"); err != nil { |
1970 | 1965 |
c.Fatal(err) |
1971 | 1966 |
} |
1972 |
- id2, err := buildImageFromContext(name2, ctx, true) |
|
1973 |
- if err != nil { |
|
1974 |
- c.Fatal(err) |
|
1975 |
- } |
|
1967 |
+ buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
1968 |
+ id2 := getIDByName(c, name2) |
|
1976 | 1969 |
if id1 == id2 { |
1977 | 1970 |
c.Fatal("The cache should have been invalided but hasn't.") |
1978 | 1971 |
} |
... | ... |
@@ -1980,10 +1854,8 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { |
1980 | 1980 |
if err := ctx.Add("foo", "hello1"); err != nil { |
1981 | 1981 |
c.Fatal(err) |
1982 | 1982 |
} |
1983 |
- id3, err := buildImageFromContext(name3, ctx, true) |
|
1984 |
- if err != nil { |
|
1985 |
- c.Fatal(err) |
|
1986 |
- } |
|
1983 |
+ buildImageSuccessfully(c, name3, withExternalBuildContext(ctx)) |
|
1984 |
+ id3 := getIDByName(c, name3) |
|
1987 | 1985 |
if id2 == id3 { |
1988 | 1986 |
c.Fatal("The cache should have been invalided but hasn't.") |
1989 | 1987 |
} |
... | ... |
@@ -1993,10 +1865,8 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { |
1993 | 1993 |
if err := ctx.Add("foo", "hello1"); err != nil { |
1994 | 1994 |
c.Fatal(err) |
1995 | 1995 |
} |
1996 |
- id4, err := buildImageFromContext(name4, ctx, true) |
|
1997 |
- if err != nil { |
|
1998 |
- c.Fatal(err) |
|
1999 |
- } |
|
1996 |
+ buildImageSuccessfully(c, name4, withExternalBuildContext(ctx)) |
|
1997 |
+ id4 := getIDByName(c, name4) |
|
2000 | 1998 |
if id3 != id4 { |
2001 | 1999 |
c.Fatal("The cache should have been used but hasn't.") |
2002 | 2000 |
} |
... | ... |
@@ -2009,21 +1879,14 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { |
2009 | 2009 |
FROM ` + minimalBaseImage() + ` |
2010 | 2010 |
MAINTAINER dockerio |
2011 | 2011 |
ADD . /usr/lib/bla` |
2012 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
2012 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
2013 | 2013 |
"foo": "hello", |
2014 | 2014 |
}) |
2015 |
- if err != nil { |
|
2016 |
- c.Fatal(err) |
|
2017 |
- } |
|
2018 | 2015 |
defer ctx.Close() |
2019 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
2020 |
- if err != nil { |
|
2021 |
- c.Fatal(err) |
|
2022 |
- } |
|
2023 |
- id2, err := buildImageFromContext(name, ctx, false) |
|
2024 |
- if err != nil { |
|
2025 |
- c.Fatal(err) |
|
2026 |
- } |
|
2016 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2017 |
+ id1 := getIDByName(c, name) |
|
2018 |
+ buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) |
|
2019 |
+ id2 := getIDByName(c, name) |
|
2027 | 2020 |
if id1 == id2 { |
2028 | 2021 |
c.Fatal("The cache should have been invalided but hasn't.") |
2029 | 2022 |
} |
... | ... |
@@ -2031,26 +1894,20 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { |
2031 | 2031 |
|
2032 | 2032 |
func (s *DockerSuite) TestBuildAddRemoteFileWithAndWithoutCache(c *check.C) { |
2033 | 2033 |
name := "testbuildaddremotefilewithcache" |
2034 |
- server, err := fakeStorage(map[string]string{ |
|
2034 |
+ server := fakeStorage(c, map[string]string{ |
|
2035 | 2035 |
"baz": "hello", |
2036 | 2036 |
}) |
2037 |
- if err != nil { |
|
2038 |
- c.Fatal(err) |
|
2039 |
- } |
|
2040 | 2037 |
defer server.Close() |
2041 | 2038 |
|
2042 | 2039 |
dockerfile := fmt.Sprintf(`FROM `+minimalBaseImage()+` |
2043 | 2040 |
MAINTAINER dockerio |
2044 | 2041 |
ADD %s/baz /usr/lib/baz/quux`, server.URL()) |
2045 | 2042 |
buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
2046 |
- id1, err := getIDByName(name) |
|
2047 |
- c.Assert(err, checker.IsNil) |
|
2043 |
+ id1 := getIDByName(c, name) |
|
2048 | 2044 |
buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
2049 |
- id2, err := getIDByName(name) |
|
2050 |
- c.Assert(err, checker.IsNil) |
|
2045 |
+ id2 := getIDByName(c, name) |
|
2051 | 2046 |
buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
2052 |
- id3, err := getIDByName(name) |
|
2053 |
- c.Assert(err, checker.IsNil) |
|
2047 |
+ id3 := getIDByName(c, name) |
|
2054 | 2048 |
|
2055 | 2049 |
if id1 != id2 { |
2056 | 2050 |
c.Fatal("The cache should have been used but hasn't.") |
... | ... |
@@ -2066,29 +1923,18 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { |
2066 | 2066 |
name3 := name + "3" |
2067 | 2067 |
|
2068 | 2068 |
files := map[string]string{"baz": "hello"} |
2069 |
- server, err := fakeStorage(files) |
|
2070 |
- if err != nil { |
|
2071 |
- c.Fatal(err) |
|
2072 |
- } |
|
2069 |
+ server := fakeStorage(c, files) |
|
2073 | 2070 |
defer server.Close() |
2074 | 2071 |
|
2075 |
- ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2072 |
+ ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2076 | 2073 |
MAINTAINER dockerio |
2077 | 2074 |
ADD %s/baz /usr/lib/baz/quux`, server.URL()), nil) |
2078 |
- if err != nil { |
|
2079 |
- c.Fatal(err) |
|
2080 |
- } |
|
2081 | 2075 |
defer ctx.Close() |
2082 | 2076 |
|
2083 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
2084 |
- if err != nil { |
|
2085 |
- c.Fatal(err) |
|
2086 |
- } |
|
2087 |
- |
|
2088 |
- id2, err := buildImageFromContext(name2, ctx, true) |
|
2089 |
- if err != nil { |
|
2090 |
- c.Fatal(err) |
|
2091 |
- } |
|
2077 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2078 |
+ id1 := getIDByName(c, name) |
|
2079 |
+ buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
2080 |
+ id2 := getIDByName(c, name2) |
|
2092 | 2081 |
if id1 != id2 { |
2093 | 2082 |
c.Fatal("The cache should have been used but wasn't - #1") |
2094 | 2083 |
} |
... | ... |
@@ -2099,23 +1945,15 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { |
2099 | 2099 |
// allow some time for clock to pass as mtime precision is only 1s |
2100 | 2100 |
time.Sleep(2 * time.Second) |
2101 | 2101 |
|
2102 |
- server2, err := fakeStorage(files) |
|
2103 |
- if err != nil { |
|
2104 |
- c.Fatal(err) |
|
2105 |
- } |
|
2102 |
+ server2 := fakeStorage(c, files) |
|
2106 | 2103 |
defer server2.Close() |
2107 | 2104 |
|
2108 |
- ctx2, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2105 |
+ ctx2 := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2109 | 2106 |
MAINTAINER dockerio |
2110 | 2107 |
ADD %s/baz /usr/lib/baz/quux`, server2.URL()), nil) |
2111 |
- if err != nil { |
|
2112 |
- c.Fatal(err) |
|
2113 |
- } |
|
2114 | 2108 |
defer ctx2.Close() |
2115 |
- id3, err := buildImageFromContext(name3, ctx2, true) |
|
2116 |
- if err != nil { |
|
2117 |
- c.Fatal(err) |
|
2118 |
- } |
|
2109 |
+ buildImageSuccessfully(c, name3, withExternalBuildContext(ctx2)) |
|
2110 |
+ id3 := getIDByName(c, name3) |
|
2119 | 2111 |
if id1 != id3 { |
2120 | 2112 |
c.Fatal("The cache should have been used but wasn't") |
2121 | 2113 |
} |
... | ... |
@@ -2124,37 +1962,25 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { |
2124 | 2124 |
// FIXME(vdemeester) this really seems to test the same thing as before (combined) |
2125 | 2125 |
func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *check.C) { |
2126 | 2126 |
name := "testbuildaddlocalandremotefilewithcache" |
2127 |
- server, err := fakeStorage(map[string]string{ |
|
2127 |
+ server := fakeStorage(c, map[string]string{ |
|
2128 | 2128 |
"baz": "hello", |
2129 | 2129 |
}) |
2130 |
- if err != nil { |
|
2131 |
- c.Fatal(err) |
|
2132 |
- } |
|
2133 | 2130 |
defer server.Close() |
2134 | 2131 |
|
2135 |
- ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2132 |
+ ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
2136 | 2133 |
MAINTAINER dockerio |
2137 | 2134 |
ADD foo /usr/lib/bla/bar |
2138 | 2135 |
ADD %s/baz /usr/lib/baz/quux`, server.URL()), |
2139 | 2136 |
map[string]string{ |
2140 | 2137 |
"foo": "hello world", |
2141 | 2138 |
}) |
2142 |
- if err != nil { |
|
2143 |
- c.Fatal(err) |
|
2144 |
- } |
|
2145 | 2139 |
defer ctx.Close() |
2146 |
- id1, err := buildImageFromContext(name, ctx, true) |
|
2147 |
- if err != nil { |
|
2148 |
- c.Fatal(err) |
|
2149 |
- } |
|
2150 |
- id2, err := buildImageFromContext(name, ctx, true) |
|
2151 |
- if err != nil { |
|
2152 |
- c.Fatal(err) |
|
2153 |
- } |
|
2154 |
- id3, err := buildImageFromContext(name, ctx, false) |
|
2155 |
- if err != nil { |
|
2156 |
- c.Fatal(err) |
|
2157 |
- } |
|
2140 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2141 |
+ id1 := getIDByName(c, name) |
|
2142 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2143 |
+ id2 := getIDByName(c, name) |
|
2144 |
+ buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(ctx)) |
|
2145 |
+ id3 := getIDByName(c, name) |
|
2158 | 2146 |
if id1 != id2 { |
2159 | 2147 |
c.Fatal("The cache should have been used but hasn't.") |
2160 | 2148 |
} |
... | ... |
@@ -2164,7 +1990,7 @@ func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *chec |
2164 | 2164 |
} |
2165 | 2165 |
|
2166 | 2166 |
func testContextTar(c *check.C, compression archive.Compression) { |
2167 |
- ctx, err := fakeContext( |
|
2167 |
+ ctx := fakeContext(c, |
|
2168 | 2168 |
`FROM busybox |
2169 | 2169 |
ADD foo /foo |
2170 | 2170 |
CMD ["cat", "/foo"]`, |
... | ... |
@@ -2172,9 +1998,6 @@ CMD ["cat", "/foo"]`, |
2172 | 2172 |
"foo": "bar", |
2173 | 2173 |
}, |
2174 | 2174 |
) |
2175 |
- if err != nil { |
|
2176 |
- c.Fatal(err) |
|
2177 |
- } |
|
2178 | 2175 |
defer ctx.Close() |
2179 | 2176 |
context, err := archive.Tar(ctx.Dir, compression) |
2180 | 2177 |
if err != nil { |
... | ... |
@@ -2257,7 +2080,7 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) { |
2257 | 2257 |
expected = "foo: The system cannot find the file specified" |
2258 | 2258 |
} |
2259 | 2259 |
|
2260 |
- buildImageNew(name, withBuildContext(c, |
|
2260 |
+ buildImage(name, withBuildContext(c, |
|
2261 | 2261 |
withFile("Dockerfile", `FROM `+minimalBaseImage()+` |
2262 | 2262 |
ADD foo /usr/local/bar`), |
2263 | 2263 |
withFile("bar", "hello"))).Assert(c, icmd.Expected{ |
... | ... |
@@ -2289,7 +2112,7 @@ func (s *DockerSuite) TestBuildInheritance(c *check.C) { |
2289 | 2289 |
|
2290 | 2290 |
func (s *DockerSuite) TestBuildFails(c *check.C) { |
2291 | 2291 |
name := "testbuildfails" |
2292 |
- buildImageNew(name, withDockerfile(`FROM busybox |
|
2292 |
+ buildImage(name, withDockerfile(`FROM busybox |
|
2293 | 2293 |
RUN sh -c "exit 23"`)).Assert(c, icmd.Expected{ |
2294 | 2294 |
ExitCode: 23, |
2295 | 2295 |
Err: "returned a non-zero code: 23", |
... | ... |
@@ -2504,51 +2327,41 @@ func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) { |
2504 | 2504 |
} |
2505 | 2505 |
|
2506 | 2506 |
func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) { |
2507 |
- var id1 string |
|
2508 |
- var id2 string |
|
2509 |
- |
|
2510 | 2507 |
name := "testbuilddockerignoretouchdockerfile" |
2511 | 2508 |
dockerfile := ` |
2512 | 2509 |
FROM busybox |
2513 | 2510 |
ADD . /tmp/` |
2514 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
2511 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
2515 | 2512 |
"Dockerfile": dockerfile, |
2516 | 2513 |
".dockerignore": "Dockerfile\n", |
2517 | 2514 |
}) |
2518 |
- if err != nil { |
|
2519 |
- c.Fatal(err) |
|
2520 |
- } |
|
2521 | 2515 |
defer ctx.Close() |
2522 | 2516 |
|
2523 |
- if id1, err = buildImageFromContext(name, ctx, true); err != nil { |
|
2524 |
- c.Fatalf("Didn't build it correctly:%s", err) |
|
2525 |
- } |
|
2517 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2518 |
+ id1 := getIDByName(c, name) |
|
2526 | 2519 |
|
2527 |
- if id2, err = buildImageFromContext(name, ctx, true); err != nil { |
|
2528 |
- c.Fatalf("Didn't build it correctly:%s", err) |
|
2529 |
- } |
|
2520 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2521 |
+ id2 := getIDByName(c, name) |
|
2530 | 2522 |
if id1 != id2 { |
2531 | 2523 |
c.Fatalf("Didn't use the cache - 1") |
2532 | 2524 |
} |
2533 | 2525 |
|
2534 | 2526 |
// Now make sure touching Dockerfile doesn't invalidate the cache |
2535 |
- if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { |
|
2527 |
+ if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { |
|
2536 | 2528 |
c.Fatalf("Didn't add Dockerfile: %s", err) |
2537 | 2529 |
} |
2538 |
- if id2, err = buildImageFromContext(name, ctx, true); err != nil { |
|
2539 |
- c.Fatalf("Didn't build it correctly:%s", err) |
|
2540 |
- } |
|
2530 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2531 |
+ id2 = getIDByName(c, name) |
|
2541 | 2532 |
if id1 != id2 { |
2542 | 2533 |
c.Fatalf("Didn't use the cache - 2") |
2543 | 2534 |
} |
2544 | 2535 |
|
2545 | 2536 |
// One more time but just 'touch' it instead of changing the content |
2546 |
- if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { |
|
2537 |
+ if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { |
|
2547 | 2538 |
c.Fatalf("Didn't add Dockerfile: %s", err) |
2548 | 2539 |
} |
2549 |
- if id2, err = buildImageFromContext(name, ctx, true); err != nil { |
|
2550 |
- c.Fatalf("Didn't build it correctly:%s", err) |
|
2551 |
- } |
|
2540 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2541 |
+ id2 = getIDByName(c, name) |
|
2552 | 2542 |
if id1 != id2 { |
2553 | 2543 |
c.Fatalf("Didn't use the cache - 3") |
2554 | 2544 |
} |
... | ... |
@@ -2590,7 +2403,7 @@ func (s *DockerSuite) TestBuildDockerignoringOnlyDotfiles(c *check.C) { |
2590 | 2590 |
|
2591 | 2591 |
func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) { |
2592 | 2592 |
name := "testbuilddockerignorebadexclusion" |
2593 |
- buildImageNew(name, withBuildContext(c, |
|
2593 |
+ buildImage(name, withBuildContext(c, |
|
2594 | 2594 |
withFile("Dockerfile", ` |
2595 | 2595 |
FROM busybox |
2596 | 2596 |
COPY . / |
... | ... |
@@ -2949,10 +2762,7 @@ RUN cat /existing-directory-trailing-slash/test/foo | grep Hi` |
2949 | 2949 |
}() |
2950 | 2950 |
defer ctx.Close() |
2951 | 2951 |
|
2952 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
2953 |
- c.Fatalf("build failed to complete for TestBuildAddTar: %v", err) |
|
2954 |
- } |
|
2955 |
- |
|
2952 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
2956 | 2953 |
} |
2957 | 2954 |
|
2958 | 2955 |
func (s *DockerSuite) TestBuildAddBrokenTar(c *check.C) { |
... | ... |
@@ -3001,9 +2811,9 @@ ADD test.tar /` |
3001 | 3001 |
}() |
3002 | 3002 |
defer ctx.Close() |
3003 | 3003 |
|
3004 |
- if _, err := buildImageFromContext(name, ctx, true); err == nil { |
|
3005 |
- c.Fatalf("build should have failed for TestBuildAddBrokenTar") |
|
3006 |
- } |
|
3004 |
+ buildImage(name, withExternalBuildContext(ctx)).Assert(c, icmd.Expected{ |
|
3005 |
+ ExitCode: 1, |
|
3006 |
+ }) |
|
3007 | 3007 |
} |
3008 | 3008 |
|
3009 | 3009 |
func (s *DockerSuite) TestBuildAddNonTar(c *check.C) { |
... | ... |
@@ -3068,10 +2878,7 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) { |
3068 | 3068 |
|
3069 | 3069 |
defer ctx.Close() |
3070 | 3070 |
|
3071 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
3072 |
- c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) |
|
3073 |
- } |
|
3074 |
- |
|
3071 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
3075 | 3072 |
} |
3076 | 3073 |
|
3077 | 3074 |
func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { |
... | ... |
@@ -3128,24 +2935,18 @@ func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { |
3128 | 3128 |
|
3129 | 3129 |
defer ctx.Close() |
3130 | 3130 |
|
3131 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
3132 |
- c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) |
|
3133 |
- } |
|
3134 |
- |
|
3131 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
3135 | 3132 |
} |
3136 | 3133 |
|
3137 | 3134 |
func (s *DockerSuite) TestBuildFromGit(c *check.C) { |
3138 | 3135 |
name := "testbuildfromgit" |
3139 |
- git, err := newFakeGit("repo", map[string]string{ |
|
3136 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
3140 | 3137 |
"Dockerfile": `FROM busybox |
3141 | 3138 |
ADD first /first |
3142 | 3139 |
RUN [ -f /first ] |
3143 | 3140 |
MAINTAINER docker`, |
3144 | 3141 |
"first": "test git data", |
3145 | 3142 |
}, true) |
3146 |
- if err != nil { |
|
3147 |
- c.Fatal(err) |
|
3148 |
- } |
|
3149 | 3143 |
defer git.Close() |
3150 | 3144 |
|
3151 | 3145 |
buildImageSuccessfully(c, name, withBuildContextPath(git.RepoURL)) |
... | ... |
@@ -3158,16 +2959,13 @@ func (s *DockerSuite) TestBuildFromGit(c *check.C) { |
3158 | 3158 |
|
3159 | 3159 |
func (s *DockerSuite) TestBuildFromGitWithContext(c *check.C) { |
3160 | 3160 |
name := "testbuildfromgit" |
3161 |
- git, err := newFakeGit("repo", map[string]string{ |
|
3161 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
3162 | 3162 |
"docker/Dockerfile": `FROM busybox |
3163 | 3163 |
ADD first /first |
3164 | 3164 |
RUN [ -f /first ] |
3165 | 3165 |
MAINTAINER docker`, |
3166 | 3166 |
"docker/first": "test git data", |
3167 | 3167 |
}, true) |
3168 |
- if err != nil { |
|
3169 |
- c.Fatal(err) |
|
3170 |
- } |
|
3171 | 3168 |
defer git.Close() |
3172 | 3169 |
|
3173 | 3170 |
buildImageSuccessfully(c, name, withBuildContextPath(fmt.Sprintf("%s#master:docker", git.RepoURL))) |
... | ... |
@@ -3180,16 +2978,13 @@ func (s *DockerSuite) TestBuildFromGitWithContext(c *check.C) { |
3180 | 3180 |
|
3181 | 3181 |
func (s *DockerSuite) TestBuildFromGitwithF(c *check.C) { |
3182 | 3182 |
name := "testbuildfromgitwithf" |
3183 |
- git, err := newFakeGit("repo", map[string]string{ |
|
3183 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
3184 | 3184 |
"myApp/myDockerfile": `FROM busybox |
3185 | 3185 |
RUN echo hi from Dockerfile`, |
3186 | 3186 |
}, true) |
3187 |
- if err != nil { |
|
3188 |
- c.Fatal(err) |
|
3189 |
- } |
|
3190 | 3187 |
defer git.Close() |
3191 | 3188 |
|
3192 |
- buildImageNew(name, withBuildFlags("-f", "myApp/myDockerfile"), withBuildContextPath(git.RepoURL)).Assert(c, icmd.Expected{ |
|
3189 |
+ buildImage(name, withBuildFlags("-f", "myApp/myDockerfile"), withBuildContextPath(git.RepoURL)).Assert(c, icmd.Expected{ |
|
3193 | 3190 |
Out: "hi from Dockerfile", |
3194 | 3191 |
}) |
3195 | 3192 |
} |
... | ... |
@@ -3216,11 +3011,9 @@ func (s *DockerSuite) TestBuildFromRemoteTarball(c *check.C) { |
3216 | 3216 |
c.Fatalf("failed to close tar archive: %v", err) |
3217 | 3217 |
} |
3218 | 3218 |
|
3219 |
- server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ |
|
3219 |
+ server := fakeBinaryStorage(c, map[string]*bytes.Buffer{ |
|
3220 | 3220 |
"testT.tar": buffer, |
3221 | 3221 |
}) |
3222 |
- c.Assert(err, check.IsNil) |
|
3223 |
- |
|
3224 | 3222 |
defer server.Close() |
3225 | 3223 |
|
3226 | 3224 |
buildImageSuccessfully(c, name, withBuildContextPath(server.URL()+"/testT.tar")) |
... | ... |
@@ -3279,7 +3072,7 @@ func (s *DockerSuite) TestBuildOnBuildOutput(c *check.C) { |
3279 | 3279 |
name := "testbuildonbuildparent" |
3280 | 3280 |
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nONBUILD RUN echo foo\n")) |
3281 | 3281 |
|
3282 |
- buildImageNew(name, withDockerfile("FROM "+name+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ |
|
3282 |
+ buildImage(name, withDockerfile("FROM "+name+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ |
|
3283 | 3283 |
Out: "# Executing 1 build trigger", |
3284 | 3284 |
}) |
3285 | 3285 |
} |
... | ... |
@@ -3287,7 +3080,7 @@ func (s *DockerSuite) TestBuildOnBuildOutput(c *check.C) { |
3287 | 3287 |
// FIXME(vdemeester) should be a unit test |
3288 | 3288 |
func (s *DockerSuite) TestBuildInvalidTag(c *check.C) { |
3289 | 3289 |
name := "abcd:" + stringutils.GenerateRandomAlphaOnlyString(200) |
3290 |
- buildImageNew(name, withDockerfile("FROM "+minimalBaseImage()+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ |
|
3290 |
+ buildImage(name, withDockerfile("FROM "+minimalBaseImage()+"\nMAINTAINER quux\n")).Assert(c, icmd.Expected{ |
|
3291 | 3291 |
ExitCode: 125, |
3292 | 3292 |
Err: "Error parsing reference", |
3293 | 3293 |
}) |
... | ... |
@@ -3315,10 +3108,9 @@ func (s *DockerSuite) TestBuildCmdSpaces(c *check.C) { |
3315 | 3315 |
name := "testbuildcmdspaces" |
3316 | 3316 |
|
3317 | 3317 |
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nCMD [\"echo hi\"]\n")) |
3318 |
- id1, err := getIDByName(name) |
|
3319 |
- c.Assert(err, checker.IsNil) |
|
3318 |
+ id1 := getIDByName(c, name) |
|
3320 | 3319 |
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nCMD [\"echo\", \"hi\"]\n")) |
3321 |
- id2, err := getIDByName(name) |
|
3320 |
+ id2 := getIDByName(c, name) |
|
3322 | 3321 |
|
3323 | 3322 |
if id1 == id2 { |
3324 | 3323 |
c.Fatal("Should not have resulted in the same CMD") |
... | ... |
@@ -3326,10 +3118,9 @@ func (s *DockerSuite) TestBuildCmdSpaces(c *check.C) { |
3326 | 3326 |
|
3327 | 3327 |
// Now do the same with ENTRYPOINT |
3328 | 3328 |
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENTRYPOINT [\"echo hi\"]\n")) |
3329 |
- id1, err = getIDByName(name) |
|
3330 |
- c.Assert(err, checker.IsNil) |
|
3329 |
+ id1 = getIDByName(c, name) |
|
3331 | 3330 |
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENTRYPOINT [\"echo\", \"hi\"]\n")) |
3332 |
- id2, err = getIDByName(name) |
|
3331 |
+ id2 = getIDByName(c, name) |
|
3333 | 3332 |
|
3334 | 3333 |
if id1 == id2 { |
3335 | 3334 |
c.Fatal("Should not have resulted in the same ENTRYPOINT") |
... | ... |
@@ -3451,7 +3242,7 @@ func (s *DockerSuite) TestBuildVerboseOut(c *check.C) { |
3451 | 3451 |
expected = "\n123\r\n" |
3452 | 3452 |
} |
3453 | 3453 |
|
3454 |
- buildImageNew(name, withDockerfile(`FROM busybox |
|
3454 |
+ buildImage(name, withDockerfile(`FROM busybox |
|
3455 | 3455 |
RUN echo 123`)).Assert(c, icmd.Expected{ |
3456 | 3456 |
Out: expected, |
3457 | 3457 |
}) |
... | ... |
@@ -3489,44 +3280,37 @@ func (s *DockerSuite) TestBuildLabelsCache(c *check.C) { |
3489 | 3489 |
|
3490 | 3490 |
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
3491 | 3491 |
LABEL Vendor=Acme`)) |
3492 |
- id1, err := getIDByName(name) |
|
3493 |
- c.Assert(err, checker.IsNil) |
|
3492 |
+ id1 := getIDByName(c, name) |
|
3494 | 3493 |
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
3495 | 3494 |
LABEL Vendor=Acme`)) |
3496 |
- id2, err := getIDByName(name) |
|
3497 |
- c.Assert(err, checker.IsNil) |
|
3495 |
+ id2 := getIDByName(c, name) |
|
3498 | 3496 |
if id1 != id2 { |
3499 |
- c.Fatalf("Build 2 should have worked & used cache(%s,%s): %v", id1, id2, err) |
|
3497 |
+ c.Fatalf("Build 2 should have worked & used cache(%s,%s)", id1, id2) |
|
3500 | 3498 |
} |
3501 | 3499 |
|
3502 | 3500 |
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
3503 | 3501 |
LABEL Vendor=Acme1`)) |
3504 |
- id2, err = getIDByName(name) |
|
3505 |
- c.Assert(err, checker.IsNil) |
|
3502 |
+ id2 = getIDByName(c, name) |
|
3506 | 3503 |
if id1 == id2 { |
3507 |
- c.Fatalf("Build 3 should have worked & NOT used cache(%s,%s): %v", id1, id2, err) |
|
3504 |
+ c.Fatalf("Build 3 should have worked & NOT used cache(%s,%s)", id1, id2) |
|
3508 | 3505 |
} |
3509 | 3506 |
|
3510 | 3507 |
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
3511 | 3508 |
LABEL Vendor Acme`)) |
3512 |
- id2, err = getIDByName(name) |
|
3513 |
- c.Assert(err, checker.IsNil) |
|
3509 |
+ id2 = getIDByName(c, name) |
|
3514 | 3510 |
if id1 != id2 { |
3515 |
- c.Fatalf("Build 4 should have worked & used cache(%s,%s): %v", id1, id2, err) |
|
3511 |
+ c.Fatalf("Build 4 should have worked & used cache(%s,%s)", id1, id2) |
|
3516 | 3512 |
} |
3517 | 3513 |
|
3518 | 3514 |
// Now make sure the cache isn't used by mistake |
3519 | 3515 |
buildImageSuccessfully(c, name, withoutCache, withDockerfile(`FROM busybox |
3520 | 3516 |
LABEL f1=b1 f2=b2`)) |
3521 |
- _, err = getIDByName(name) |
|
3522 |
- c.Assert(err, checker.IsNil) |
|
3523 | 3517 |
|
3524 | 3518 |
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
3525 | 3519 |
LABEL f1=b1 f2=b2`)) |
3526 |
- id2, err = getIDByName(name) |
|
3527 |
- c.Assert(err, checker.IsNil) |
|
3520 |
+ id2 = getIDByName(c, name) |
|
3528 | 3521 |
if id1 == id2 { |
3529 |
- c.Fatalf("Build 6 should have worked & NOT used the cache(%s,%s): %q", id1, id2, err) |
|
3522 |
+ c.Fatalf("Build 6 should have worked & NOT used the cache(%s,%s)", id1, id2) |
|
3530 | 3523 |
} |
3531 | 3524 |
|
3532 | 3525 |
} |
... | ... |
@@ -3544,13 +3328,13 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) { |
3544 | 3544 |
{ |
3545 | 3545 |
Name: "quiet_build_stdin_success", |
3546 | 3546 |
BuildFunc: func(name string) *icmd.Result { |
3547 |
- return buildImageNew(name, buildFlags, withDockerfile("FROM busybox")) |
|
3547 |
+ return buildImage(name, buildFlags, withDockerfile("FROM busybox")) |
|
3548 | 3548 |
}, |
3549 | 3549 |
}, |
3550 | 3550 |
{ |
3551 | 3551 |
Name: "quiet_build_ctx_success", |
3552 | 3552 |
BuildFunc: func(name string) *icmd.Result { |
3553 |
- return buildImageNew(name, buildFlags, withBuildContext(c, |
|
3553 |
+ return buildImage(name, buildFlags, withBuildContext(c, |
|
3554 | 3554 |
withFile("Dockerfile", "FROM busybox"), |
3555 | 3555 |
withFile("quiet_build_success_fctx", "test"), |
3556 | 3556 |
)) |
... | ... |
@@ -3559,11 +3343,10 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) { |
3559 | 3559 |
{ |
3560 | 3560 |
Name: "quiet_build_git_success", |
3561 | 3561 |
BuildFunc: func(name string) *icmd.Result { |
3562 |
- git, err := newFakeGit("repo", map[string]string{ |
|
3562 |
+ git := newFakeGit(c, "repo", map[string]string{ |
|
3563 | 3563 |
"Dockerfile": "FROM busybox", |
3564 | 3564 |
}, true) |
3565 |
- c.Assert(err, checker.IsNil) |
|
3566 |
- return buildImageNew(name, buildFlags, withBuildContextPath(git.RepoURL)) |
|
3565 |
+ return buildImage(name, buildFlags, withBuildContextPath(git.RepoURL)) |
|
3567 | 3566 |
}, |
3568 | 3567 |
}, |
3569 | 3568 |
} |
... | ... |
@@ -3589,11 +3372,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailureWithNonExistImage(c *check.C) { |
3589 | 3589 |
testRequires(c, Network) |
3590 | 3590 |
testName := "quiet_build_not_exists_image" |
3591 | 3591 |
dockerfile := "FROM busybox11" |
3592 |
- quietResult := buildImageNew(testName, withBuildFlags("-q"), withDockerfile(dockerfile)) |
|
3592 |
+ quietResult := buildImage(testName, withBuildFlags("-q"), withDockerfile(dockerfile)) |
|
3593 | 3593 |
quietResult.Assert(c, icmd.Expected{ |
3594 | 3594 |
ExitCode: 1, |
3595 | 3595 |
}) |
3596 |
- result := buildImageNew(testName, withDockerfile(dockerfile)) |
|
3596 |
+ result := buildImage(testName, withDockerfile(dockerfile)) |
|
3597 | 3597 |
result.Assert(c, icmd.Expected{ |
3598 | 3598 |
ExitCode: 1, |
3599 | 3599 |
}) |
... | ... |
@@ -3615,11 +3398,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailure(c *check.C) { |
3615 | 3615 |
} |
3616 | 3616 |
|
3617 | 3617 |
for _, tc := range testCases { |
3618 |
- quietResult := buildImageNew(tc.testName, withBuildFlags("-q"), withDockerfile(tc.dockerfile)) |
|
3618 |
+ quietResult := buildImage(tc.testName, withBuildFlags("-q"), withDockerfile(tc.dockerfile)) |
|
3619 | 3619 |
quietResult.Assert(c, icmd.Expected{ |
3620 | 3620 |
ExitCode: 1, |
3621 | 3621 |
}) |
3622 |
- result := buildImageNew(tc.testName, withDockerfile(tc.dockerfile)) |
|
3622 |
+ result := buildImage(tc.testName, withDockerfile(tc.dockerfile)) |
|
3623 | 3623 |
result.Assert(c, icmd.Expected{ |
3624 | 3624 |
ExitCode: 1, |
3625 | 3625 |
}) |
... | ... |
@@ -3635,11 +3418,11 @@ func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) { |
3635 | 3635 |
// TODO(vdemeester) with cobra, stdout has a carriage return too much so this test should not check stdout |
3636 | 3636 |
URL := "http://something.invalid" |
3637 | 3637 |
name := "quiet_build_wrong_remote" |
3638 |
- quietResult := buildImageNew(name, withBuildFlags("-q"), withBuildContextPath(URL)) |
|
3638 |
+ quietResult := buildImage(name, withBuildFlags("-q"), withBuildContextPath(URL)) |
|
3639 | 3639 |
quietResult.Assert(c, icmd.Expected{ |
3640 | 3640 |
ExitCode: 1, |
3641 | 3641 |
}) |
3642 |
- result := buildImageNew(name, withBuildContextPath(URL)) |
|
3642 |
+ result := buildImage(name, withBuildContextPath(URL)) |
|
3643 | 3643 |
result.Assert(c, icmd.Expected{ |
3644 | 3644 |
ExitCode: 1, |
3645 | 3645 |
}) |
... | ... |
@@ -3652,7 +3435,7 @@ func (s *DockerSuite) TestBuildStderr(c *check.C) { |
3652 | 3652 |
// This test just makes sure that no non-error output goes |
3653 | 3653 |
// to stderr |
3654 | 3654 |
name := "testbuildstderr" |
3655 |
- result := buildImageNew(name, withDockerfile("FROM busybox\nRUN echo one")) |
|
3655 |
+ result := buildImage(name, withDockerfile("FROM busybox\nRUN echo one")) |
|
3656 | 3656 |
result.Assert(c, icmd.Success) |
3657 | 3657 |
|
3658 | 3658 |
// Windows to non-Windows should have a security warning |
... | ... |
@@ -3671,7 +3454,7 @@ func (s *DockerSuite) TestBuildChownSingleFile(c *check.C) { |
3671 | 3671 |
|
3672 | 3672 |
name := "testbuildchownsinglefile" |
3673 | 3673 |
|
3674 |
- ctx, err := fakeContext(` |
|
3674 |
+ ctx := fakeContext(c, ` |
|
3675 | 3675 |
FROM busybox |
3676 | 3676 |
COPY test / |
3677 | 3677 |
RUN ls -l /test |
... | ... |
@@ -3679,19 +3462,13 @@ RUN [ $(ls -l /test | awk '{print $3":"$4}') = 'root:root' ] |
3679 | 3679 |
`, map[string]string{ |
3680 | 3680 |
"test": "test", |
3681 | 3681 |
}) |
3682 |
- if err != nil { |
|
3683 |
- c.Fatal(err) |
|
3684 |
- } |
|
3685 | 3682 |
defer ctx.Close() |
3686 | 3683 |
|
3687 | 3684 |
if err := os.Chown(filepath.Join(ctx.Dir, "test"), 4242, 4242); err != nil { |
3688 | 3685 |
c.Fatal(err) |
3689 | 3686 |
} |
3690 | 3687 |
|
3691 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
3692 |
- c.Fatal(err) |
|
3693 |
- } |
|
3694 |
- |
|
3688 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
3695 | 3689 |
} |
3696 | 3690 |
|
3697 | 3691 |
func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) { |
... | ... |
@@ -3735,9 +3512,8 @@ func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) { |
3735 | 3735 |
}) |
3736 | 3736 |
w.Close() |
3737 | 3737 |
f.Close() |
3738 |
- if _, err := buildImageFromContext(name, fakeContextFromDir(ctx), false); err != nil { |
|
3739 |
- c.Fatal(err) |
|
3740 |
- } |
|
3738 |
+ |
|
3739 |
+ buildImageSuccessfully(c, name, withoutCache, withExternalBuildContext(fakeContextFromDir(ctx))) |
|
3741 | 3740 |
if _, err := os.Lstat(filepath.Join(tmpdir, "inject")); err == nil { |
3742 | 3741 |
c.Fatal("symlink breakout - inject") |
3743 | 3742 |
} else if !os.IsNotExist(err) { |
... | ... |
@@ -3797,7 +3573,7 @@ CMD cat /foo/file`), |
3797 | 3797 |
|
3798 | 3798 |
//Â FIXME(vdemeester) part of this should be unit test, other part should be clearer |
3799 | 3799 |
func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) { |
3800 |
- ctx, err := fakeContext(`FROM busybox |
|
3800 |
+ ctx := fakeContext(c, `FROM busybox |
|
3801 | 3801 |
RUN echo from Dockerfile`, |
3802 | 3802 |
map[string]string{ |
3803 | 3803 |
"Dockerfile": "FROM busybox\nRUN echo from Dockerfile", |
... | ... |
@@ -3806,9 +3582,6 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) { |
3806 | 3806 |
"dFile": "FROM busybox\nRUN echo from dFile", |
3807 | 3807 |
"files/dFile2": "FROM busybox\nRUN echo from files/dFile2", |
3808 | 3808 |
}) |
3809 |
- if err != nil { |
|
3810 |
- c.Fatal(err) |
|
3811 |
- } |
|
3812 | 3809 |
defer ctx.Close() |
3813 | 3810 |
|
3814 | 3811 |
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") |
... | ... |
@@ -3904,7 +3677,7 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { |
3904 | 3904 |
testRequires(c, DaemonIsLinux) |
3905 | 3905 |
|
3906 | 3906 |
// If Dockerfile is not present, use dockerfile |
3907 |
- buildImageNew("test1", withBuildContext(c, |
|
3907 |
+ buildImage("test1", withBuildContext(c, |
|
3908 | 3908 |
withFile("dockerfile", `FROM busybox |
3909 | 3909 |
RUN echo from dockerfile`), |
3910 | 3910 |
)).Assert(c, icmd.Expected{ |
... | ... |
@@ -3912,7 +3685,7 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { |
3912 | 3912 |
}) |
3913 | 3913 |
|
3914 | 3914 |
// Prefer Dockerfile in place of dockerfile |
3915 |
- buildImageNew("test1", withBuildContext(c, |
|
3915 |
+ buildImage("test1", withBuildContext(c, |
|
3916 | 3916 |
withFile("dockerfile", `FROM busybox |
3917 | 3917 |
RUN echo from dockerfile`), |
3918 | 3918 |
withFile("Dockerfile", `FROM busybox |
... | ... |
@@ -3923,26 +3696,20 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { |
3923 | 3923 |
} |
3924 | 3924 |
|
3925 | 3925 |
func (s *DockerSuite) TestBuildFromURLWithF(c *check.C) { |
3926 |
- server, err := fakeStorage(map[string]string{"baz": `FROM busybox |
|
3926 |
+ server := fakeStorage(c, map[string]string{"baz": `FROM busybox |
|
3927 | 3927 |
RUN echo from baz |
3928 | 3928 |
COPY * /tmp/ |
3929 | 3929 |
RUN find /tmp/`}) |
3930 |
- if err != nil { |
|
3931 |
- c.Fatal(err) |
|
3932 |
- } |
|
3933 | 3930 |
defer server.Close() |
3934 | 3931 |
|
3935 |
- ctx, err := fakeContext(`FROM busybox |
|
3932 |
+ ctx := fakeContext(c, `FROM busybox |
|
3936 | 3933 |
RUN echo from Dockerfile`, |
3937 | 3934 |
map[string]string{}) |
3938 |
- if err != nil { |
|
3939 |
- c.Fatal(err) |
|
3940 |
- } |
|
3941 | 3935 |
defer ctx.Close() |
3942 | 3936 |
|
3943 | 3937 |
// Make sure that -f is ignored and that we don't use the Dockerfile |
3944 | 3938 |
// that's in the current dir |
3945 |
- result := buildImageNew("test1", withBuildFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() { |
|
3939 |
+ result := buildImage("test1", withBuildFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() { |
|
3946 | 3940 |
cmd.Dir = ctx.Dir |
3947 | 3941 |
return nil |
3948 | 3942 |
}) |
... | ... |
@@ -3958,17 +3725,14 @@ RUN echo from Dockerfile`, |
3958 | 3958 |
|
3959 | 3959 |
func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) { |
3960 | 3960 |
testRequires(c, DaemonIsLinux) // TODO Windows: This test is flaky; no idea why |
3961 |
- ctx, err := fakeContext(`FROM busybox |
|
3961 |
+ ctx := fakeContext(c, `FROM busybox |
|
3962 | 3962 |
RUN echo "from Dockerfile"`, |
3963 | 3963 |
map[string]string{}) |
3964 |
- if err != nil { |
|
3965 |
- c.Fatal(err) |
|
3966 |
- } |
|
3967 | 3964 |
defer ctx.Close() |
3968 | 3965 |
|
3969 | 3966 |
// Make sure that -f is ignored and that we don't use the Dockerfile |
3970 | 3967 |
// that's in the current dir |
3971 |
- result := buildImageNew("test1", withBuildFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() { |
|
3968 |
+ result := buildImage("test1", withBuildFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() { |
|
3972 | 3969 |
cmd.Dir = ctx.Dir |
3973 | 3970 |
cmd.Stdin = strings.NewReader(`FROM busybox |
3974 | 3971 |
RUN echo "from baz" |
... | ... |
@@ -4062,69 +3826,65 @@ func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) { |
4062 | 4062 |
func (s *DockerSuite) TestBuildSpaces(c *check.C) { |
4063 | 4063 |
// Test to make sure that leading/trailing spaces on a command |
4064 | 4064 |
// doesn't change the error msg we get |
4065 |
- var ( |
|
4066 |
- err1 error |
|
4067 |
- err2 error |
|
4068 |
- ) |
|
4069 |
- |
|
4070 | 4065 |
name := "testspaces" |
4071 |
- ctx, err := fakeContext("FROM busybox\nCOPY\n", |
|
4066 |
+ ctx := fakeContext(c, "FROM busybox\nCOPY\n", |
|
4072 | 4067 |
map[string]string{ |
4073 | 4068 |
"Dockerfile": "FROM busybox\nCOPY\n", |
4074 | 4069 |
}) |
4075 |
- if err != nil { |
|
4076 |
- c.Fatal(err) |
|
4077 |
- } |
|
4078 | 4070 |
defer ctx.Close() |
4079 | 4071 |
|
4080 |
- if _, err1 = buildImageFromContext(name, ctx, false); err1 == nil { |
|
4081 |
- c.Fatal("Build 1 was supposed to fail, but didn't") |
|
4082 |
- } |
|
4072 |
+ result1 := buildImage(name, withExternalBuildContext(ctx)) |
|
4073 |
+ result1.Assert(c, icmd.Expected{ |
|
4074 |
+ ExitCode: 1, |
|
4075 |
+ }) |
|
4083 | 4076 |
|
4084 | 4077 |
ctx.Add("Dockerfile", "FROM busybox\nCOPY ") |
4085 |
- if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { |
|
4086 |
- c.Fatal("Build 2 was supposed to fail, but didn't") |
|
4087 |
- } |
|
4078 |
+ result2 := buildImage(name, withExternalBuildContext(ctx)) |
|
4079 |
+ result2.Assert(c, icmd.Expected{ |
|
4080 |
+ ExitCode: 1, |
|
4081 |
+ }) |
|
4088 | 4082 |
|
4089 | 4083 |
removeLogTimestamps := func(s string) string { |
4090 | 4084 |
return regexp.MustCompile(`time="(.*?)"`).ReplaceAllString(s, `time=[TIMESTAMP]`) |
4091 | 4085 |
} |
4092 | 4086 |
|
4093 | 4087 |
// Skip over the times |
4094 |
- e1 := removeLogTimestamps(err1.Error()) |
|
4095 |
- e2 := removeLogTimestamps(err2.Error()) |
|
4088 |
+ e1 := removeLogTimestamps(result1.Error.Error()) |
|
4089 |
+ e2 := removeLogTimestamps(result2.Error.Error()) |
|
4096 | 4090 |
|
4097 | 4091 |
// Ignore whitespace since that's what were verifying doesn't change stuff |
4098 | 4092 |
if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { |
4099 |
- c.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", err1, err2) |
|
4093 |
+ c.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", result1.Error, result2.Error) |
|
4100 | 4094 |
} |
4101 | 4095 |
|
4102 | 4096 |
ctx.Add("Dockerfile", "FROM busybox\n COPY") |
4103 |
- if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { |
|
4104 |
- c.Fatal("Build 3 was supposed to fail, but didn't") |
|
4105 |
- } |
|
4097 |
+ result2 = buildImage(name, withoutCache, withExternalBuildContext(ctx)) |
|
4098 |
+ result2.Assert(c, icmd.Expected{ |
|
4099 |
+ ExitCode: 1, |
|
4100 |
+ }) |
|
4106 | 4101 |
|
4107 | 4102 |
// Skip over the times |
4108 |
- e1 = removeLogTimestamps(err1.Error()) |
|
4109 |
- e2 = removeLogTimestamps(err2.Error()) |
|
4103 |
+ e1 = removeLogTimestamps(result1.Error.Error()) |
|
4104 |
+ e2 = removeLogTimestamps(result2.Error.Error()) |
|
4110 | 4105 |
|
4111 | 4106 |
// Ignore whitespace since that's what were verifying doesn't change stuff |
4112 | 4107 |
if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { |
4113 |
- c.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", err1, err2) |
|
4108 |
+ c.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", result1.Error, result2.Error) |
|
4114 | 4109 |
} |
4115 | 4110 |
|
4116 | 4111 |
ctx.Add("Dockerfile", "FROM busybox\n COPY ") |
4117 |
- if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { |
|
4118 |
- c.Fatal("Build 4 was supposed to fail, but didn't") |
|
4119 |
- } |
|
4112 |
+ result2 = buildImage(name, withoutCache, withExternalBuildContext(ctx)) |
|
4113 |
+ result2.Assert(c, icmd.Expected{ |
|
4114 |
+ ExitCode: 1, |
|
4115 |
+ }) |
|
4120 | 4116 |
|
4121 | 4117 |
// Skip over the times |
4122 |
- e1 = removeLogTimestamps(err1.Error()) |
|
4123 |
- e2 = removeLogTimestamps(err2.Error()) |
|
4118 |
+ e1 = removeLogTimestamps(result1.Error.Error()) |
|
4119 |
+ e2 = removeLogTimestamps(result2.Error.Error()) |
|
4124 | 4120 |
|
4125 | 4121 |
// Ignore whitespace since that's what were verifying doesn't change stuff |
4126 | 4122 |
if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { |
4127 |
- c.Fatalf("Build 4's error wasn't the same as build 1's\n1:%s\n4:%s", err1, err2) |
|
4123 |
+ c.Fatalf("Build 4's error wasn't the same as build 1's\n1:%s\n4:%s", result1.Error, result2.Error) |
|
4128 | 4124 |
} |
4129 | 4125 |
|
4130 | 4126 |
} |
... | ... |
@@ -4143,7 +3903,7 @@ RUN echo " \ |
4143 | 4143 |
expected = "\" foo \"" |
4144 | 4144 |
} |
4145 | 4145 |
|
4146 |
- buildImageNew(name, withDockerfile(dockerfile)).Assert(c, icmd.Expected{ |
|
4146 |
+ buildImage(name, withDockerfile(dockerfile)).Assert(c, icmd.Expected{ |
|
4147 | 4147 |
Out: expected, |
4148 | 4148 |
}) |
4149 | 4149 |
} |
... | ... |
@@ -4151,7 +3911,7 @@ RUN echo " \ |
4151 | 4151 |
// #4393 |
4152 | 4152 |
func (s *DockerSuite) TestBuildVolumeFileExistsinContainer(c *check.C) { |
4153 | 4153 |
testRequires(c, DaemonIsLinux) // TODO Windows: This should error out |
4154 |
- buildImageNew("docker-test-errcreatevolumewithfile", withDockerfile(` |
|
4154 |
+ buildImage("docker-test-errcreatevolumewithfile", withDockerfile(` |
|
4155 | 4155 |
FROM busybox |
4156 | 4156 |
RUN touch /foo |
4157 | 4157 |
VOLUME /foo |
... | ... |
@@ -4199,7 +3959,7 @@ func (s *DockerSuite) TestBuildMissingArgs(c *check.C) { |
4199 | 4199 |
dockerfile = "FROM busybox\n" + cmd |
4200 | 4200 |
} |
4201 | 4201 |
|
4202 |
- buildImageNew("args", withDockerfile(dockerfile)).Assert(c, icmd.Expected{ |
|
4202 |
+ buildImage("args", withDockerfile(dockerfile)).Assert(c, icmd.Expected{ |
|
4203 | 4203 |
ExitCode: 1, |
4204 | 4204 |
Err: cmd + " requires", |
4205 | 4205 |
}) |
... | ... |
@@ -4209,7 +3969,7 @@ func (s *DockerSuite) TestBuildMissingArgs(c *check.C) { |
4209 | 4209 |
|
4210 | 4210 |
func (s *DockerSuite) TestBuildEmptyScratch(c *check.C) { |
4211 | 4211 |
testRequires(c, DaemonIsLinux) |
4212 |
- buildImageNew("sc", withDockerfile("FROM scratch")).Assert(c, icmd.Expected{ |
|
4212 |
+ buildImage("sc", withDockerfile("FROM scratch")).Assert(c, icmd.Expected{ |
|
4213 | 4213 |
ExitCode: 1, |
4214 | 4214 |
Err: "No image was generated", |
4215 | 4215 |
}) |
... | ... |
@@ -4226,7 +3986,7 @@ func (s *DockerSuite) TestBuildRUNoneJSON(c *check.C) { |
4226 | 4226 |
testRequires(c, DaemonIsLinux) // No hello-world Windows image |
4227 | 4227 |
name := "testbuildrunonejson" |
4228 | 4228 |
|
4229 |
- buildImageNew(name, withDockerfile(`FROM hello-world:frozen |
|
4229 |
+ buildImage(name, withDockerfile(`FROM hello-world:frozen |
|
4230 | 4230 |
RUN [ "/hello" ]`)).Assert(c, icmd.Expected{ |
4231 | 4231 |
Out: "Hello from Docker", |
4232 | 4232 |
}) |
... | ... |
@@ -4235,7 +3995,7 @@ RUN [ "/hello" ]`)).Assert(c, icmd.Expected{ |
4235 | 4235 |
func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) { |
4236 | 4236 |
name := "testbuildemptystringvolume" |
4237 | 4237 |
|
4238 |
- buildImageNew(name, withDockerfile(` |
|
4238 |
+ buildImage(name, withDockerfile(` |
|
4239 | 4239 |
FROM busybox |
4240 | 4240 |
ENV foo="" |
4241 | 4241 |
VOLUME $foo |
... | ... |
@@ -4257,7 +4017,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) { |
4257 | 4257 |
if !found { |
4258 | 4258 |
c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths) |
4259 | 4259 |
} |
4260 |
- result := buildImageNew("buildcgroupparent", |
|
4260 |
+ result := buildImage("buildcgroupparent", |
|
4261 | 4261 |
withBuildFlags("--cgroup-parent", cgroupParent), |
4262 | 4262 |
withDockerfile(` |
4263 | 4263 |
FROM busybox |
... | ... |
@@ -4277,7 +4037,7 @@ func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) { |
4277 | 4277 |
// property - there was a bug that caused it to be duplicated on the |
4278 | 4278 |
// Step X line |
4279 | 4279 |
name := "testbuildnodupoutput" |
4280 |
- result := buildImageNew(name, withDockerfile(` |
|
4280 |
+ result := buildImage(name, withDockerfile(` |
|
4281 | 4281 |
FROM busybox |
4282 | 4282 |
RUN env`)) |
4283 | 4283 |
result.Assert(c, icmd.Success) |
... | ... |
@@ -4292,7 +4052,7 @@ func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) { |
4292 | 4292 |
func (s *DockerSuite) TestBuildStartsFromOne(c *check.C) { |
4293 | 4293 |
// Explicit check to ensure that build starts from step 1 rather than 0 |
4294 | 4294 |
name := "testbuildstartsfromone" |
4295 |
- result := buildImageNew(name, withDockerfile(`FROM busybox`)) |
|
4295 |
+ result := buildImage(name, withDockerfile(`FROM busybox`)) |
|
4296 | 4296 |
result.Assert(c, icmd.Success) |
4297 | 4297 |
exp := "\nStep 1/1 : FROM busybox\n" |
4298 | 4298 |
if !strings.Contains(result.Combined(), exp) { |
... | ... |
@@ -4313,7 +4073,7 @@ func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) { |
4313 | 4313 |
} |
4314 | 4314 |
exp := fmt.Sprintf(`The command '%s badEXE a1 \& a2 a3' returned a non-zero code: %d`, shell, exitCode) |
4315 | 4315 |
|
4316 |
- buildImageNew(name, withDockerfile(` |
|
4316 |
+ buildImage(name, withDockerfile(` |
|
4317 | 4317 |
FROM busybox |
4318 | 4318 |
RUN badEXE a1 \& a2 a3`)).Assert(c, icmd.Expected{ |
4319 | 4319 |
ExitCode: exitCode, |
... | ... |
@@ -4330,7 +4090,7 @@ func (s *DockerTrustSuite) TestTrustedBuild(c *check.C) { |
4330 | 4330 |
|
4331 | 4331 |
name := "testtrustedbuild" |
4332 | 4332 |
|
4333 |
- buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4333 |
+ buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4334 | 4334 |
Out: fmt.Sprintf("FROM %s@sha", repoName[:len(repoName)-7]), |
4335 | 4335 |
}) |
4336 | 4336 |
|
... | ... |
@@ -4350,7 +4110,7 @@ func (s *DockerTrustSuite) TestTrustedBuildUntrustedTag(c *check.C) { |
4350 | 4350 |
|
4351 | 4351 |
name := "testtrustedbuilduntrustedtag" |
4352 | 4352 |
|
4353 |
- buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4353 |
+ buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4354 | 4354 |
ExitCode: 1, |
4355 | 4355 |
Err: "does not have trust data for", |
4356 | 4356 |
}) |
... | ... |
@@ -4418,7 +4178,7 @@ func (s *DockerTrustSuite) TestTrustedBuildTagFromReleasesRole(c *check.C) { |
4418 | 4418 |
RUN [] |
4419 | 4419 |
`, otherTag) |
4420 | 4420 |
name := "testtrustedbuildreleasesrole" |
4421 |
- buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4421 |
+ buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4422 | 4422 |
Out: fmt.Sprintf("FROM %s@sha", repoName), |
4423 | 4423 |
}) |
4424 | 4424 |
} |
... | ... |
@@ -4451,7 +4211,7 @@ func (s *DockerTrustSuite) TestTrustedBuildTagIgnoresOtherDelegationRoles(c *che |
4451 | 4451 |
`, otherTag) |
4452 | 4452 |
|
4453 | 4453 |
name := "testtrustedbuildotherrole" |
4454 |
- buildImageNew(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4454 |
+ buildImage(name, trustedBuild, withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
4455 | 4455 |
ExitCode: 1, |
4456 | 4456 |
}) |
4457 | 4457 |
} |
... | ... |
@@ -4513,7 +4273,7 @@ func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) { |
4513 | 4513 |
CMD echo $%s`, envKey, envKey, envKey) |
4514 | 4514 |
|
4515 | 4515 |
} |
4516 |
- buildImageNew(imgName, |
|
4516 |
+ buildImage(imgName, |
|
4517 | 4517 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4518 | 4518 |
withDockerfile(dockerfile), |
4519 | 4519 |
).Assert(c, icmd.Expected{ |
... | ... |
@@ -4535,7 +4295,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgHistory(c *check.C) { |
4535 | 4535 |
envDef := "bar1" |
4536 | 4536 |
dockerfile := fmt.Sprintf(`FROM busybox |
4537 | 4537 |
ARG %s=%s`, envKey, envDef) |
4538 |
- buildImageNew(imgName, |
|
4538 |
+ buildImage(imgName, |
|
4539 | 4539 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4540 | 4540 |
withDockerfile(dockerfile), |
4541 | 4541 |
).Assert(c, icmd.Expected{ |
... | ... |
@@ -4560,16 +4320,14 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheHit(c *check.C) { |
4560 | 4560 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4561 | 4561 |
withDockerfile(dockerfile), |
4562 | 4562 |
) |
4563 |
- origImgID, err := getIDByName(imgName) |
|
4564 |
- c.Assert(err, checker.IsNil) |
|
4563 |
+ origImgID := getIDByName(c, imgName) |
|
4565 | 4564 |
|
4566 | 4565 |
imgNameCache := "bldargtestcachehit" |
4567 | 4566 |
buildImageSuccessfully(c, imgNameCache, |
4568 | 4567 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4569 | 4568 |
withDockerfile(dockerfile), |
4570 | 4569 |
) |
4571 |
- newImgID, err := getIDByName(imgName) |
|
4572 |
- c.Assert(err, checker.IsNil) |
|
4570 |
+ newImgID := getIDByName(c, imgName) |
|
4573 | 4571 |
if newImgID != origImgID { |
4574 | 4572 |
c.Fatalf("build didn't use cache! expected image id: %q built image id: %q", origImgID, newImgID) |
4575 | 4573 |
} |
... | ... |
@@ -4589,8 +4347,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissExtraArg(c *check.C) { |
4589 | 4589 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4590 | 4590 |
withDockerfile(dockerfile), |
4591 | 4591 |
) |
4592 |
- origImgID, err := getIDByName(imgName) |
|
4593 |
- c.Assert(err, checker.IsNil) |
|
4592 |
+ origImgID := getIDByName(c, imgName) |
|
4594 | 4593 |
|
4595 | 4594 |
imgNameCache := "bldargtestcachemiss" |
4596 | 4595 |
buildImageSuccessfully(c, imgNameCache, |
... | ... |
@@ -4600,8 +4357,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissExtraArg(c *check.C) { |
4600 | 4600 |
), |
4601 | 4601 |
withDockerfile(dockerfile), |
4602 | 4602 |
) |
4603 |
- newImgID, err := getIDByName(imgNameCache) |
|
4604 |
- c.Assert(err, checker.IsNil) |
|
4603 |
+ newImgID := getIDByName(c, imgNameCache) |
|
4605 | 4604 |
|
4606 | 4605 |
if newImgID == origImgID { |
4607 | 4606 |
c.Fatalf("build used cache, expected a miss!") |
... | ... |
@@ -4620,16 +4376,14 @@ func (s *DockerSuite) TestBuildBuildTimeArgCacheMissSameArgDiffVal(c *check.C) { |
4620 | 4620 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4621 | 4621 |
withDockerfile(dockerfile), |
4622 | 4622 |
) |
4623 |
- origImgID, err := getIDByName(imgName) |
|
4624 |
- c.Assert(err, checker.IsNil) |
|
4623 |
+ origImgID := getIDByName(c, imgName) |
|
4625 | 4624 |
|
4626 | 4625 |
imgNameCache := "bldargtestcachemiss" |
4627 | 4626 |
buildImageSuccessfully(c, imgNameCache, |
4628 | 4627 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, newEnvVal)), |
4629 | 4628 |
withDockerfile(dockerfile), |
4630 | 4629 |
) |
4631 |
- newImgID, err := getIDByName(imgNameCache) |
|
4632 |
- c.Assert(err, checker.IsNil) |
|
4630 |
+ newImgID := getIDByName(c, imgNameCache) |
|
4633 | 4631 |
if newImgID == origImgID { |
4634 | 4632 |
c.Fatalf("build used cache, expected a miss!") |
4635 | 4633 |
} |
... | ... |
@@ -4648,7 +4402,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgOverrideArgDefinedBeforeEnv(c *check. |
4648 | 4648 |
CMD echo $%s |
4649 | 4649 |
`, envKey, envKey, envValOveride, envKey, envKey) |
4650 | 4650 |
|
4651 |
- result := buildImageNew(imgName, |
|
4651 |
+ result := buildImage(imgName, |
|
4652 | 4652 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4653 | 4653 |
withDockerfile(dockerfile), |
4654 | 4654 |
) |
... | ... |
@@ -4676,7 +4430,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgOverrideEnvDefinedBeforeArg(c *check. |
4676 | 4676 |
RUN echo $%s |
4677 | 4677 |
CMD echo $%s |
4678 | 4678 |
`, envKey, envValOveride, envKey, envKey, envKey) |
4679 |
- result := buildImageNew(imgName, |
|
4679 |
+ result := buildImage(imgName, |
|
4680 | 4680 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4681 | 4681 |
withDockerfile(dockerfile), |
4682 | 4682 |
) |
... | ... |
@@ -4793,7 +4547,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansionOverride(c *check.C) { |
4793 | 4793 |
ENV %s ${%s} |
4794 | 4794 |
RUN echo $%s |
4795 | 4795 |
CMD echo $%s`, envKey, envKey, envValOveride, envKey1, envKey, envKey1, envKey1) |
4796 |
- result := buildImageNew(imgName, |
|
4796 |
+ result := buildImage(imgName, |
|
4797 | 4797 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4798 | 4798 |
withDockerfile(dockerfile), |
4799 | 4799 |
) |
... | ... |
@@ -4817,7 +4571,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgUntrustedDefinedAfterUse(c *check.C) |
4817 | 4817 |
RUN echo $%s |
4818 | 4818 |
ARG %s |
4819 | 4819 |
CMD echo $%s`, envKey, envKey, envKey) |
4820 |
- result := buildImageNew(imgName, |
|
4820 |
+ result := buildImage(imgName, |
|
4821 | 4821 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4822 | 4822 |
withDockerfile(dockerfile), |
4823 | 4823 |
) |
... | ... |
@@ -4841,7 +4595,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgBuiltinArg(c *check.C) { |
4841 | 4841 |
RUN echo $%s |
4842 | 4842 |
CMD echo $%s`, envKey, envKey) |
4843 | 4843 |
|
4844 |
- result := buildImageNew(imgName, |
|
4844 |
+ result := buildImage(imgName, |
|
4845 | 4845 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4846 | 4846 |
withDockerfile(dockerfile), |
4847 | 4847 |
) |
... | ... |
@@ -4866,7 +4620,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgDefaultOverride(c *check.C) { |
4866 | 4866 |
ENV %s $%s |
4867 | 4867 |
RUN echo $%s |
4868 | 4868 |
CMD echo $%s`, envKey, envVal, envKey, envKey, envKey, envKey) |
4869 |
- result := buildImageNew(imgName, |
|
4869 |
+ result := buildImage(imgName, |
|
4870 | 4870 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envValOveride)), |
4871 | 4871 |
withDockerfile(dockerfile), |
4872 | 4872 |
) |
... | ... |
@@ -4889,7 +4643,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) { |
4889 | 4889 |
RUN echo $%s |
4890 | 4890 |
CMD echo $%s`, envKey, envKey) |
4891 | 4891 |
warnStr := "[Warning] One or more build-args" |
4892 |
- buildImageNew(imgName, |
|
4892 |
+ buildImage(imgName, |
|
4893 | 4893 |
withBuildFlags("--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)), |
4894 | 4894 |
withDockerfile(dockerfile), |
4895 | 4895 |
).Assert(c, icmd.Expected{ |
... | ... |
@@ -4918,7 +4672,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgEnv(c *check.C) { |
4918 | 4918 |
RUN [ "$(env | grep FOO8)" == "" ] |
4919 | 4919 |
RUN [ "$(env | grep FOO9)" == "" ] |
4920 | 4920 |
` |
4921 |
- result := buildImageNew("testbuildtimeargenv", |
|
4921 |
+ result := buildImage("testbuildtimeargenv", |
|
4922 | 4922 |
withBuildFlags( |
4923 | 4923 |
"--build-arg", fmt.Sprintf("FOO1=fromcmd"), |
4924 | 4924 |
"--build-arg", fmt.Sprintf("FOO2="), |
... | ... |
@@ -4998,7 +4752,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgDefintionWithNoEnvInjection(c *check. |
4998 | 4998 |
ARG %s |
4999 | 4999 |
RUN env`, envKey) |
5000 | 5000 |
|
5001 |
- result := buildImageNew(imgName, withDockerfile(dockerfile)) |
|
5001 |
+ result := buildImage(imgName, withDockerfile(dockerfile)) |
|
5002 | 5002 |
result.Assert(c, icmd.Success) |
5003 | 5003 |
if strings.Count(result.Combined(), envKey) != 1 { |
5004 | 5004 |
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) { |
5017 | 5017 |
VOLUME ` + volName + ` |
5018 | 5018 |
RUN ls /foo/oops |
5019 | 5019 |
` |
5020 |
- buildImageNew("test", withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
5020 |
+ buildImage("test", withDockerfile(dockerFile)).Assert(c, icmd.Expected{ |
|
5021 | 5021 |
ExitCode: 1, |
5022 | 5022 |
}) |
5023 | 5023 |
} |
... | ... |
@@ -5053,105 +4807,97 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) { |
5053 | 5053 |
` |
5054 | 5054 |
buildImageSuccessfully(c, "tag1", withBuildFlags("-t", "tag2:v2", "-t", "tag1:latest", "-t", "tag1"), withDockerfile(dockerfile)) |
5055 | 5055 |
|
5056 |
- id1, err := getIDByName("tag1") |
|
5057 |
- c.Assert(err, check.IsNil) |
|
5058 |
- id2, err := getIDByName("tag2:v2") |
|
5059 |
- c.Assert(err, check.IsNil) |
|
5056 |
+ id1 := getIDByName(c, "tag1") |
|
5057 |
+ id2 := getIDByName(c, "tag2:v2") |
|
5060 | 5058 |
c.Assert(id1, check.Equals, id2) |
5061 | 5059 |
} |
5062 | 5060 |
|
5063 | 5061 |
// #17290 |
5064 | 5062 |
func (s *DockerSuite) TestBuildCacheBrokenSymlink(c *check.C) { |
5065 | 5063 |
name := "testbuildbrokensymlink" |
5066 |
- ctx, err := fakeContext(` |
|
5064 |
+ ctx := fakeContext(c, ` |
|
5067 | 5065 |
FROM busybox |
5068 | 5066 |
COPY . ./`, |
5069 | 5067 |
map[string]string{ |
5070 | 5068 |
"foo": "bar", |
5071 | 5069 |
}) |
5072 |
- c.Assert(err, checker.IsNil) |
|
5073 | 5070 |
defer ctx.Close() |
5074 | 5071 |
|
5075 |
- err = os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) |
|
5072 |
+ err := os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) |
|
5076 | 5073 |
c.Assert(err, checker.IsNil) |
5077 | 5074 |
|
5078 | 5075 |
// warm up cache |
5079 |
- _, err = buildImageFromContext(name, ctx, true) |
|
5080 |
- c.Assert(err, checker.IsNil) |
|
5076 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
5081 | 5077 |
|
5082 | 5078 |
// add new file to context, should invalidate cache |
5083 | 5079 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "newfile"), []byte("foo"), 0644) |
5084 | 5080 |
c.Assert(err, checker.IsNil) |
5085 | 5081 |
|
5086 |
- _, out, err := buildImageFromContextWithOut(name, ctx, true) |
|
5087 |
- c.Assert(err, checker.IsNil) |
|
5088 |
- |
|
5089 |
- c.Assert(out, checker.Not(checker.Contains), "Using cache") |
|
5090 |
- |
|
5082 |
+ result := buildImage(name, withExternalBuildContext(ctx)) |
|
5083 |
+ result.Assert(c, icmd.Success) |
|
5084 |
+ if strings.Contains(result.Combined(), "Using cache") { |
|
5085 |
+ c.Fatal("2nd build used cache on ADD, it shouldn't") |
|
5086 |
+ } |
|
5091 | 5087 |
} |
5092 | 5088 |
|
5093 | 5089 |
func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *check.C) { |
5094 | 5090 |
name := "testbuildbrokensymlink" |
5095 |
- ctx, err := fakeContext(` |
|
5091 |
+ ctx := fakeContext(c, ` |
|
5096 | 5092 |
FROM busybox |
5097 | 5093 |
COPY asymlink target`, |
5098 | 5094 |
map[string]string{ |
5099 | 5095 |
"foo": "bar", |
5100 | 5096 |
}) |
5101 |
- c.Assert(err, checker.IsNil) |
|
5102 | 5097 |
defer ctx.Close() |
5103 | 5098 |
|
5104 |
- err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5099 |
+ err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5105 | 5100 |
c.Assert(err, checker.IsNil) |
5106 | 5101 |
|
5107 |
- id, err := buildImageFromContext(name, ctx, true) |
|
5108 |
- c.Assert(err, checker.IsNil) |
|
5102 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
5109 | 5103 |
|
5110 |
- out, _ := dockerCmd(c, "run", "--rm", id, "cat", "target") |
|
5104 |
+ out, _ := dockerCmd(c, "run", "--rm", name, "cat", "target") |
|
5111 | 5105 |
c.Assert(out, checker.Matches, "bar") |
5112 | 5106 |
|
5113 | 5107 |
// change target file should invalidate cache |
5114 | 5108 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) |
5115 | 5109 |
c.Assert(err, checker.IsNil) |
5116 | 5110 |
|
5117 |
- id, out, err = buildImageFromContextWithOut(name, ctx, true) |
|
5118 |
- c.Assert(err, checker.IsNil) |
|
5119 |
- c.Assert(out, checker.Not(checker.Contains), "Using cache") |
|
5111 |
+ result := buildImage(name, withExternalBuildContext(ctx)) |
|
5112 |
+ result.Assert(c, icmd.Success) |
|
5113 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
|
5120 | 5114 |
|
5121 |
- out, _ = dockerCmd(c, "run", "--rm", id, "cat", "target") |
|
5115 |
+ out, _ = dockerCmd(c, "run", "--rm", name, "cat", "target") |
|
5122 | 5116 |
c.Assert(out, checker.Matches, "baz") |
5123 | 5117 |
} |
5124 | 5118 |
|
5125 | 5119 |
func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) { |
5126 | 5120 |
name := "testbuildbrokensymlink" |
5127 |
- ctx, err := fakeContext(` |
|
5121 |
+ ctx := fakeContext(c, ` |
|
5128 | 5122 |
FROM busybox |
5129 | 5123 |
COPY asymlink /`, |
5130 | 5124 |
map[string]string{ |
5131 | 5125 |
"foo/abc": "bar", |
5132 | 5126 |
"foo/def": "baz", |
5133 | 5127 |
}) |
5134 |
- c.Assert(err, checker.IsNil) |
|
5135 | 5128 |
defer ctx.Close() |
5136 | 5129 |
|
5137 |
- err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5130 |
+ err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5138 | 5131 |
c.Assert(err, checker.IsNil) |
5139 | 5132 |
|
5140 |
- id, err := buildImageFromContext(name, ctx, true) |
|
5141 |
- c.Assert(err, checker.IsNil) |
|
5133 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
5142 | 5134 |
|
5143 |
- out, _ := dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") |
|
5135 |
+ out, _ := dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") |
|
5144 | 5136 |
c.Assert(out, checker.Matches, "barbaz") |
5145 | 5137 |
|
5146 | 5138 |
// change target file should invalidate cache |
5147 | 5139 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644) |
5148 | 5140 |
c.Assert(err, checker.IsNil) |
5149 | 5141 |
|
5150 |
- id, out, err = buildImageFromContextWithOut(name, ctx, true) |
|
5151 |
- c.Assert(err, checker.IsNil) |
|
5152 |
- c.Assert(out, checker.Not(checker.Contains), "Using cache") |
|
5142 |
+ result := buildImage(name, withExternalBuildContext(ctx)) |
|
5143 |
+ result.Assert(c, icmd.Success) |
|
5144 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
|
5153 | 5145 |
|
5154 |
- out, _ = dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") |
|
5146 |
+ out, _ = dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") |
|
5155 | 5147 |
c.Assert(out, checker.Matches, "barbax") |
5156 | 5148 |
|
5157 | 5149 |
} |
... | ... |
@@ -5160,61 +4906,56 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) { |
5160 | 5160 |
// not from the target file. |
5161 | 5161 |
func (s *DockerSuite) TestBuildSymlinkBasename(c *check.C) { |
5162 | 5162 |
name := "testbuildbrokensymlink" |
5163 |
- ctx, err := fakeContext(` |
|
5163 |
+ ctx := fakeContext(c, ` |
|
5164 | 5164 |
FROM busybox |
5165 | 5165 |
COPY asymlink /`, |
5166 | 5166 |
map[string]string{ |
5167 | 5167 |
"foo": "bar", |
5168 | 5168 |
}) |
5169 |
- c.Assert(err, checker.IsNil) |
|
5170 | 5169 |
defer ctx.Close() |
5171 | 5170 |
|
5172 |
- err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5171 |
+ err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) |
|
5173 | 5172 |
c.Assert(err, checker.IsNil) |
5174 | 5173 |
|
5175 |
- id, err := buildImageFromContext(name, ctx, true) |
|
5176 |
- c.Assert(err, checker.IsNil) |
|
5174 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
5177 | 5175 |
|
5178 |
- out, _ := dockerCmd(c, "run", "--rm", id, "cat", "asymlink") |
|
5176 |
+ out, _ := dockerCmd(c, "run", "--rm", name, "cat", "asymlink") |
|
5179 | 5177 |
c.Assert(out, checker.Matches, "bar") |
5180 |
- |
|
5181 | 5178 |
} |
5182 | 5179 |
|
5183 | 5180 |
// #17827 |
5184 | 5181 |
func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) { |
5185 | 5182 |
name := "testbuildrootsource" |
5186 |
- ctx, err := fakeContext(` |
|
5183 |
+ ctx := fakeContext(c, ` |
|
5187 | 5184 |
FROM busybox |
5188 | 5185 |
COPY / /data`, |
5189 | 5186 |
map[string]string{ |
5190 | 5187 |
"foo": "bar", |
5191 | 5188 |
}) |
5192 |
- c.Assert(err, checker.IsNil) |
|
5193 | 5189 |
defer ctx.Close() |
5194 | 5190 |
|
5195 | 5191 |
// warm up cache |
5196 |
- _, err = buildImageFromContext(name, ctx, true) |
|
5197 |
- c.Assert(err, checker.IsNil) |
|
5192 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
5198 | 5193 |
|
5199 | 5194 |
// change file, should invalidate cache |
5200 |
- err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) |
|
5195 |
+ err := ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) |
|
5201 | 5196 |
c.Assert(err, checker.IsNil) |
5202 | 5197 |
|
5203 |
- _, out, err := buildImageFromContextWithOut(name, ctx, true) |
|
5204 |
- c.Assert(err, checker.IsNil) |
|
5198 |
+ result := buildImage(name, withExternalBuildContext(ctx)) |
|
5199 |
+ result.Assert(c, icmd.Success) |
|
5205 | 5200 |
|
5206 |
- c.Assert(out, checker.Not(checker.Contains), "Using cache") |
|
5201 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
|
5207 | 5202 |
} |
5208 | 5203 |
|
5209 | 5204 |
// #19375 |
5210 | 5205 |
func (s *DockerSuite) TestBuildFailsGitNotCallable(c *check.C) { |
5211 |
- buildImageNew("gitnotcallable", withEnvironmentVariales("PATH="), |
|
5206 |
+ buildImage("gitnotcallable", withEnvironmentVariales("PATH="), |
|
5212 | 5207 |
withBuildContextPath("github.com/docker/v1.10-migrator.git")).Assert(c, icmd.Expected{ |
5213 | 5208 |
ExitCode: 1, |
5214 | 5209 |
Err: "unable to prepare context: unable to find 'git': ", |
5215 | 5210 |
}) |
5216 | 5211 |
|
5217 |
- buildImageNew("gitnotcallable", withEnvironmentVariales("PATH="), |
|
5212 |
+ buildImage("gitnotcallable", withEnvironmentVariales("PATH="), |
|
5218 | 5213 |
withBuildContextPath("https://github.com/docker/v1.10-migrator.git")).Assert(c, icmd.Expected{ |
5219 | 5214 |
ExitCode: 1, |
5220 | 5215 |
Err: "unable to prepare context: unable to find 'git': ", |
... | ... |
@@ -5541,7 +5282,7 @@ func (s *DockerSuite) TestBuildShellUpdatesConfig(c *check.C) { |
5541 | 5541 |
func (s *DockerSuite) TestBuildShellMultiple(c *check.C) { |
5542 | 5542 |
name := "testbuildshellmultiple" |
5543 | 5543 |
|
5544 |
- result := buildImageNew(name, withDockerfile(`FROM busybox |
|
5544 |
+ result := buildImage(name, withDockerfile(`FROM busybox |
|
5545 | 5545 |
RUN echo defaultshell |
5546 | 5546 |
SHELL ["echo"] |
5547 | 5547 |
RUN echoshell |
... | ... |
@@ -5594,7 +5335,7 @@ func (s *DockerSuite) TestBuildShellInherited(c *check.C) { |
5594 | 5594 |
buildImageSuccessfully(c, name1, withDockerfile(`FROM busybox |
5595 | 5595 |
SHELL ["ls"]`)) |
5596 | 5596 |
name2 := "testbuildshellinherited2" |
5597 |
- buildImageNew(name2, withDockerfile(`FROM `+name1+` |
|
5597 |
+ buildImage(name2, withDockerfile(`FROM `+name1+` |
|
5598 | 5598 |
RUN -l`)).Assert(c, icmd.Expected{ |
5599 | 5599 |
// ls -l has "total " followed by some number in it, ls without -l does not. |
5600 | 5600 |
Out: "total ", |
... | ... |
@@ -5605,7 +5346,7 @@ func (s *DockerSuite) TestBuildShellInherited(c *check.C) { |
5605 | 5605 |
func (s *DockerSuite) TestBuildShellNotJSON(c *check.C) { |
5606 | 5606 |
name := "testbuildshellnotjson" |
5607 | 5607 |
|
5608 |
- buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
5608 |
+ buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
5609 | 5609 |
sHeLl exec -form`, // Casing explicit to ensure error is upper-cased. |
5610 | 5610 |
)).Assert(c, icmd.Expected{ |
5611 | 5611 |
ExitCode: 1, |
... | ... |
@@ -5618,7 +5359,7 @@ func (s *DockerSuite) TestBuildShellNotJSON(c *check.C) { |
5618 | 5618 |
func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) { |
5619 | 5619 |
testRequires(c, DaemonIsWindows) |
5620 | 5620 |
name := "testbuildshellpowershell" |
5621 |
- buildImageNew(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
5621 |
+ buildImage(name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
5622 | 5622 |
SHELL ["powershell", "-command"] |
5623 | 5623 |
RUN Write-Host John`)).Assert(c, icmd.Expected{ |
5624 | 5624 |
Out: "\nJohn\n", |
... | ... |
@@ -5630,7 +5371,7 @@ func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) { |
5630 | 5630 |
func (s *DockerSuite) TestBuildEscapeNotBackslashWordTest(c *check.C) { |
5631 | 5631 |
testRequires(c, DaemonIsWindows) |
5632 | 5632 |
name := "testbuildescapenotbackslashwordtesta" |
5633 |
- buildImageNew(name, withDockerfile(`# escape= `+"`"+` |
|
5633 |
+ buildImage(name, withDockerfile(`# escape= `+"`"+` |
|
5634 | 5634 |
FROM `+minimalBaseImage()+` |
5635 | 5635 |
WORKDIR c:\windows |
5636 | 5636 |
RUN dir /w`)).Assert(c, icmd.Expected{ |
... | ... |
@@ -5638,7 +5379,7 @@ func (s *DockerSuite) TestBuildEscapeNotBackslashWordTest(c *check.C) { |
5638 | 5638 |
}) |
5639 | 5639 |
|
5640 | 5640 |
name = "testbuildescapenotbackslashwordtestb" |
5641 |
- buildImageNew(name, withDockerfile(`# escape= `+"`"+` |
|
5641 |
+ buildImage(name, withDockerfile(`# escape= `+"`"+` |
|
5642 | 5642 |
FROM `+minimalBaseImage()+` |
5643 | 5643 |
SHELL ["powershell.exe"] |
5644 | 5644 |
WORKDIR c:\foo |
... | ... |
@@ -5673,7 +5414,7 @@ func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) { |
5673 | 5673 |
func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) { |
5674 | 5674 |
name := "testbuildstepswithprogress" |
5675 | 5675 |
totalRun := 5 |
5676 |
- result := buildImageNew(name, withDockerfile("FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun))) |
|
5676 |
+ result := buildImage(name, withDockerfile("FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun))) |
|
5677 | 5677 |
result.Assert(c, icmd.Success) |
5678 | 5678 |
c.Assert(result.Combined(), checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun)) |
5679 | 5679 |
for i := 2; i <= 1+totalRun; i++ { |
... | ... |
@@ -5686,14 +5427,14 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) { |
5686 | 5686 |
|
5687 | 5687 |
// First test case can only detect `nobody` in runtime so all steps will show up |
5688 | 5688 |
dockerfile := "FROM busybox\nRUN nobody" |
5689 |
- result := buildImageNew(name, withDockerfile(dockerfile)) |
|
5689 |
+ result := buildImage(name, withDockerfile(dockerfile)) |
|
5690 | 5690 |
c.Assert(result.Error, checker.NotNil) |
5691 | 5691 |
c.Assert(result.Stdout(), checker.Contains, "Step 1/2 : FROM busybox") |
5692 | 5692 |
c.Assert(result.Stdout(), checker.Contains, "Step 2/2 : RUN nobody") |
5693 | 5693 |
|
5694 | 5694 |
// Second test case `FFOM` should have been detected before build runs so no steps |
5695 | 5695 |
dockerfile = "FFOM nobody\nRUN nobody" |
5696 |
- result = buildImageNew(name, withDockerfile(dockerfile)) |
|
5696 |
+ result = buildImage(name, withDockerfile(dockerfile)) |
|
5697 | 5697 |
c.Assert(result.Error, checker.NotNil) |
5698 | 5698 |
c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 1/2 : FROM busybox") |
5699 | 5699 |
c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody") |
... | ... |
@@ -5706,28 +5447,29 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { |
5706 | 5706 |
ENV FOO=bar |
5707 | 5707 |
ADD baz / |
5708 | 5708 |
RUN touch bax` |
5709 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
5709 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
5710 | 5710 |
"Dockerfile": dockerfile, |
5711 | 5711 |
"baz": "baz", |
5712 | 5712 |
}) |
5713 |
- c.Assert(err, checker.IsNil) |
|
5714 | 5713 |
defer ctx.Close() |
5715 | 5714 |
|
5716 |
- id1, err := buildImageFromContext("build1", ctx, true) |
|
5717 |
- c.Assert(err, checker.IsNil) |
|
5715 |
+ buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx)) |
|
5716 |
+ id1 := getIDByName(c, "build1") |
|
5718 | 5717 |
|
5719 | 5718 |
// rebuild with cache-from |
5720 |
- id2, out, err := buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") |
|
5721 |
- c.Assert(err, checker.IsNil) |
|
5719 |
+ result := buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) |
|
5720 |
+ result.Assert(c, icmd.Success) |
|
5721 |
+ id2 := getIDByName(c, "build2") |
|
5722 | 5722 |
c.Assert(id1, checker.Equals, id2) |
5723 |
- c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) |
|
5723 |
+ c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
|
5724 | 5724 |
dockerCmd(c, "rmi", "build2") |
5725 | 5725 |
|
5726 | 5726 |
// no cache match with unknown source |
5727 |
- id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=nosuchtag") |
|
5728 |
- c.Assert(err, checker.IsNil) |
|
5727 |
+ result = buildImage("build2", withBuildFlags("--cache-from=nosuchtag"), withExternalBuildContext(ctx)) |
|
5728 |
+ result.Assert(c, icmd.Success) |
|
5729 |
+ id2 = getIDByName(c, "build2") |
|
5729 | 5730 |
c.Assert(id1, checker.Not(checker.Equals), id2) |
5730 |
- c.Assert(strings.Count(out, "Using cache"), checker.Equals, 0) |
|
5731 |
+ c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 0) |
|
5731 | 5732 |
dockerCmd(c, "rmi", "build2") |
5732 | 5733 |
|
5733 | 5734 |
// clear parent images |
... | ... |
@@ -5744,17 +5486,19 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { |
5744 | 5744 |
c.Assert(strings.TrimSpace(parentID), checker.Equals, "") |
5745 | 5745 |
|
5746 | 5746 |
// cache still applies without parents |
5747 |
- id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") |
|
5748 |
- c.Assert(err, checker.IsNil) |
|
5747 |
+ result = buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) |
|
5748 |
+ result.Assert(c, icmd.Success) |
|
5749 |
+ id2 = getIDByName(c, "build2") |
|
5749 | 5750 |
c.Assert(id1, checker.Equals, id2) |
5750 |
- c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) |
|
5751 |
+ c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
|
5751 | 5752 |
history1, _ := dockerCmd(c, "history", "-q", "build2") |
5752 | 5753 |
|
5753 | 5754 |
// Retry, no new intermediate images |
5754 |
- id3, out, err := buildImageFromContextWithOut("build3", ctx, true, "--cache-from=build1") |
|
5755 |
- c.Assert(err, checker.IsNil) |
|
5755 |
+ result = buildImage("build3", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) |
|
5756 |
+ result.Assert(c, icmd.Success) |
|
5757 |
+ id3 := getIDByName(c, "build3") |
|
5756 | 5758 |
c.Assert(id1, checker.Equals, id3) |
5757 |
- c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) |
|
5759 |
+ c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
|
5758 | 5760 |
history2, _ := dockerCmd(c, "history", "-q", "build3") |
5759 | 5761 |
|
5760 | 5762 |
c.Assert(history1, checker.Equals, history2) |
... | ... |
@@ -5772,10 +5516,11 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { |
5772 | 5772 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(dockerfile), 0644) |
5773 | 5773 |
c.Assert(err, checker.IsNil) |
5774 | 5774 |
|
5775 |
- id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") |
|
5776 |
- c.Assert(err, checker.IsNil) |
|
5775 |
+ result = buildImage("build2", withBuildFlags("--cache-from=build1"), withExternalBuildContext(ctx)) |
|
5776 |
+ result.Assert(c, icmd.Success) |
|
5777 |
+ id2 = getIDByName(c, "build2") |
|
5777 | 5778 |
c.Assert(id1, checker.Not(checker.Equals), id2) |
5778 |
- c.Assert(strings.Count(out, "Using cache"), checker.Equals, 2) |
|
5779 |
+ c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) |
|
5779 | 5780 |
|
5780 | 5781 |
layers1Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1") |
5781 | 5782 |
layers2Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2") |
... | ... |
@@ -5795,7 +5540,7 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { |
5795 | 5795 |
func (s *DockerSuite) TestBuildNetNone(c *check.C) { |
5796 | 5796 |
testRequires(c, DaemonIsLinux) |
5797 | 5797 |
name := "testbuildnetnone" |
5798 |
- buildImageNew(name, withBuildFlags("--network=none"), withDockerfile(` |
|
5798 |
+ buildImage(name, withBuildFlags("--network=none"), withDockerfile(` |
|
5799 | 5799 |
FROM busybox |
5800 | 5800 |
RUN ping -c 1 8.8.8.8 |
5801 | 5801 |
`)).Assert(c, icmd.Expected{ |
... | ... |
@@ -5833,13 +5578,11 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { |
5833 | 5833 |
// build and get the ID that we can use later for history comparison |
5834 | 5834 |
name := "test" |
5835 | 5835 |
buildImageSuccessfully(c, name, withDockerfile(dockerFile)) |
5836 |
- origID, err := getIDByName(name) |
|
5837 |
- c.Assert(err, checker.IsNil) |
|
5836 |
+ origID := getIDByName(c, name) |
|
5838 | 5837 |
|
5839 | 5838 |
// build with squash |
5840 | 5839 |
buildImageSuccessfully(c, name, withBuildFlags("--squash"), withDockerfile(dockerFile)) |
5841 |
- id, err := getIDByName(name) |
|
5842 |
- c.Assert(err, checker.IsNil) |
|
5840 |
+ id := getIDByName(c, name) |
|
5843 | 5841 |
|
5844 | 5842 |
out, _ := dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", "cat /hello") |
5845 | 5843 |
c.Assert(strings.TrimSpace(out), checker.Equals, "hello\nworld") |
... | ... |
@@ -5867,23 +5610,23 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { |
5867 | 5867 |
func (s *DockerSuite) TestBuildContChar(c *check.C) { |
5868 | 5868 |
name := "testbuildcontchar" |
5869 | 5869 |
|
5870 |
- buildImageNew(name, withDockerfile(`FROM busybox\`)).Assert(c, icmd.Expected{ |
|
5870 |
+ buildImage(name, withDockerfile(`FROM busybox\`)).Assert(c, icmd.Expected{ |
|
5871 | 5871 |
Out: "Step 1/1 : FROM busybox", |
5872 | 5872 |
}) |
5873 | 5873 |
|
5874 |
- result := buildImageNew(name, withDockerfile(`FROM busybox |
|
5874 |
+ result := buildImage(name, withDockerfile(`FROM busybox |
|
5875 | 5875 |
RUN echo hi \`)) |
5876 | 5876 |
result.Assert(c, icmd.Success) |
5877 | 5877 |
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") |
5878 | 5878 |
c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi\n") |
5879 | 5879 |
|
5880 |
- result = buildImageNew(name, withDockerfile(`FROM busybox |
|
5880 |
+ result = buildImage(name, withDockerfile(`FROM busybox |
|
5881 | 5881 |
RUN echo hi \\`)) |
5882 | 5882 |
result.Assert(c, icmd.Success) |
5883 | 5883 |
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") |
5884 | 5884 |
c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\n") |
5885 | 5885 |
|
5886 |
- result = buildImageNew(name, withDockerfile(`FROM busybox |
|
5886 |
+ result = buildImage(name, withDockerfile(`FROM busybox |
|
5887 | 5887 |
RUN echo hi \\\`)) |
5888 | 5888 |
result.Assert(c, icmd.Success) |
5889 | 5889 |
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox") |
... | ... |
@@ -5911,7 +5654,7 @@ func (s *DockerSuite) TestBuildOpaqueDirectory(c *check.C) { |
5911 | 5911 |
func (s *DockerSuite) TestBuildWindowsUser(c *check.C) { |
5912 | 5912 |
testRequires(c, DaemonIsWindows) |
5913 | 5913 |
name := "testbuildwindowsuser" |
5914 |
- buildImageNew(name, withDockerfile(`FROM `+testEnv.MinimalBaseImage()+` |
|
5914 |
+ buildImage(name, withDockerfile(`FROM `+testEnv.MinimalBaseImage()+` |
|
5915 | 5915 |
RUN net user user /add |
5916 | 5916 |
USER user |
5917 | 5917 |
RUN set username |
... | ... |
@@ -5987,7 +5730,7 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) { |
5987 | 5987 |
WORKDIR / |
5988 | 5988 |
` |
5989 | 5989 |
buildImageSuccessfully(c, name, withDockerfile(dockerFile)) |
5990 |
- result := buildImageNew(name, withDockerfile(dockerFile)) |
|
5990 |
+ result := buildImage(name, withDockerfile(dockerFile)) |
|
5991 | 5991 |
result.Assert(c, icmd.Success) |
5992 | 5992 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 1) |
5993 | 5993 |
} |
... | ... |
@@ -5995,7 +5738,7 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) { |
5995 | 5995 |
// FIXME(vdemeester) should be a unit test |
5996 | 5996 |
func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) { |
5997 | 5997 |
name := "test_build_line_error_onbuild" |
5998 |
- buildImageNew(name, withDockerfile(`FROM busybox |
|
5998 |
+ buildImage(name, withDockerfile(`FROM busybox |
|
5999 | 5999 |
ONBUILD |
6000 | 6000 |
`)).Assert(c, icmd.Expected{ |
6001 | 6001 |
ExitCode: 1, |
... | ... |
@@ -6006,7 +5749,7 @@ func (s *DockerSuite) TestBuildLineErrorOnBuild(c *check.C) { |
6006 | 6006 |
// FIXME(vdemeester) should be a unit test |
6007 | 6007 |
func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) { |
6008 | 6008 |
name := "test_build_line_error_unknown_instruction" |
6009 |
- buildImageNew(name, withDockerfile(`FROM busybox |
|
6009 |
+ buildImage(name, withDockerfile(`FROM busybox |
|
6010 | 6010 |
RUN echo hello world |
6011 | 6011 |
NOINSTRUCTION echo ba |
6012 | 6012 |
RUN echo hello |
... | ... |
@@ -6020,7 +5763,7 @@ func (s *DockerSuite) TestBuildLineErrorUknownInstruction(c *check.C) { |
6020 | 6020 |
// FIXME(vdemeester) should be a unit test |
6021 | 6021 |
func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) { |
6022 | 6022 |
name := "test_build_line_error_with_empty_lines" |
6023 |
- buildImageNew(name, withDockerfile(` |
|
6023 |
+ buildImage(name, withDockerfile(` |
|
6024 | 6024 |
FROM busybox |
6025 | 6025 |
|
6026 | 6026 |
RUN echo hello world |
... | ... |
@@ -6037,7 +5780,7 @@ func (s *DockerSuite) TestBuildLineErrorWithEmptyLines(c *check.C) { |
6037 | 6037 |
// FIXME(vdemeester) should be a unit test |
6038 | 6038 |
func (s *DockerSuite) TestBuildLineErrorWithComments(c *check.C) { |
6039 | 6039 |
name := "test_build_line_error_with_comments" |
6040 |
- buildImageNew(name, withDockerfile(`FROM busybox |
|
6040 |
+ buildImage(name, withDockerfile(`FROM busybox |
|
6041 | 6041 |
# This will print hello world |
6042 | 6042 |
# and then ba |
6043 | 6043 |
RUN echo hello world |
... | ... |
@@ -25,13 +25,11 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { |
25 | 25 |
testRequires(c, cpuCfsQuota) |
26 | 26 |
name := "testbuildresourceconstraints" |
27 | 27 |
|
28 |
- ctx, err := fakeContext(` |
|
28 |
+ ctx := fakeContext(c, ` |
|
29 | 29 |
FROM hello-world:frozen |
30 | 30 |
RUN ["/hello"] |
31 | 31 |
`, map[string]string{}) |
32 |
- c.Assert(err, checker.IsNil) |
|
33 |
- |
|
34 |
- _, _, 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, ".") |
|
32 |
+ _, _, 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, ".") |
|
35 | 33 |
if err != nil { |
36 | 34 |
c.Fatal(err) |
37 | 35 |
} |
... | ... |
@@ -114,9 +112,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) { |
114 | 114 |
|
115 | 115 |
defer ctx.Close() |
116 | 116 |
|
117 |
- if _, err := buildImageFromContext(name, ctx, true); err != nil { |
|
118 |
- c.Fatalf("build failed to complete for TestBuildAddChangeOwnership: %v", err) |
|
119 |
- } |
|
117 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
120 | 118 |
} |
121 | 119 |
|
122 | 120 |
// 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) { |
137 | 137 |
defer observer.Stop() |
138 | 138 |
|
139 | 139 |
// (Note: one year, will never finish) |
140 |
- ctx, err := fakeContext("FROM busybox\nRUN sleep 31536000", nil) |
|
141 |
- if err != nil { |
|
142 |
- c.Fatal(err) |
|
143 |
- } |
|
140 |
+ ctx := fakeContext(c, "FROM busybox\nRUN sleep 31536000", nil) |
|
144 | 141 |
defer ctx.Close() |
145 | 142 |
|
146 | 143 |
buildCmd := exec.Command(dockerBinary, "build", "-t", name, ".") |
... | ... |
@@ -193,10 +193,9 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { |
193 | 193 |
|
194 | 194 |
// do the build |
195 | 195 |
name := "buildbydigest" |
196 |
- _, err = buildImage(name, fmt.Sprintf( |
|
196 |
+ buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf( |
|
197 | 197 |
`FROM %s |
198 |
- CMD ["/bin/echo", "Hello World"]`, imageReference), |
|
199 |
- true) |
|
198 |
+ CMD ["/bin/echo", "Hello World"]`, imageReference))) |
|
200 | 199 |
c.Assert(err, checker.IsNil) |
201 | 200 |
|
202 | 201 |
// get the build's image id |
... | ... |
@@ -417,20 +416,17 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c |
417 | 417 |
|
418 | 418 |
// build an image from it |
419 | 419 |
imageName1 := "images_ps_filter_test" |
420 |
- _, err = buildImage(imageName1, fmt.Sprintf( |
|
420 |
+ buildImageSuccessfully(c, imageName1, withDockerfile(fmt.Sprintf( |
|
421 | 421 |
`FROM %s |
422 |
- LABEL match me 1`, imageReference), true) |
|
423 |
- c.Assert(err, checker.IsNil) |
|
422 |
+ LABEL match me 1`, imageReference))) |
|
424 | 423 |
|
425 | 424 |
// run a container based on that |
426 | 425 |
dockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello") |
427 |
- expectedID, err := getIDByName("test1") |
|
428 |
- c.Assert(err, check.IsNil) |
|
426 |
+ expectedID := getIDByName(c, "test1") |
|
429 | 427 |
|
430 | 428 |
// run a container based on the a descendant of that too |
431 | 429 |
dockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello") |
432 |
- expectedID1, err := getIDByName("test2") |
|
433 |
- c.Assert(err, check.IsNil) |
|
430 |
+ expectedID1 := getIDByName(c, "test2") |
|
434 | 431 |
|
435 | 432 |
expectedIDs := []string{expectedID, expectedID1} |
436 | 433 |
|
... | ... |
@@ -204,12 +204,8 @@ func (s *DockerSuite) TestCreateLabels(c *check.C) { |
204 | 204 |
|
205 | 205 |
func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) { |
206 | 206 |
imageName := "testcreatebuildlabel" |
207 |
- _, err := buildImage(imageName, |
|
208 |
- `FROM busybox |
|
209 |
- LABEL k1=v1 k2=v2`, |
|
210 |
- true) |
|
211 |
- |
|
212 |
- c.Assert(err, check.IsNil) |
|
207 |
+ buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox |
|
208 |
+ LABEL k1=v1 k2=v2`)) |
|
213 | 209 |
|
214 | 210 |
name := "test_create_labels_from_image" |
215 | 211 |
expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"} |
... | ... |
@@ -263,13 +259,9 @@ func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) { |
263 | 263 |
|
264 | 264 |
func (s *DockerSuite) TestCreateByImageID(c *check.C) { |
265 | 265 |
imageName := "testcreatebyimageid" |
266 |
- imageID, err := buildImage(imageName, |
|
267 |
- `FROM busybox |
|
268 |
- MAINTAINER dockerio`, |
|
269 |
- true) |
|
270 |
- if err != nil { |
|
271 |
- c.Fatal(err) |
|
272 |
- } |
|
266 |
+ buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox |
|
267 |
+ MAINTAINER dockerio`)) |
|
268 |
+ imageID := getIDByName(c, imageName) |
|
273 | 269 |
truncatedImageID := stringid.TruncateID(imageID) |
274 | 270 |
|
275 | 271 |
dockerCmd(c, "create", imageID) |
... | ... |
@@ -444,16 +436,14 @@ RUN chmod 755 /entrypoint.sh |
444 | 444 |
ENTRYPOINT ["/entrypoint.sh"] |
445 | 445 |
CMD echo foobar` |
446 | 446 |
|
447 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
447 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
448 | 448 |
"entrypoint.sh": `#!/bin/sh |
449 | 449 |
echo "I am an entrypoint" |
450 | 450 |
exec "$@"`, |
451 | 451 |
}) |
452 |
- c.Assert(err, check.IsNil) |
|
453 | 452 |
defer ctx.Close() |
454 | 453 |
|
455 |
- _, err = buildImageFromContext(name, ctx, true) |
|
456 |
- c.Assert(err, check.IsNil) |
|
454 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
457 | 455 |
|
458 | 456 |
out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo") |
459 | 457 |
id := strings.TrimSpace(out) |
... | ... |
@@ -379,11 +379,9 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) { |
379 | 379 |
label := "io.docker.testing=image" |
380 | 380 |
|
381 | 381 |
// Build a test image. |
382 |
- _, err := buildImage(name, fmt.Sprintf(` |
|
382 |
+ buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(` |
|
383 | 383 |
FROM busybox:latest |
384 |
- LABEL %s`, label), true) |
|
385 |
- c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) |
|
386 |
- |
|
384 |
+ LABEL %s`, label))) |
|
387 | 385 |
dockerCmd(c, "tag", name, "labelfiltertest:tag1") |
388 | 386 |
dockerCmd(c, "tag", name, "labelfiltertest:tag2") |
389 | 387 |
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") |
... | ... |
@@ -462,10 +460,10 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) { |
462 | 462 |
|
463 | 463 |
func (s *DockerSuite) TestEventsCopy(c *check.C) { |
464 | 464 |
// Build a test image. |
465 |
- id, err := buildImage("cpimg", ` |
|
465 |
+ buildImageSuccessfully(c, "cpimg", withDockerfile(` |
|
466 | 466 |
FROM busybox |
467 |
- RUN echo HI > /file`, true) |
|
468 |
- c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) |
|
467 |
+ RUN echo HI > /file`)) |
|
468 |
+ id := getIDByName(c, "cpimg") |
|
469 | 469 |
|
470 | 470 |
// Create an empty test file. |
471 | 471 |
tempFile, err := ioutil.TempFile("", "test-events-copy-") |
... | ... |
@@ -595,11 +593,9 @@ func (s *DockerSuite) TestEventsFilterType(c *check.C) { |
595 | 595 |
label := "io.docker.testing=image" |
596 | 596 |
|
597 | 597 |
// Build a test image. |
598 |
- _, err := buildImage(name, fmt.Sprintf(` |
|
598 |
+ buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(` |
|
599 | 599 |
FROM busybox:latest |
600 |
- LABEL %s`, label), true) |
|
601 |
- c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) |
|
602 |
- |
|
600 |
+ LABEL %s`, label))) |
|
603 | 601 |
dockerCmd(c, "tag", name, "labelfiltertest:tag1") |
604 | 602 |
dockerCmd(c, "tag", name, "labelfiltertest:tag2") |
605 | 603 |
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") |
... | ... |
@@ -310,11 +310,9 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) { |
310 | 310 |
defer observer.Stop() |
311 | 311 |
|
312 | 312 |
name := "testimageevents" |
313 |
- imageID, err := buildImage(name, |
|
314 |
- `FROM scratch |
|
315 |
- MAINTAINER "docker"`, |
|
316 |
- true) |
|
317 |
- c.Assert(err, checker.IsNil) |
|
313 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM scratch |
|
314 |
+ MAINTAINER "docker"`)) |
|
315 |
+ imageID := getIDByName(c, name) |
|
318 | 316 |
c.Assert(deleteImages(name), checker.IsNil) |
319 | 317 |
|
320 | 318 |
testActions := map[string]chan bool{ |
... | ... |
@@ -473,13 +473,9 @@ func (s *DockerSuite) TestExecWithImageUser(c *check.C) { |
473 | 473 |
// Not applicable on Windows |
474 | 474 |
testRequires(c, DaemonIsLinux) |
475 | 475 |
name := "testbuilduser" |
476 |
- _, err := buildImage(name, |
|
477 |
- `FROM busybox |
|
476 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
478 | 477 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
479 |
- USER dockerio`, |
|
480 |
- true) |
|
481 |
- c.Assert(err, checker.IsNil) |
|
482 |
- |
|
478 |
+ USER dockerio`)) |
|
483 | 479 |
dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top") |
484 | 480 |
|
485 | 481 |
out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami") |
... | ... |
@@ -40,16 +40,12 @@ func (s *DockerSuite) TestHealth(c *check.C) { |
40 | 40 |
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows |
41 | 41 |
|
42 | 42 |
imageName := "testhealth" |
43 |
- _, err := buildImage(imageName, |
|
44 |
- `FROM busybox |
|
43 |
+ buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox |
|
45 | 44 |
RUN echo OK > /status |
46 | 45 |
CMD ["/bin/sleep", "120"] |
47 | 46 |
STOPSIGNAL SIGKILL |
48 | 47 |
HEALTHCHECK --interval=1s --timeout=30s \ |
49 |
- CMD cat /status`, |
|
50 |
- true) |
|
51 |
- |
|
52 |
- c.Check(err, check.IsNil) |
|
48 |
+ CMD cat /status`)) |
|
53 | 49 |
|
54 | 50 |
// No health status before starting |
55 | 51 |
name := "test_health" |
... | ... |
@@ -91,10 +87,8 @@ func (s *DockerSuite) TestHealth(c *check.C) { |
91 | 91 |
dockerCmd(c, "rm", "noh") |
92 | 92 |
|
93 | 93 |
// Disable the check with a new build |
94 |
- _, err = buildImage("no_healthcheck", |
|
95 |
- `FROM testhealth |
|
96 |
- HEALTHCHECK NONE`, true) |
|
97 |
- c.Check(err, check.IsNil) |
|
94 |
+ buildImageSuccessfully(c, "no_healthcheck", withDockerfile(`FROM testhealth |
|
95 |
+ HEALTHCHECK NONE`)) |
|
98 | 96 |
|
99 | 97 |
out, _ = dockerCmd(c, "inspect", "--format={{.ContainerConfig.Healthcheck.Test}}", "no_healthcheck") |
100 | 98 |
c.Check(out, checker.Equals, "[NONE]\n") |
... | ... |
@@ -137,15 +131,12 @@ func (s *DockerSuite) TestHealth(c *check.C) { |
137 | 137 |
dockerCmd(c, "rm", "-f", "test") |
138 | 138 |
|
139 | 139 |
// Check JSON-format |
140 |
- _, err = buildImage(imageName, |
|
141 |
- `FROM busybox |
|
140 |
+ buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox |
|
142 | 141 |
RUN echo OK > /status |
143 | 142 |
CMD ["/bin/sleep", "120"] |
144 | 143 |
STOPSIGNAL SIGKILL |
145 | 144 |
HEALTHCHECK --interval=1s --timeout=30s \ |
146 |
- CMD ["cat", "/my status"]`, |
|
147 |
- true) |
|
148 |
- c.Check(err, check.IsNil) |
|
145 |
+ CMD ["cat", "/my status"]`)) |
|
149 | 146 |
out, _ = dockerCmd(c, "inspect", |
150 | 147 |
"--format={{.Config.Healthcheck.Test}}", imageName) |
151 | 148 |
c.Check(out, checker.Equals, "[CMD cat /my status]\n") |
... | ... |
@@ -14,7 +14,7 @@ import ( |
14 | 14 |
// sort is not predictable it doesn't always fail. |
15 | 15 |
func (s *DockerSuite) TestBuildHistory(c *check.C) { |
16 | 16 |
name := "testbuildhistory" |
17 |
- _, err := buildImage(name, `FROM `+minimalBaseImage()+` |
|
17 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM `+minimalBaseImage()+` |
|
18 | 18 |
LABEL label.A="A" |
19 | 19 |
LABEL label.B="B" |
20 | 20 |
LABEL label.C="C" |
... | ... |
@@ -40,12 +40,9 @@ LABEL label.V="V" |
40 | 40 |
LABEL label.W="W" |
41 | 41 |
LABEL label.X="X" |
42 | 42 |
LABEL label.Y="Y" |
43 |
-LABEL label.Z="Z"`, |
|
44 |
- true) |
|
43 |
+LABEL label.Z="Z"`)) |
|
45 | 44 |
|
46 |
- c.Assert(err, checker.IsNil) |
|
47 |
- |
|
48 |
- out, _ := dockerCmd(c, "history", "testbuildhistory") |
|
45 |
+ out, _ := dockerCmd(c, "history", name) |
|
49 | 46 |
actualValues := strings.Split(out, "\n")[1:27] |
50 | 47 |
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"} |
51 | 48 |
|
... | ... |
@@ -12,6 +12,7 @@ import ( |
12 | 12 |
|
13 | 13 |
"github.com/docker/docker/integration-cli/checker" |
14 | 14 |
"github.com/docker/docker/pkg/stringid" |
15 |
+ icmd "github.com/docker/docker/pkg/testutil/cmd" |
|
15 | 16 |
"github.com/go-check/check" |
16 | 17 |
) |
17 | 18 |
|
... | ... |
@@ -45,20 +46,17 @@ func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) { |
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) { |
48 |
- id1, err := buildImage("order:test_a", |
|
49 |
- `FROM busybox |
|
50 |
- MAINTAINER dockerio1`, true) |
|
51 |
- c.Assert(err, checker.IsNil) |
|
48 |
+ buildImageSuccessfully(c, "order:test_a", withDockerfile(`FROM busybox |
|
49 |
+ MAINTAINER dockerio1`)) |
|
50 |
+ id1 := getIDByName(c, "order:test_a") |
|
52 | 51 |
time.Sleep(1 * time.Second) |
53 |
- id2, err := buildImage("order:test_c", |
|
54 |
- `FROM busybox |
|
55 |
- MAINTAINER dockerio2`, true) |
|
56 |
- c.Assert(err, checker.IsNil) |
|
52 |
+ buildImageSuccessfully(c, "order:test_c", withDockerfile(`FROM busybox |
|
53 |
+ MAINTAINER dockerio2`)) |
|
54 |
+ id2 := getIDByName(c, "order:test_c") |
|
57 | 55 |
time.Sleep(1 * time.Second) |
58 |
- id3, err := buildImage("order:test_b", |
|
59 |
- `FROM busybox |
|
60 |
- MAINTAINER dockerio3`, true) |
|
61 |
- c.Assert(err, checker.IsNil) |
|
56 |
+ buildImageSuccessfully(c, "order:test_b", withDockerfile(`FROM busybox |
|
57 |
+ MAINTAINER dockerio3`)) |
|
58 |
+ id3 := getIDByName(c, "order:test_b") |
|
62 | 59 |
|
63 | 60 |
out, _ := dockerCmd(c, "images", "-q", "--no-trunc") |
64 | 61 |
imgs := strings.Split(out, "\n") |
... | ... |
@@ -77,20 +75,17 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) { |
77 | 77 |
imageName1 := "images_filter_test1" |
78 | 78 |
imageName2 := "images_filter_test2" |
79 | 79 |
imageName3 := "images_filter_test3" |
80 |
- image1ID, err := buildImage(imageName1, |
|
81 |
- `FROM busybox |
|
82 |
- LABEL match me`, true) |
|
83 |
- c.Assert(err, check.IsNil) |
|
80 |
+ buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox |
|
81 |
+ LABEL match me`)) |
|
82 |
+ image1ID := getIDByName(c, imageName1) |
|
84 | 83 |
|
85 |
- image2ID, err := buildImage(imageName2, |
|
86 |
- `FROM busybox |
|
87 |
- LABEL match="me too"`, true) |
|
88 |
- c.Assert(err, check.IsNil) |
|
84 |
+ buildImageSuccessfully(c, imageName2, withDockerfile(`FROM busybox |
|
85 |
+ LABEL match="me too"`)) |
|
86 |
+ image2ID := getIDByName(c, imageName2) |
|
89 | 87 |
|
90 |
- image3ID, err := buildImage(imageName3, |
|
91 |
- `FROM busybox |
|
92 |
- LABEL nomatch me`, true) |
|
93 |
- c.Assert(err, check.IsNil) |
|
88 |
+ buildImageSuccessfully(c, imageName3, withDockerfile(`FROM busybox |
|
89 |
+ LABEL nomatch me`)) |
|
90 |
+ image3ID := getIDByName(c, imageName3) |
|
94 | 91 |
|
95 | 92 |
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match") |
96 | 93 |
out = strings.TrimSpace(out) |
... | ... |
@@ -117,15 +112,15 @@ func (s *DockerSuite) TestImagesFilterLabelWithCommit(c *check.C) { |
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) { |
120 |
- imageID1, err := buildImage("image:1", `FROM `+minimalBaseImage()+` |
|
121 |
-LABEL number=1`, true) |
|
122 |
- c.Assert(err, checker.IsNil) |
|
123 |
- imageID2, err := buildImage("image:2", `FROM `+minimalBaseImage()+` |
|
124 |
-LABEL number=2`, true) |
|
125 |
- c.Assert(err, checker.IsNil) |
|
126 |
- imageID3, err := buildImage("image:3", `FROM `+minimalBaseImage()+` |
|
127 |
-LABEL number=3`, true) |
|
128 |
- c.Assert(err, checker.IsNil) |
|
120 |
+ buildImageSuccessfully(c, "image:1", withDockerfile(`FROM `+minimalBaseImage()+` |
|
121 |
+LABEL number=1`)) |
|
122 |
+ imageID1 := getIDByName(c, "image:1") |
|
123 |
+ buildImageSuccessfully(c, "image:2", withDockerfile(`FROM `+minimalBaseImage()+` |
|
124 |
+LABEL number=2`)) |
|
125 |
+ imageID2 := getIDByName(c, "image:2") |
|
126 |
+ buildImageSuccessfully(c, "image:3", withDockerfile(`FROM `+minimalBaseImage()+` |
|
127 |
+LABEL number=3`)) |
|
128 |
+ imageID3 := getIDByName(c, "image:3") |
|
129 | 129 |
|
130 | 130 |
expected := []string{imageID3, imageID2} |
131 | 131 |
|
... | ... |
@@ -185,13 +180,16 @@ func assertImageList(out string, expected []string) bool { |
185 | 185 |
return true |
186 | 186 |
} |
187 | 187 |
|
188 |
+// FIXME(vdemeester) should be a unit test on `docker image ls` |
|
188 | 189 |
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) { |
189 | 190 |
imageName := "images_filter_test" |
190 |
- buildImage(imageName, |
|
191 |
- `FROM busybox |
|
191 |
+ // Build a image and fail to build so that we have dangling images ? |
|
192 |
+ buildImage(imageName, withDockerfile(`FROM busybox |
|
192 | 193 |
RUN touch /test/foo |
193 | 194 |
RUN touch /test/bar |
194 |
- RUN touch /test/baz`, true) |
|
195 |
+ RUN touch /test/baz`)).Assert(c, icmd.Expected{ |
|
196 |
+ ExitCode: 1, |
|
197 |
+ }) |
|
195 | 198 |
|
196 | 199 |
filters := []string{ |
197 | 200 |
"dangling=true", |
... | ... |
@@ -250,6 +248,7 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) { |
250 | 250 |
|
251 | 251 |
} |
252 | 252 |
|
253 |
+// FIXME(vdemeester) should be a unit test for `docker image ls` |
|
253 | 254 |
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) { |
254 | 255 |
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") |
255 | 256 |
c.Assert(err, check.NotNil) |
... | ... |
@@ -261,32 +260,33 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) { |
261 | 261 |
FROM busybox |
262 | 262 |
MAINTAINER docker |
263 | 263 |
ENV foo bar` |
264 |
- |
|
265 |
- head, out, err := buildImageWithOut("scratch-image", dockerfile, false) |
|
266 |
- c.Assert(err, check.IsNil) |
|
264 |
+ name := "scratch-image" |
|
265 |
+ result := buildImage(name, withDockerfile(dockerfile)) |
|
266 |
+ result.Assert(c, icmd.Success) |
|
267 |
+ id := getIDByName(c, name) |
|
267 | 268 |
|
268 | 269 |
// this is just the output of docker build |
269 | 270 |
// we're interested in getting the image id of the MAINTAINER instruction |
270 | 271 |
// and that's located at output, line 5, from 7 to end |
271 |
- split := strings.Split(out, "\n") |
|
272 |
+ split := strings.Split(result.Combined(), "\n") |
|
272 | 273 |
intermediate := strings.TrimSpace(split[5][7:]) |
273 | 274 |
|
274 |
- out, _ = dockerCmd(c, "images") |
|
275 |
+ out, _ := dockerCmd(c, "images") |
|
275 | 276 |
// images shouldn't show non-heads images |
276 | 277 |
c.Assert(out, checker.Not(checker.Contains), intermediate) |
277 | 278 |
// images should contain final built images |
278 |
- c.Assert(out, checker.Contains, stringid.TruncateID(head)) |
|
279 |
+ c.Assert(out, checker.Contains, stringid.TruncateID(id)) |
|
279 | 280 |
} |
280 | 281 |
|
281 | 282 |
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) { |
282 | 283 |
testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch |
283 |
- |
|
284 | 284 |
dockerfile := ` |
285 | 285 |
FROM scratch |
286 | 286 |
MAINTAINER docker` |
287 | 287 |
|
288 |
- id, _, err := buildImageWithOut("scratch-image", dockerfile, false) |
|
289 |
- c.Assert(err, check.IsNil) |
|
288 |
+ name := "scratch-image" |
|
289 |
+ buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
|
290 |
+ id := getIDByName(c, name) |
|
290 | 291 |
|
291 | 292 |
out, _ := dockerCmd(c, "images") |
292 | 293 |
// images should contain images built from scratch |
... | ... |
@@ -299,9 +299,10 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) { |
299 | 299 |
dockerfile := ` |
300 | 300 |
FROM busybox |
301 | 301 |
MAINTAINER docker` |
302 |
+ name := "busybox-image" |
|
302 | 303 |
|
303 |
- id, _, err := buildImageWithOut("busybox-image", dockerfile, false) |
|
304 |
- c.Assert(err, check.IsNil) |
|
304 |
+ buildImageSuccessfully(c, name, withDockerfile(dockerfile)) |
|
305 |
+ id := getIDByName(c, name) |
|
305 | 306 |
|
306 | 307 |
out, _ := dockerCmd(c, "images") |
307 | 308 |
// images should contain images built from busybox |
... | ... |
@@ -130,8 +130,7 @@ func (s *DockerSuite) TestLogsTail(c *check.C) { |
130 | 130 |
|
131 | 131 |
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { |
132 | 132 |
dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") |
133 |
- id, err := getIDByName("test") |
|
134 |
- c.Assert(err, check.IsNil) |
|
133 |
+ id := getIDByName(c, "test") |
|
135 | 134 |
|
136 | 135 |
logsCmd := exec.Command(dockerBinary, "logs", "-f", id) |
137 | 136 |
c.Assert(logsCmd.Start(), checker.IsNil) |
... | ... |
@@ -157,8 +157,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) { |
157 | 157 |
|
158 | 158 |
name := "test_size" |
159 | 159 |
dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") |
160 |
- id, err := getIDByName(name) |
|
161 |
- c.Assert(err, checker.IsNil) |
|
160 |
+ id := getIDByName(c, name) |
|
162 | 161 |
|
163 | 162 |
runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1") |
164 | 163 |
var out string |
... | ... |
@@ -286,8 +285,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) { |
286 | 286 |
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) { |
287 | 287 |
// start container |
288 | 288 |
dockerCmd(c, "run", "--name=a_name_to_match", "busybox") |
289 |
- id, err := getIDByName("a_name_to_match") |
|
290 |
- c.Assert(err, check.IsNil) |
|
289 |
+ id := getIDByName(c, "a_name_to_match") |
|
291 | 290 |
|
292 | 291 |
// start another container |
293 | 292 |
runSleepingContainer(c, "--name=b_name_to_match") |
... | ... |
@@ -309,47 +307,39 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) { |
309 | 309 |
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) { |
310 | 310 |
// Build images |
311 | 311 |
imageName1 := "images_ps_filter_test1" |
312 |
- imageID1, err := buildImage(imageName1, |
|
313 |
- `FROM busybox |
|
314 |
- LABEL match me 1`, true) |
|
315 |
- c.Assert(err, checker.IsNil) |
|
312 |
+ buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox |
|
313 |
+ LABEL match me 1`)) |
|
314 |
+ imageID1 := getIDByName(c, imageName1) |
|
316 | 315 |
|
317 | 316 |
imageName1Tagged := "images_ps_filter_test1:tag" |
318 |
- imageID1Tagged, err := buildImage(imageName1Tagged, |
|
319 |
- `FROM busybox |
|
320 |
- LABEL match me 1 tagged`, true) |
|
321 |
- c.Assert(err, checker.IsNil) |
|
317 |
+ buildImageSuccessfully(c, imageName1Tagged, withDockerfile(`FROM busybox |
|
318 |
+ LABEL match me 1 tagged`)) |
|
319 |
+ imageID1Tagged := getIDByName(c, imageName1Tagged) |
|
322 | 320 |
|
323 | 321 |
imageName2 := "images_ps_filter_test2" |
324 |
- imageID2, err := buildImage(imageName2, |
|
325 |
- fmt.Sprintf(`FROM %s |
|
326 |
- LABEL match me 2`, imageName1), true) |
|
327 |
- c.Assert(err, checker.IsNil) |
|
322 |
+ buildImageSuccessfully(c, imageName2, withDockerfile(fmt.Sprintf(`FROM %s |
|
323 |
+ LABEL match me 2`, imageName1))) |
|
324 |
+ imageID2 := getIDByName(c, imageName2) |
|
328 | 325 |
|
329 | 326 |
// start containers |
330 | 327 |
dockerCmd(c, "run", "--name=first", "busybox", "echo", "hello") |
331 |
- firstID, err := getIDByName("first") |
|
332 |
- c.Assert(err, check.IsNil) |
|
328 |
+ firstID := getIDByName(c, "first") |
|
333 | 329 |
|
334 | 330 |
// start another container |
335 | 331 |
dockerCmd(c, "run", "--name=second", "busybox", "echo", "hello") |
336 |
- secondID, err := getIDByName("second") |
|
337 |
- c.Assert(err, check.IsNil) |
|
332 |
+ secondID := getIDByName(c, "second") |
|
338 | 333 |
|
339 | 334 |
// start third container |
340 | 335 |
dockerCmd(c, "run", "--name=third", imageName1, "echo", "hello") |
341 |
- thirdID, err := getIDByName("third") |
|
342 |
- c.Assert(err, check.IsNil) |
|
336 |
+ thirdID := getIDByName(c, "third") |
|
343 | 337 |
|
344 | 338 |
// start fourth container |
345 | 339 |
dockerCmd(c, "run", "--name=fourth", imageName1Tagged, "echo", "hello") |
346 |
- fourthID, err := getIDByName("fourth") |
|
347 |
- c.Assert(err, check.IsNil) |
|
340 |
+ fourthID := getIDByName(c, "fourth") |
|
348 | 341 |
|
349 | 342 |
// start fifth container |
350 | 343 |
dockerCmd(c, "run", "--name=fifth", imageName2, "echo", "hello") |
351 |
- fifthID, err := getIDByName("fifth") |
|
352 |
- c.Assert(err, check.IsNil) |
|
344 |
+ fifthID := getIDByName(c, "fifth") |
|
353 | 345 |
|
354 | 346 |
var filterTestSuite = []struct { |
355 | 347 |
filterName string |
... | ... |
@@ -410,18 +400,15 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe |
410 | 410 |
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) { |
411 | 411 |
// start container |
412 | 412 |
dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox") |
413 |
- firstID, err := getIDByName("first") |
|
414 |
- c.Assert(err, check.IsNil) |
|
413 |
+ firstID := getIDByName(c, "first") |
|
415 | 414 |
|
416 | 415 |
// start another container |
417 | 416 |
dockerCmd(c, "run", "--name=second", "-l", "match=me too", "busybox") |
418 |
- secondID, err := getIDByName("second") |
|
419 |
- c.Assert(err, check.IsNil) |
|
417 |
+ secondID := getIDByName(c, "second") |
|
420 | 418 |
|
421 | 419 |
// start third container |
422 | 420 |
dockerCmd(c, "run", "--name=third", "-l", "nomatch=me", "busybox") |
423 |
- thirdID, err := getIDByName("third") |
|
424 |
- c.Assert(err, check.IsNil) |
|
421 |
+ thirdID := getIDByName(c, "third") |
|
425 | 422 |
|
426 | 423 |
// filter containers by exact match |
427 | 424 |
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me") |
... | ... |
@@ -450,23 +437,19 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) { |
450 | 450 |
runSleepingContainer(c, "--name=sleep") |
451 | 451 |
|
452 | 452 |
dockerCmd(c, "run", "--name", "zero1", "busybox", "true") |
453 |
- firstZero, err := getIDByName("zero1") |
|
454 |
- c.Assert(err, checker.IsNil) |
|
453 |
+ firstZero := getIDByName(c, "zero1") |
|
455 | 454 |
|
456 | 455 |
dockerCmd(c, "run", "--name", "zero2", "busybox", "true") |
457 |
- secondZero, err := getIDByName("zero2") |
|
458 |
- c.Assert(err, checker.IsNil) |
|
456 |
+ secondZero := getIDByName(c, "zero2") |
|
459 | 457 |
|
460 | 458 |
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false") |
461 | 459 |
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) |
462 | 460 |
|
463 |
- firstNonZero, err := getIDByName("nonzero1") |
|
464 |
- c.Assert(err, checker.IsNil) |
|
461 |
+ firstNonZero := getIDByName(c, "nonzero1") |
|
465 | 462 |
|
466 | 463 |
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false") |
467 | 464 |
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) |
468 |
- secondNonZero, err := getIDByName("nonzero2") |
|
469 |
- c.Assert(err, checker.IsNil) |
|
465 |
+ secondNonZero := getIDByName(c, "nonzero2") |
|
470 | 466 |
|
471 | 467 |
// filter containers by exited=0 |
472 | 468 |
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") |
... | ... |
@@ -671,8 +654,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) { |
671 | 671 |
|
672 | 672 |
icmd.RunCommand(dockerBinary, "tag", "busybox:latest", originalImageName).Assert(c, icmd.Success) |
673 | 673 |
|
674 |
- originalImageID, err := getIDByName(originalImageName) |
|
675 |
- c.Assert(err, checker.IsNil) |
|
674 |
+ originalImageID := getIDByName(c, originalImageName) |
|
676 | 675 |
|
677 | 676 |
result := icmd.RunCommand(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...) |
678 | 677 |
result.Assert(c, icmd.Success) |
... | ... |
@@ -65,14 +65,13 @@ func testConcurrentPullWholeRepo(c *check.C) { |
65 | 65 |
repos := []string{} |
66 | 66 |
for _, tag := range []string{"recent", "fresh", "todays"} { |
67 | 67 |
repo := fmt.Sprintf("%v:%v", repoName, tag) |
68 |
- _, err := buildImage(repo, fmt.Sprintf(` |
|
68 |
+ buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` |
|
69 | 69 |
FROM busybox |
70 | 70 |
ENTRYPOINT ["/bin/echo"] |
71 | 71 |
ENV FOO foo |
72 | 72 |
ENV BAR bar |
73 | 73 |
CMD echo %s |
74 |
- `, repo), true) |
|
75 |
- c.Assert(err, checker.IsNil) |
|
74 |
+ `, repo))) |
|
76 | 75 |
dockerCmd(c, "push", repo) |
77 | 76 |
repos = append(repos, repo) |
78 | 77 |
} |
... | ... |
@@ -154,14 +153,13 @@ func testConcurrentPullMultipleTags(c *check.C) { |
154 | 154 |
repos := []string{} |
155 | 155 |
for _, tag := range []string{"recent", "fresh", "todays"} { |
156 | 156 |
repo := fmt.Sprintf("%v:%v", repoName, tag) |
157 |
- _, err := buildImage(repo, fmt.Sprintf(` |
|
157 |
+ buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` |
|
158 | 158 |
FROM busybox |
159 | 159 |
ENTRYPOINT ["/bin/echo"] |
160 | 160 |
ENV FOO foo |
161 | 161 |
ENV BAR bar |
162 | 162 |
CMD echo %s |
163 |
- `, repo), true) |
|
164 |
- c.Assert(err, checker.IsNil) |
|
163 |
+ `, repo))) |
|
165 | 164 |
dockerCmd(c, "push", repo) |
166 | 165 |
repos = append(repos, repo) |
167 | 166 |
} |
... | ... |
@@ -209,21 +207,15 @@ func testPullIDStability(c *check.C) { |
209 | 209 |
derivedImage := privateRegistryURL + "/dockercli/id-stability" |
210 | 210 |
baseImage := "busybox" |
211 | 211 |
|
212 |
- _, err := buildImage(derivedImage, fmt.Sprintf(` |
|
212 |
+ buildImageSuccessfully(c, derivedImage, withDockerfile(fmt.Sprintf(` |
|
213 | 213 |
FROM %s |
214 | 214 |
ENV derived true |
215 | 215 |
ENV asdf true |
216 | 216 |
RUN dd if=/dev/zero of=/file bs=1024 count=1024 |
217 | 217 |
CMD echo %s |
218 |
- `, baseImage, derivedImage), true) |
|
219 |
- if err != nil { |
|
220 |
- c.Fatal(err) |
|
221 |
- } |
|
218 |
+ `, baseImage, derivedImage))) |
|
222 | 219 |
|
223 |
- originalID, err := getIDByName(derivedImage) |
|
224 |
- if err != nil { |
|
225 |
- c.Fatalf("error inspecting: %v", err) |
|
226 |
- } |
|
220 |
+ originalID := getIDByName(c, derivedImage) |
|
227 | 221 |
dockerCmd(c, "push", derivedImage) |
228 | 222 |
|
229 | 223 |
// Pull |
... | ... |
@@ -232,10 +224,7 @@ func testPullIDStability(c *check.C) { |
232 | 232 |
c.Fatalf("repull redownloaded a layer: %s", out) |
233 | 233 |
} |
234 | 234 |
|
235 |
- derivedIDAfterPull, err := getIDByName(derivedImage) |
|
236 |
- if err != nil { |
|
237 |
- c.Fatalf("error inspecting: %v", err) |
|
238 |
- } |
|
235 |
+ derivedIDAfterPull := getIDByName(c, derivedImage) |
|
239 | 236 |
|
240 | 237 |
if derivedIDAfterPull != originalID { |
241 | 238 |
c.Fatal("image's ID unexpectedly changed after a repush/repull") |
... | ... |
@@ -252,17 +241,11 @@ func testPullIDStability(c *check.C) { |
252 | 252 |
dockerCmd(c, "rmi", derivedImage) |
253 | 253 |
dockerCmd(c, "pull", derivedImage) |
254 | 254 |
|
255 |
- derivedIDAfterPull, err = getIDByName(derivedImage) |
|
256 |
- if err != nil { |
|
257 |
- c.Fatalf("error inspecting: %v", err) |
|
258 |
- } |
|
255 |
+ derivedIDAfterPull = getIDByName(c, derivedImage) |
|
259 | 256 |
|
260 | 257 |
if derivedIDAfterPull != originalID { |
261 | 258 |
c.Fatal("image's ID unexpectedly changed after a repush/repull") |
262 | 259 |
} |
263 |
- if err != nil { |
|
264 |
- c.Fatalf("error inspecting: %v", err) |
|
265 |
- } |
|
266 | 260 |
|
267 | 261 |
// Make sure the image still runs |
268 | 262 |
out, _ = dockerCmd(c, "run", "--rm", derivedImage) |
... | ... |
@@ -283,14 +266,9 @@ func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *check.C) { |
283 | 283 |
func testPullNoLayers(c *check.C) { |
284 | 284 |
repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL) |
285 | 285 |
|
286 |
- _, err := buildImage(repoName, ` |
|
286 |
+ buildImageSuccessfully(c, repoName, withDockerfile(` |
|
287 | 287 |
FROM scratch |
288 |
- ENV foo bar`, |
|
289 |
- true) |
|
290 |
- if err != nil { |
|
291 |
- c.Fatal(err) |
|
292 |
- } |
|
293 |
- |
|
288 |
+ ENV foo bar`)) |
|
294 | 289 |
dockerCmd(c, "push", repoName) |
295 | 290 |
dockerCmd(c, "rmi", repoName) |
296 | 291 |
dockerCmd(c, "pull", repoName) |
... | ... |
@@ -149,11 +149,10 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) { |
149 | 149 |
func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) { |
150 | 150 |
repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, "trusted-pull-delete") |
151 | 151 |
// tag the image and upload it to the private registry |
152 |
- _, err := buildImage(repoName, ` |
|
152 |
+ buildImageSuccessfully(c, repoName, withDockerfile(` |
|
153 | 153 |
FROM busybox |
154 | 154 |
CMD echo trustedpulldelete |
155 |
- `, true) |
|
156 |
- |
|
155 |
+ `)) |
|
157 | 156 |
icmd.RunCmd(icmd.Command(dockerBinary, "push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing) |
158 | 157 |
|
159 | 158 |
dockerCmd(c, "rmi", repoName) |
... | ... |
@@ -176,7 +175,7 @@ func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) { |
176 | 176 |
// rmi of tag should also remove the digest reference |
177 | 177 |
dockerCmd(c, "rmi", repoName) |
178 | 178 |
|
179 |
- _, err = inspectFieldWithError(imageByDigest, "Id") |
|
179 |
+ _, err := inspectFieldWithError(imageByDigest, "Id") |
|
180 | 180 |
c.Assert(err, checker.NotNil, check.Commentf("digest reference should have been removed")) |
181 | 181 |
|
182 | 182 |
_, err = inspectFieldWithError(imageID, "Id") |
... | ... |
@@ -161,14 +161,13 @@ func testConcurrentPush(c *check.C) { |
161 | 161 |
repos := []string{} |
162 | 162 |
for _, tag := range []string{"push1", "push2", "push3"} { |
163 | 163 |
repo := fmt.Sprintf("%v:%v", repoName, tag) |
164 |
- _, err := buildImage(repo, fmt.Sprintf(` |
|
164 |
+ buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(` |
|
165 | 165 |
FROM busybox |
166 | 166 |
ENTRYPOINT ["/bin/echo"] |
167 | 167 |
ENV FOO foo |
168 | 168 |
ENV BAR bar |
169 | 169 |
CMD echo %s |
170 |
-`, repo), true) |
|
171 |
- c.Assert(err, checker.IsNil) |
|
170 |
+`, repo))) |
|
172 | 171 |
repos = append(repos, repo) |
173 | 172 |
} |
174 | 173 |
|
... | ... |
@@ -12,8 +12,7 @@ import ( |
12 | 12 |
|
13 | 13 |
func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { |
14 | 14 |
dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar") |
15 |
- cleanedContainerID, err := getIDByName("test") |
|
16 |
- c.Assert(err, check.IsNil) |
|
15 |
+ cleanedContainerID := getIDByName(c, "test") |
|
17 | 16 |
|
18 | 17 |
out, _ := dockerCmd(c, "logs", cleanedContainerID) |
19 | 18 |
c.Assert(out, checker.Equals, "foobar\n") |
... | ... |
@@ -21,7 +20,7 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { |
21 | 21 |
dockerCmd(c, "restart", cleanedContainerID) |
22 | 22 |
|
23 | 23 |
// Wait until the container has stopped |
24 |
- err = waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second) |
|
24 |
+ err := waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second) |
|
25 | 25 |
c.Assert(err, checker.IsNil) |
26 | 26 |
|
27 | 27 |
out, _ = dockerCmd(c, "logs", cleanedContainerID) |
... | ... |
@@ -58,13 +58,12 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) { |
58 | 58 |
MAINTAINER Integration Tests` |
59 | 59 |
|
60 | 60 |
// build first dockerfile |
61 |
- img1, err := buildImage(img, dockerfile1, true) |
|
62 |
- c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img)) |
|
61 |
+ buildImageSuccessfully(c, img, withDockerfile(dockerfile1)) |
|
62 |
+ img1 := getIDByName(c, img) |
|
63 | 63 |
// run container on first image |
64 | 64 |
dockerCmd(c, "run", img) |
65 | 65 |
// rebuild dockerfile with a small addition at the end |
66 |
- _, err = buildImage(img, dockerfile2, true) |
|
67 |
- c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img)) |
|
66 |
+ buildImageSuccessfully(c, img, withDockerfile(dockerfile2)) |
|
68 | 67 |
// try to remove the image, should not error out. |
69 | 68 |
out, _, err := dockerCmdWithError("rmi", img) |
70 | 69 |
c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out)) |
... | ... |
@@ -147,8 +147,8 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) { |
147 | 147 |
// See https://github.com/docker/docker/issues/14116 |
148 | 148 |
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) { |
149 | 149 |
dockerfile := "FROM busybox\nRUN echo test 14116\n" |
150 |
- imgID, err := buildImage("test-14116", dockerfile, false) |
|
151 |
- c.Assert(err, checker.IsNil) |
|
150 |
+ buildImageSuccessfully(c, "test-14116", withDockerfile(dockerfile)) |
|
151 |
+ imgID := getIDByName(c, "test-14116") |
|
152 | 152 |
|
153 | 153 |
newTag := "newtag" |
154 | 154 |
dockerCmd(c, "tag", imgID, newTag) |
... | ... |
@@ -205,14 +205,8 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) { |
205 | 205 |
tag1 := imageName + ":tag1" |
206 | 206 |
tag2 := imageName + ":tag2" |
207 | 207 |
|
208 |
- _, err := buildImage(tag1, |
|
209 |
- `FROM busybox |
|
210 |
- MAINTAINER "docker"`, |
|
211 |
- true) |
|
212 |
- if err != nil { |
|
213 |
- c.Fatal(err) |
|
214 |
- } |
|
215 |
- |
|
208 |
+ buildImageSuccessfully(c, tag1, withDockerfile(`FROM busybox |
|
209 |
+ MAINTAINER "docker"`)) |
|
216 | 210 |
dockerCmd(c, "tag", tag1, tag2) |
217 | 211 |
|
218 | 212 |
out, _ := dockerCmd(c, "rmi", "-f", tag2) |
... | ... |
@@ -240,8 +234,8 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) { |
240 | 240 |
imageIds := make([]string, 2) |
241 | 241 |
for i, name := range imageNames { |
242 | 242 |
dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name) |
243 |
- id, err := buildImage(name, dockerfile, false) |
|
244 |
- c.Assert(err, checker.IsNil) |
|
243 |
+ buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile)) |
|
244 |
+ id := getIDByName(c, name) |
|
245 | 245 |
imageIds[i] = id |
246 | 246 |
} |
247 | 247 |
|
... | ... |
@@ -269,9 +263,7 @@ RUN echo 0 #layer0 |
269 | 269 |
RUN echo 1 #layer1 |
270 | 270 |
RUN echo 2 #layer2 |
271 | 271 |
` |
272 |
- _, err := buildImage(image, dockerfile, false) |
|
273 |
- c.Assert(err, checker.IsNil) |
|
274 |
- |
|
272 |
+ buildImageSuccessfully(c, image, withoutCache, withDockerfile(dockerfile)) |
|
275 | 273 |
out, _ := dockerCmd(c, "history", "-q", image) |
276 | 274 |
ids := strings.Split(out, "\n") |
277 | 275 |
idToTag := ids[2] |
... | ... |
@@ -294,7 +286,7 @@ RUN echo 2 #layer2 |
294 | 294 |
|
295 | 295 |
// At this point we have 2 containers, one based on layer2 and another based on layer0. |
296 | 296 |
// Try to untag "tmp2" without the -f flag. |
297 |
- out, _, err = dockerCmdWithError("rmi", newTag) |
|
297 |
+ out, _, err := dockerCmdWithError("rmi", newTag) |
|
298 | 298 |
// should not be untagged without the -f flag |
299 | 299 |
c.Assert(err, checker.NotNil) |
300 | 300 |
c.Assert(out, checker.Contains, cid[:12]) |
... | ... |
@@ -307,10 +299,9 @@ RUN echo 2 #layer2 |
307 | 307 |
} |
308 | 308 |
|
309 | 309 |
func (*DockerSuite) TestRmiParentImageFail(c *check.C) { |
310 |
- _, err := buildImage("test", ` |
|
310 |
+ buildImageSuccessfully(c, "test", withDockerfile(` |
|
311 | 311 |
FROM busybox |
312 |
- RUN echo hello`, false) |
|
313 |
- c.Assert(err, checker.IsNil) |
|
312 |
+ RUN echo hello`)) |
|
314 | 313 |
|
315 | 314 |
id := inspectField(c, "busybox", "ID") |
316 | 315 |
out, _, err := dockerCmdWithError("rmi", id) |
... | ... |
@@ -410,10 +410,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) { |
410 | 410 |
containerPath = "/test/test" |
411 | 411 |
cmd = "true" |
412 | 412 |
} |
413 |
- if _, err := buildImage(name, dockerFile, false); err != nil { |
|
414 |
- c.Fatal(err) |
|
415 |
- } |
|
416 |
- |
|
413 |
+ buildImageSuccessfully(c, name, withDockerfile(dockerFile)) |
|
417 | 414 |
dockerCmd(c, "run", "-v", containerPath, name, cmd) |
418 | 415 |
} |
419 | 416 |
|
... | ... |
@@ -438,10 +435,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir2(c *check.C) { |
438 | 438 |
containerPath = "/test/test" |
439 | 439 |
cmd = "true" |
440 | 440 |
} |
441 |
- if _, err := buildImage(name, dockerFile, false); err != nil { |
|
442 |
- c.Fatal(err) |
|
443 |
- } |
|
444 |
- |
|
441 |
+ buildImageSuccessfully(c, name, withDockerfile(dockerFile)) |
|
445 | 442 |
dockerCmd(c, "run", "-v", containerPath, name, cmd) |
446 | 443 |
} |
447 | 444 |
|
... | ... |
@@ -1409,10 +1403,7 @@ func (s *DockerSuite) TestRunNonRootUserResolvName(c *check.C) { |
1409 | 1409 |
|
1410 | 1410 |
dockerCmd(c, "run", "--name=testperm", "--user=nobody", "busybox", "nslookup", "apt.dockerproject.org") |
1411 | 1411 |
|
1412 |
- cID, err := getIDByName("testperm") |
|
1413 |
- if err != nil { |
|
1414 |
- c.Fatal(err) |
|
1415 |
- } |
|
1412 |
+ cID := getIDByName(c, "testperm") |
|
1416 | 1413 |
|
1417 | 1414 |
fmode := (os.FileMode)(0644) |
1418 | 1415 |
finfo, err := os.Stat(containerStorageFile(cID, "resolv.conf")) |
... | ... |
@@ -1462,10 +1453,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1462 | 1462 |
|
1463 | 1463 |
//1. test that a restarting container gets an updated resolv.conf |
1464 | 1464 |
dockerCmd(c, "run", "--name=first", "busybox", "true") |
1465 |
- containerID1, err := getIDByName("first") |
|
1466 |
- if err != nil { |
|
1467 |
- c.Fatal(err) |
|
1468 |
- } |
|
1465 |
+ containerID1 := getIDByName(c, "first") |
|
1469 | 1466 |
|
1470 | 1467 |
// replace resolv.conf with our temporary copy |
1471 | 1468 |
bytesResolvConf := []byte(tmpResolvConf) |
... | ... |
@@ -1492,10 +1480,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1492 | 1492 |
//2. test that a restarting container does not receive resolv.conf updates |
1493 | 1493 |
// if it modified the container copy of the starting point resolv.conf |
1494 | 1494 |
dockerCmd(c, "run", "--name=second", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf") |
1495 |
- containerID2, err := getIDByName("second") |
|
1496 |
- if err != nil { |
|
1497 |
- c.Fatal(err) |
|
1498 |
- } |
|
1495 |
+ containerID2 := getIDByName(c, "second") |
|
1499 | 1496 |
|
1500 | 1497 |
//make a change to resolv.conf (in this case replacing our tmp copy with orig copy) |
1501 | 1498 |
if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { |
... | ... |
@@ -1581,10 +1566,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1581 | 1581 |
|
1582 | 1582 |
// Run the container so it picks up the old settings |
1583 | 1583 |
dockerCmd(c, "run", "--name=third", "busybox", "true") |
1584 |
- containerID3, err := getIDByName("third") |
|
1585 |
- if err != nil { |
|
1586 |
- c.Fatal(err) |
|
1587 |
- } |
|
1584 |
+ containerID3 := getIDByName(c, "third") |
|
1588 | 1585 |
|
1589 | 1586 |
// Create a modified resolv.conf.aside and override resolv.conf with it |
1590 | 1587 |
bytesResolvConf = []byte(tmpResolvConf) |
... | ... |
@@ -1698,15 +1680,10 @@ func (s *DockerSuite) TestRunCopyVolumeUIDGID(c *check.C) { |
1698 | 1698 |
// Not applicable on Windows as it does not support uid or gid in this way |
1699 | 1699 |
testRequires(c, DaemonIsLinux) |
1700 | 1700 |
name := "testrunvolumesuidgid" |
1701 |
- _, err := buildImage(name, |
|
1702 |
- `FROM busybox |
|
1701 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
1703 | 1702 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
1704 | 1703 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
1705 |
- RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`, |
|
1706 |
- true) |
|
1707 |
- if err != nil { |
|
1708 |
- c.Fatal(err) |
|
1709 |
- } |
|
1704 |
+ RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`)) |
|
1710 | 1705 |
|
1711 | 1706 |
// Test that the uid and gid is copied from the image to the volume |
1712 | 1707 |
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) { |
1722 | 1722 |
// that copies from the image to the volume. |
1723 | 1723 |
testRequires(c, DaemonIsLinux) |
1724 | 1724 |
name := "testruncopyvolumecontent" |
1725 |
- _, err := buildImage(name, |
|
1726 |
- `FROM busybox |
|
1727 |
- RUN mkdir -p /hello/local && echo hello > /hello/local/world`, |
|
1728 |
- true) |
|
1729 |
- if err != nil { |
|
1730 |
- c.Fatal(err) |
|
1731 |
- } |
|
1725 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
1726 |
+ RUN mkdir -p /hello/local && echo hello > /hello/local/world`)) |
|
1732 | 1727 |
|
1733 | 1728 |
// Test that the content is copied from the image to the volume |
1734 | 1729 |
out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello") |
... | ... |
@@ -1739,13 +1711,9 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) { |
1739 | 1739 |
|
1740 | 1740 |
func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) { |
1741 | 1741 |
name := "testrunmdcleanuponentrypoint" |
1742 |
- if _, err := buildImage(name, |
|
1743 |
- `FROM busybox |
|
1742 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
1744 | 1743 |
ENTRYPOINT ["echo"] |
1745 |
- CMD ["testingpoint"]`, |
|
1746 |
- true); err != nil { |
|
1747 |
- c.Fatal(err) |
|
1748 |
- } |
|
1744 |
+ CMD ["testingpoint"]`)) |
|
1749 | 1745 |
|
1750 | 1746 |
out, exit := dockerCmd(c, "run", "--entrypoint", "whoami", name) |
1751 | 1747 |
if exit != 0 { |
... | ... |
@@ -1879,9 +1847,7 @@ func testRunWriteSpecialFilesAndNotCommit(c *check.C, name, path string) { |
1879 | 1879 |
func eqToBaseDiff(out string, c *check.C) bool { |
1880 | 1880 |
name := "eqToBaseDiff" + stringutils.GenerateRandomAlphaOnlyString(32) |
1881 | 1881 |
dockerCmd(c, "run", "--name", name, "busybox", "echo", "hello") |
1882 |
- cID, err := getIDByName(name) |
|
1883 |
- c.Assert(err, check.IsNil) |
|
1884 |
- |
|
1882 |
+ cID := getIDByName(c, name) |
|
1885 | 1883 |
baseDiff, _ := dockerCmd(c, "diff", cID) |
1886 | 1884 |
baseArr := strings.Split(baseDiff, "\n") |
1887 | 1885 |
sort.Strings(baseArr) |
... | ... |
@@ -2229,14 +2195,9 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) { |
2229 | 2229 |
// are pre-populated such as is built in the dockerfile used in this test. |
2230 | 2230 |
testRequires(c, DaemonIsLinux) |
2231 | 2231 |
prefix, slash := getPrefixAndSlashFromDaemonPlatform() |
2232 |
- if _, err := buildImage("dataimage", |
|
2233 |
- `FROM busybox |
|
2232 |
+ buildImageSuccessfully(c, "dataimage", withDockerfile(`FROM busybox |
|
2234 | 2233 |
RUN ["mkdir", "-p", "/foo"] |
2235 |
- RUN ["touch", "/foo/bar"]`, |
|
2236 |
- true); err != nil { |
|
2237 |
- c.Fatal(err) |
|
2238 |
- } |
|
2239 |
- |
|
2234 |
+ RUN ["touch", "/foo/bar"]`)) |
|
2240 | 2235 |
dockerCmd(c, "run", "--name", "test", "-v", prefix+slash+"foo", "busybox") |
2241 | 2236 |
|
2242 | 2237 |
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) { |
2265 | 2265 |
func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) { |
2266 | 2266 |
testRequires(c, SameHostDaemon) |
2267 | 2267 |
prefix, slash := getPrefixAndSlashFromDaemonPlatform() |
2268 |
- if _, err := buildImage("run_volumes_clean_paths", |
|
2269 |
- `FROM busybox |
|
2270 |
- VOLUME `+prefix+`/foo/`, |
|
2271 |
- true); err != nil { |
|
2272 |
- c.Fatal(err) |
|
2273 |
- } |
|
2274 |
- |
|
2268 |
+ buildImageSuccessfully(c, "run_volumes_clean_paths", withDockerfile(`FROM busybox |
|
2269 |
+ VOLUME `+prefix+`/foo/`)) |
|
2275 | 2270 |
dockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") |
2276 | 2271 |
|
2277 | 2272 |
out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash) |
... | ... |
@@ -3444,8 +3400,7 @@ func testRunContainerWithCgroupParent(c *check.C, cgroupParent, name string) { |
3444 | 3444 |
if len(cgroupPaths) == 0 { |
3445 | 3445 |
c.Fatalf("unexpected output - %q", string(out)) |
3446 | 3446 |
} |
3447 |
- id, err := getIDByName(name) |
|
3448 |
- c.Assert(err, check.IsNil) |
|
3447 |
+ id := getIDByName(c, name) |
|
3449 | 3448 |
expectedCgroup := path.Join(cgroupParent, id) |
3450 | 3449 |
found := false |
3451 | 3450 |
for _, path := range cgroupPaths { |
... | ... |
@@ -3485,8 +3440,7 @@ func testRunInvalidCgroupParent(c *check.C, cgroupParent, cleanCgroupParent, nam |
3485 | 3485 |
if len(cgroupPaths) == 0 { |
3486 | 3486 |
c.Fatalf("unexpected output - %q", string(out)) |
3487 | 3487 |
} |
3488 |
- id, err := getIDByName(name) |
|
3489 |
- c.Assert(err, check.IsNil) |
|
3488 |
+ id := getIDByName(c, name) |
|
3490 | 3489 |
expectedCgroup := path.Join(cleanCgroupParent, id) |
3491 | 3490 |
found := false |
3492 | 3491 |
for _, path := range cgroupPaths { |
... | ... |
@@ -3919,15 +3873,10 @@ func (s *DockerSuite) TestRunInitLayerPathOwnership(c *check.C) { |
3919 | 3919 |
// Not applicable on Windows as it does not support Linux uid/gid ownership |
3920 | 3920 |
testRequires(c, DaemonIsLinux) |
3921 | 3921 |
name := "testetcfileownership" |
3922 |
- _, err := buildImage(name, |
|
3923 |
- `FROM busybox |
|
3922 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
3924 | 3923 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
3925 | 3924 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
3926 |
- RUN chown dockerio:dockerio /etc`, |
|
3927 |
- true) |
|
3928 |
- if err != nil { |
|
3929 |
- c.Fatal(err) |
|
3930 |
- } |
|
3925 |
+ RUN chown dockerio:dockerio /etc`)) |
|
3931 | 3926 |
|
3932 | 3927 |
// Test that dockerio ownership of /etc is retained at runtime |
3933 | 3928 |
out, _ := dockerCmd(c, "run", "--rm", name, "stat", "-c", "%U:%G", "/etc") |
... | ... |
@@ -4056,11 +4005,10 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) { |
4056 | 4056 |
testRequires(c, DaemonIsLinux) |
4057 | 4057 |
|
4058 | 4058 |
testImg := "testvolumecopy" |
4059 |
- _, err := buildImage(testImg, ` |
|
4059 |
+ buildImageSuccessfully(c, testImg, withDockerfile(` |
|
4060 | 4060 |
FROM busybox |
4061 | 4061 |
RUN mkdir -p /foo && echo hello > /foo/hello |
4062 |
- `, true) |
|
4063 |
- c.Assert(err, check.IsNil) |
|
4062 |
+ `)) |
|
4064 | 4063 |
|
4065 | 4064 |
dockerCmd(c, "run", "-v", "foo:/foo", testImg) |
4066 | 4065 |
out, _ := dockerCmd(c, "run", "-v", "foo:/foo", "busybox", "cat", "/foo/hello") |
... | ... |
@@ -4136,14 +4084,9 @@ func (s *DockerSuite) TestRunVolumeWithOneCharacter(c *check.C) { |
4136 | 4136 |
|
4137 | 4137 |
func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) { |
4138 | 4138 |
testRequires(c, DaemonIsLinux) // Windows does not support copying data from image to the volume |
4139 |
- _, err := buildImage("volumecopy", |
|
4140 |
- `FROM busybox |
|
4139 |
+ buildImageSuccessfully(c, "volumecopy", withDockerfile(`FROM busybox |
|
4141 | 4140 |
RUN mkdir /foo && echo hello > /foo/bar |
4142 |
- CMD cat /foo/bar`, |
|
4143 |
- true, |
|
4144 |
- ) |
|
4145 |
- c.Assert(err, checker.IsNil) |
|
4146 |
- |
|
4141 |
+ CMD cat /foo/bar`)) |
|
4147 | 4142 |
dockerCmd(c, "volume", "create", "test") |
4148 | 4143 |
|
4149 | 4144 |
// test with the nocopy flag |
... | ... |
@@ -4232,22 +4175,20 @@ RUN chmod 755 /entrypoint.sh |
4232 | 4232 |
ENTRYPOINT ["/entrypoint.sh"] |
4233 | 4233 |
CMD echo foobar` |
4234 | 4234 |
|
4235 |
- ctx, err := fakeContext(dockerfile, map[string]string{ |
|
4235 |
+ ctx := fakeContext(c, dockerfile, map[string]string{ |
|
4236 | 4236 |
"entrypoint.sh": `#!/bin/sh |
4237 | 4237 |
echo "I am an entrypoint" |
4238 | 4238 |
exec "$@"`, |
4239 | 4239 |
}) |
4240 |
- c.Assert(err, check.IsNil) |
|
4241 | 4240 |
defer ctx.Close() |
4242 | 4241 |
|
4243 |
- _, err = buildImageFromContext(name, ctx, true) |
|
4244 |
- c.Assert(err, check.IsNil) |
|
4242 |
+ buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
4245 | 4243 |
|
4246 | 4244 |
out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo") |
4247 | 4245 |
c.Assert(strings.TrimSpace(out), check.Equals, "foo") |
4248 | 4246 |
|
4249 | 4247 |
// CMD will be reset as well (the same as setting a custom entrypoint) |
4250 |
- _, _, err = dockerCmdWithError("run", "--entrypoint=", "-t", name) |
|
4248 |
+ _, _, err := dockerCmdWithError("run", "--entrypoint=", "-t", name) |
|
4251 | 4249 |
c.Assert(err, check.NotNil) |
4252 | 4250 |
c.Assert(err.Error(), checker.Contains, "No command specified") |
4253 | 4251 |
} |
... | ... |
@@ -828,17 +828,11 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) { |
828 | 828 |
|
829 | 829 |
func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) { |
830 | 830 |
name := "img-with-volumes" |
831 |
- _, err := buildImage( |
|
832 |
- name, |
|
833 |
- ` |
|
831 |
+ buildImageSuccessfully(c, name, withDockerfile(` |
|
834 | 832 |
FROM busybox |
835 | 833 |
VOLUME /run |
836 | 834 |
RUN touch /run/stuff |
837 |
- `, |
|
838 |
- true) |
|
839 |
- if err != nil { |
|
840 |
- c.Fatal(err) |
|
841 |
- } |
|
835 |
+ `)) |
|
842 | 836 |
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run") |
843 | 837 |
c.Assert(out, checker.Not(checker.Contains), "stuff") |
844 | 838 |
} |
... | ... |
@@ -260,12 +260,9 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) { |
260 | 260 |
os.Mkdir(extractionDirectory, 0777) |
261 | 261 |
|
262 | 262 |
defer os.RemoveAll(tmpDir) |
263 |
- _, err = buildImage(name, |
|
264 |
- `FROM busybox |
|
263 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
265 | 264 |
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a |
266 |
- RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`, |
|
267 |
- true) |
|
268 |
- c.Assert(err, checker.IsNil, check.Commentf("%v", err)) |
|
265 |
+ RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`)) |
|
269 | 266 |
|
270 | 267 |
out, _, err := testutil.RunCommandPipelineWithOutput( |
271 | 268 |
exec.Command(dockerBinary, "save", name), |
... | ... |
@@ -358,9 +355,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) { |
358 | 358 |
|
359 | 359 |
name := "saveloadnotag" |
360 | 360 |
|
361 |
- _, err := buildImage(name, "FROM busybox\nENV foo=bar", true) |
|
362 |
- c.Assert(err, checker.IsNil, check.Commentf("%v", err)) |
|
363 |
- |
|
361 |
+ buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV foo=bar")) |
|
364 | 362 |
id := inspectField(c, name, "Id") |
365 | 363 |
|
366 | 364 |
// Test to make sure that save w/o name just shows imageID during load |
... | ... |
@@ -72,11 +72,9 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { |
72 | 72 |
|
73 | 73 |
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) { |
74 | 74 |
name := "test-load" |
75 |
- _, err := buildImage(name, ` |
|
76 |
- FROM busybox |
|
75 |
+ buildImageSuccessfully(c, name, withDockerfile(`FROM busybox |
|
77 | 76 |
RUN touch aa |
78 |
- `, true) |
|
79 |
- c.Assert(err, check.IsNil) |
|
77 |
+ `)) |
|
80 | 78 |
|
81 | 79 |
tmptar := name + ".tar" |
82 | 80 |
dockerCmd(c, "save", "-o", tmptar, name) |
... | ... |
@@ -142,13 +142,9 @@ func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) { |
142 | 142 |
|
143 | 143 |
// ensure tags cannot create ambiguity with image ids |
144 | 144 |
func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { |
145 |
- imageID, err := buildImage("notbusybox:latest", |
|
146 |
- `FROM busybox |
|
147 |
- MAINTAINER dockerio`, |
|
148 |
- true) |
|
149 |
- if err != nil { |
|
150 |
- c.Fatal(err) |
|
151 |
- } |
|
145 |
+ buildImageSuccessfully(c, "notbusybox:latest", withDockerfile(`FROM busybox |
|
146 |
+ MAINTAINER dockerio`)) |
|
147 |
+ imageID := getIDByName(c, "notbusybox:latest") |
|
152 | 148 |
truncatedImageID := stringid.TruncateID(imageID) |
153 | 149 |
truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID) |
154 | 150 |
|
... | ... |
@@ -159,7 +155,7 @@ func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { |
159 | 159 |
c.Logf("Built image: %s", imageID) |
160 | 160 |
|
161 | 161 |
// test setting tag fails |
162 |
- _, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag) |
|
162 |
+ _, _, err := dockerCmdWithError("tag", "busybox:latest", truncatedTag) |
|
163 | 163 |
if err != nil { |
164 | 164 |
c.Fatalf("Error tagging with an image id: %s", err) |
165 | 165 |
} |
... | ... |
@@ -368,52 +368,41 @@ func (f *FakeContext) Close() error { |
368 | 368 |
return os.RemoveAll(f.Dir) |
369 | 369 |
} |
370 | 370 |
|
371 |
-func fakeContextFromNewTempDir() (*FakeContext, error) { |
|
371 |
+func fakeContextFromNewTempDir(c *check.C) *FakeContext { |
|
372 | 372 |
tmp, err := ioutil.TempDir("", "fake-context") |
373 |
- if err != nil { |
|
374 |
- return nil, err |
|
375 |
- } |
|
373 |
+ c.Assert(err, checker.IsNil) |
|
376 | 374 |
if err := os.Chmod(tmp, 0755); err != nil { |
377 |
- return nil, err |
|
375 |
+ c.Fatal(err) |
|
378 | 376 |
} |
379 |
- return fakeContextFromDir(tmp), nil |
|
377 |
+ return fakeContextFromDir(tmp) |
|
380 | 378 |
} |
381 | 379 |
|
382 | 380 |
func fakeContextFromDir(dir string) *FakeContext { |
383 | 381 |
return &FakeContext{dir} |
384 | 382 |
} |
385 | 383 |
|
386 |
-func fakeContextWithFiles(files map[string]string) (*FakeContext, error) { |
|
387 |
- ctx, err := fakeContextFromNewTempDir() |
|
388 |
- if err != nil { |
|
389 |
- return nil, err |
|
390 |
- } |
|
384 |
+func fakeContextWithFiles(c *check.C, files map[string]string) *FakeContext { |
|
385 |
+ ctx := fakeContextFromNewTempDir(c) |
|
391 | 386 |
for file, content := range files { |
392 | 387 |
if err := ctx.Add(file, content); err != nil { |
393 | 388 |
ctx.Close() |
394 |
- return nil, err |
|
389 |
+ c.Fatal(err) |
|
395 | 390 |
} |
396 | 391 |
} |
397 |
- return ctx, nil |
|
392 |
+ return ctx |
|
398 | 393 |
} |
399 | 394 |
|
400 |
-func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error { |
|
395 |
+func fakeContextAddDockerfile(c *check.C, ctx *FakeContext, dockerfile string) { |
|
401 | 396 |
if err := ctx.Add("Dockerfile", dockerfile); err != nil { |
402 | 397 |
ctx.Close() |
403 |
- return err |
|
398 |
+ c.Fatal(err) |
|
404 | 399 |
} |
405 |
- return nil |
|
406 | 400 |
} |
407 | 401 |
|
408 |
-func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) { |
|
409 |
- ctx, err := fakeContextWithFiles(files) |
|
410 |
- if err != nil { |
|
411 |
- return nil, err |
|
412 |
- } |
|
413 |
- if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil { |
|
414 |
- return nil, err |
|
415 |
- } |
|
416 |
- return ctx, nil |
|
402 |
+func fakeContext(c *check.C, dockerfile string, files map[string]string) *FakeContext { |
|
403 |
+ ctx := fakeContextWithFiles(c, files) |
|
404 |
+ fakeContextAddDockerfile(c, ctx, dockerfile) |
|
405 |
+ return ctx |
|
417 | 406 |
} |
418 | 407 |
|
419 | 408 |
// FakeStorage is a static file server. It might be running locally or remotely |
... | ... |
@@ -424,34 +413,28 @@ type FakeStorage interface { |
424 | 424 |
CtxDir() string |
425 | 425 |
} |
426 | 426 |
|
427 |
-func fakeBinaryStorage(archives map[string]*bytes.Buffer) (FakeStorage, error) { |
|
428 |
- ctx, err := fakeContextFromNewTempDir() |
|
429 |
- if err != nil { |
|
430 |
- return nil, err |
|
431 |
- } |
|
427 |
+func fakeBinaryStorage(c *check.C, archives map[string]*bytes.Buffer) FakeStorage { |
|
428 |
+ ctx := fakeContextFromNewTempDir(c) |
|
432 | 429 |
for name, content := range archives { |
433 | 430 |
if err := ctx.addFile(name, content.Bytes()); err != nil { |
434 |
- return nil, err |
|
431 |
+ c.Fatal(err) |
|
435 | 432 |
} |
436 | 433 |
} |
437 |
- return fakeStorageWithContext(ctx) |
|
434 |
+ return fakeStorageWithContext(c, ctx) |
|
438 | 435 |
} |
439 | 436 |
|
440 | 437 |
// fakeStorage returns either a local or remote (at daemon machine) file server |
441 |
-func fakeStorage(files map[string]string) (FakeStorage, error) { |
|
442 |
- ctx, err := fakeContextWithFiles(files) |
|
443 |
- if err != nil { |
|
444 |
- return nil, err |
|
445 |
- } |
|
446 |
- return fakeStorageWithContext(ctx) |
|
438 |
+func fakeStorage(c *check.C, files map[string]string) FakeStorage { |
|
439 |
+ ctx := fakeContextWithFiles(c, files) |
|
440 |
+ return fakeStorageWithContext(c, ctx) |
|
447 | 441 |
} |
448 | 442 |
|
449 | 443 |
// fakeStorageWithContext returns either a local or remote (at daemon machine) file server |
450 |
-func fakeStorageWithContext(ctx *FakeContext) (FakeStorage, error) { |
|
444 |
+func fakeStorageWithContext(c *check.C, ctx *FakeContext) FakeStorage { |
|
451 | 445 |
if testEnv.LocalDaemon() { |
452 |
- return newLocalFakeStorage(ctx) |
|
446 |
+ return newLocalFakeStorage(c, ctx) |
|
453 | 447 |
} |
454 |
- return newRemoteFileServer(ctx) |
|
448 |
+ return newRemoteFileServer(c, ctx) |
|
455 | 449 |
} |
456 | 450 |
|
457 | 451 |
// localFileStorage is a file storage on the running machine |
... | ... |
@@ -473,13 +456,13 @@ func (s *localFileStorage) Close() error { |
473 | 473 |
return s.FakeContext.Close() |
474 | 474 |
} |
475 | 475 |
|
476 |
-func newLocalFakeStorage(ctx *FakeContext) (*localFileStorage, error) { |
|
476 |
+func newLocalFakeStorage(c *check.C, ctx *FakeContext) *localFileStorage { |
|
477 | 477 |
handler := http.FileServer(http.Dir(ctx.Dir)) |
478 | 478 |
server := httptest.NewServer(handler) |
479 | 479 |
return &localFileStorage{ |
480 | 480 |
FakeContext: ctx, |
481 | 481 |
Server: server, |
482 |
- }, nil |
|
482 |
+ } |
|
483 | 483 |
} |
484 | 484 |
|
485 | 485 |
// remoteFileServer is a containerized static file server started on the remote |
... | ... |
@@ -517,58 +500,45 @@ func (f *remoteFileServer) Close() error { |
517 | 517 |
return deleteContainer(false, f.container) |
518 | 518 |
} |
519 | 519 |
|
520 |
-func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) { |
|
520 |
+func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer { |
|
521 | 521 |
var ( |
522 | 522 |
image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) |
523 | 523 |
container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) |
524 | 524 |
) |
525 | 525 |
|
526 |
- if err := ensureHTTPServerImage(); err != nil { |
|
527 |
- return nil, err |
|
528 |
- } |
|
526 |
+ c.Assert(ensureHTTPServerImage(), checker.IsNil) |
|
529 | 527 |
|
530 | 528 |
// Build the image |
531 |
- if err := fakeContextAddDockerfile(ctx, `FROM httpserver |
|
532 |
-COPY . /static`); err != nil { |
|
533 |
- return nil, fmt.Errorf("Cannot add Dockerfile to context: %v", err) |
|
534 |
- } |
|
535 |
- if _, err := buildImageFromContext(image, ctx, false); err != nil { |
|
536 |
- return nil, fmt.Errorf("failed building file storage container image: %v", err) |
|
537 |
- } |
|
529 |
+ fakeContextAddDockerfile(c, ctx, `FROM httpserver |
|
530 |
+COPY . /static`) |
|
531 |
+ buildImageSuccessfully(c, image, withoutCache, withExternalBuildContext(ctx)) |
|
538 | 532 |
|
539 | 533 |
// Start the container |
540 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--name", container, image) |
|
541 |
- if out, ec, err := runCommandWithOutput(runCmd); err != nil { |
|
542 |
- return nil, fmt.Errorf("failed to start file storage container. ec=%v\nout=%s\nerr=%v", ec, out, err) |
|
543 |
- } |
|
534 |
+ dockerCmd(c, "run", "-d", "-P", "--name", container, image) |
|
544 | 535 |
|
545 | 536 |
// Find out the system assigned port |
546 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "port", container, "80/tcp")) |
|
547 |
- if err != nil { |
|
548 |
- return nil, fmt.Errorf("failed to find container port: err=%v\nout=%s", err, out) |
|
549 |
- } |
|
550 |
- |
|
537 |
+ out, _ := dockerCmd(c, "port", container, "80/tcp") |
|
551 | 538 |
fileserverHostPort := strings.Trim(out, "\n") |
552 | 539 |
_, port, err := net.SplitHostPort(fileserverHostPort) |
553 | 540 |
if err != nil { |
554 |
- return nil, fmt.Errorf("unable to parse file server host:port: %v", err) |
|
541 |
+ c.Fatalf("unable to parse file server host:port: %v", err) |
|
555 | 542 |
} |
556 | 543 |
|
557 | 544 |
dockerHostURL, err := url.Parse(daemonHost()) |
558 | 545 |
if err != nil { |
559 |
- return nil, fmt.Errorf("unable to parse daemon host URL: %v", err) |
|
546 |
+ c.Fatalf("unable to parse daemon host URL: %v", err) |
|
560 | 547 |
} |
561 | 548 |
|
562 | 549 |
host, _, err := net.SplitHostPort(dockerHostURL.Host) |
563 | 550 |
if err != nil { |
564 |
- return nil, fmt.Errorf("unable to parse docker daemon host:port: %v", err) |
|
551 |
+ c.Fatalf("unable to parse docker daemon host:port: %v", err) |
|
565 | 552 |
} |
566 | 553 |
|
567 | 554 |
return &remoteFileServer{ |
568 | 555 |
container: container, |
569 | 556 |
image: image, |
570 | 557 |
host: fmt.Sprintf("%s:%s", host, port), |
571 |
- ctx: ctx}, nil |
|
558 |
+ ctx: ctx} |
|
572 | 559 |
} |
573 | 560 |
|
574 | 561 |
func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) { |
... | ... |
@@ -671,51 +641,17 @@ func inspectImage(name, filter string) (string, error) { |
671 | 671 |
return strings.TrimSpace(out), nil |
672 | 672 |
} |
673 | 673 |
|
674 |
-func getIDByName(name string) (string, error) { |
|
675 |
- return inspectFieldWithError(name, "Id") |
|
676 |
-} |
|
677 |
- |
|
678 |
-// Deprecated |
|
679 |
-func buildImageCmd(name, dockerfile string, useCache bool, buildFlags ...string) *exec.Cmd { |
|
680 |
- return daemon.BuildImageCmdWithHost(dockerBinary, name, dockerfile, "", useCache, buildFlags...) |
|
681 |
-} |
|
682 |
- |
|
683 |
-// Deprecated |
|
684 |
-func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, error) { |
|
685 |
- buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) |
|
686 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
687 |
- if err != nil || exitCode != 0 { |
|
688 |
- return "", out, fmt.Errorf("failed to build the image: %s", out) |
|
689 |
- } |
|
690 |
- id, err := getIDByName(name) |
|
691 |
- if err != nil { |
|
692 |
- return "", out, err |
|
693 |
- } |
|
694 |
- return id, out, nil |
|
695 |
-} |
|
696 |
- |
|
697 |
-// Deprecated |
|
698 |
-func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) { |
|
699 |
- buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) |
|
700 |
- result := icmd.RunCmd(transformCmd(buildCmd)) |
|
701 |
- err := result.Error |
|
702 |
- exitCode := result.ExitCode |
|
703 |
- if err != nil || exitCode != 0 { |
|
704 |
- return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) |
|
705 |
- } |
|
706 |
- id, err := getIDByName(name) |
|
707 |
- if err != nil { |
|
708 |
- return "", result.Stdout(), result.Stderr(), err |
|
709 |
- } |
|
710 |
- return id, result.Stdout(), result.Stderr(), nil |
|
674 |
+func getIDByName(c *check.C, name string) string { |
|
675 |
+ id, err := inspectFieldWithError(name, "Id") |
|
676 |
+ c.Assert(err, checker.IsNil) |
|
677 |
+ return id |
|
711 | 678 |
} |
712 | 679 |
|
713 | 680 |
func buildImageSuccessfully(c *check.C, name string, cmdOperators ...func(*icmd.Cmd) func()) { |
714 |
- buildImageNew(name, cmdOperators...).Assert(c, icmd.Success) |
|
681 |
+ buildImage(name, cmdOperators...).Assert(c, icmd.Success) |
|
715 | 682 |
} |
716 | 683 |
|
717 |
-// FIXME(vdemeester) rename this buildImage once deprecated buildImage is no more |
|
718 |
-func buildImageNew(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result { |
|
684 |
+func buildImage(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result { |
|
719 | 685 |
cmd := icmd.Command(dockerBinary, "build", "-t", name) |
720 | 686 |
for _, op := range cmdOperators { |
721 | 687 |
deferFn := op(&cmd) |
... | ... |
@@ -733,11 +669,16 @@ func withBuildContextPath(path string) func(*icmd.Cmd) func() { |
733 | 733 |
} |
734 | 734 |
} |
735 | 735 |
|
736 |
-func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() { |
|
737 |
- ctx, err := fakeContextFromNewTempDir() |
|
738 |
- if err != nil { |
|
739 |
- c.Fatalf("error creating build context : %v", err) |
|
736 |
+func withExternalBuildContext(ctx *FakeContext) func(*icmd.Cmd) func() { |
|
737 |
+ return func(cmd *icmd.Cmd) func() { |
|
738 |
+ cmd.Dir = ctx.Dir |
|
739 |
+ cmd.Command = append(cmd.Command, ".") |
|
740 |
+ return nil |
|
740 | 741 |
} |
742 |
+} |
|
743 |
+ |
|
744 |
+func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() { |
|
745 |
+ ctx := fakeContextFromNewTempDir(c) |
|
741 | 746 |
for _, op := range contextOperators { |
742 | 747 |
if err := op(ctx); err != nil { |
743 | 748 |
c.Fatal(err) |
... | ... |
@@ -796,108 +737,6 @@ func withEnvironmentVariales(envs ...string) func(cmd *icmd.Cmd) func() { |
796 | 796 |
} |
797 | 797 |
} |
798 | 798 |
|
799 |
-// Deprecated |
|
800 |
-func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) { |
|
801 |
- id, _, err := buildImageWithOut(name, dockerfile, useCache, buildFlags...) |
|
802 |
- return id, err |
|
803 |
-} |
|
804 |
- |
|
805 |
-// Deprecated |
|
806 |
-func buildImageFromContext(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, error) { |
|
807 |
- id, _, err := buildImageFromContextWithOut(name, ctx, useCache, buildFlags...) |
|
808 |
- if err != nil { |
|
809 |
- return "", err |
|
810 |
- } |
|
811 |
- return id, nil |
|
812 |
-} |
|
813 |
- |
|
814 |
-// Deprecated |
|
815 |
-func buildImageFromContextWithOut(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, error) { |
|
816 |
- args := []string{"build", "-t", name} |
|
817 |
- if !useCache { |
|
818 |
- args = append(args, "--no-cache") |
|
819 |
- } |
|
820 |
- args = append(args, buildFlags...) |
|
821 |
- args = append(args, ".") |
|
822 |
- result := icmd.RunCmd(icmd.Cmd{ |
|
823 |
- Command: append([]string{dockerBinary}, args...), |
|
824 |
- Dir: ctx.Dir, |
|
825 |
- }) |
|
826 |
- out := result.Combined() |
|
827 |
- if result.Error != nil || result.ExitCode != 0 { |
|
828 |
- return "", "", fmt.Errorf("failed to build the image: %s", out) |
|
829 |
- } |
|
830 |
- id, err := getIDByName(name) |
|
831 |
- if err != nil { |
|
832 |
- return "", "", err |
|
833 |
- } |
|
834 |
- return id, out, nil |
|
835 |
-} |
|
836 |
- |
|
837 |
-// Deprecated |
|
838 |
-func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, string, error) { |
|
839 |
- args := []string{"build", "-t", name} |
|
840 |
- if !useCache { |
|
841 |
- args = append(args, "--no-cache") |
|
842 |
- } |
|
843 |
- args = append(args, buildFlags...) |
|
844 |
- args = append(args, ".") |
|
845 |
- |
|
846 |
- result := icmd.RunCmd(icmd.Cmd{ |
|
847 |
- Command: append([]string{dockerBinary}, args...), |
|
848 |
- Dir: ctx.Dir, |
|
849 |
- }) |
|
850 |
- exitCode := result.ExitCode |
|
851 |
- err := result.Error |
|
852 |
- if err != nil || exitCode != 0 { |
|
853 |
- return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) |
|
854 |
- } |
|
855 |
- id, err := getIDByName(name) |
|
856 |
- if err != nil { |
|
857 |
- return "", result.Stdout(), result.Stderr(), err |
|
858 |
- } |
|
859 |
- return id, result.Stdout(), result.Stderr(), nil |
|
860 |
-} |
|
861 |
- |
|
862 |
-// Deprecated |
|
863 |
-func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) { |
|
864 |
- args := []string{"build", "-t", name} |
|
865 |
- if !useCache { |
|
866 |
- args = append(args, "--no-cache") |
|
867 |
- } |
|
868 |
- args = append(args, buildFlags...) |
|
869 |
- args = append(args, ctx.RepoURL) |
|
870 |
- result := icmd.RunCmd(icmd.Cmd{ |
|
871 |
- Command: append([]string{dockerBinary}, args...), |
|
872 |
- }) |
|
873 |
- exitCode := result.ExitCode |
|
874 |
- err := result.Error |
|
875 |
- if err != nil || exitCode != 0 { |
|
876 |
- return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined()) |
|
877 |
- } |
|
878 |
- id, err := getIDByName(name) |
|
879 |
- if err != nil { |
|
880 |
- return "", result.Stdout(), result.Stderr(), err |
|
881 |
- } |
|
882 |
- return id, result.Stdout(), result.Stderr(), nil |
|
883 |
-} |
|
884 |
- |
|
885 |
-// Deprecated |
|
886 |
-func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) { |
|
887 |
- args := []string{"build", "-t", name} |
|
888 |
- if !useCache { |
|
889 |
- args = append(args, "--no-cache") |
|
890 |
- } |
|
891 |
- args = append(args, buildFlags...) |
|
892 |
- args = append(args, path) |
|
893 |
- buildCmd := exec.Command(dockerBinary, args...) |
|
894 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
895 |
- if err != nil || exitCode != 0 { |
|
896 |
- return "", fmt.Errorf("failed to build the image: %s", out) |
|
897 |
- } |
|
898 |
- return getIDByName(name) |
|
899 |
-} |
|
900 |
- |
|
901 | 799 |
type gitServer interface { |
902 | 800 |
URL() string |
903 | 801 |
Close() error |
... | ... |
@@ -927,69 +766,63 @@ func (g *fakeGit) Close() { |
927 | 927 |
os.RemoveAll(g.root) |
928 | 928 |
} |
929 | 929 |
|
930 |
-func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (*fakeGit, error) { |
|
931 |
- ctx, err := fakeContextWithFiles(files) |
|
932 |
- if err != nil { |
|
933 |
- return nil, err |
|
934 |
- } |
|
930 |
+func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalServer bool) *fakeGit { |
|
931 |
+ ctx := fakeContextWithFiles(c, files) |
|
935 | 932 |
defer ctx.Close() |
936 | 933 |
curdir, err := os.Getwd() |
937 | 934 |
if err != nil { |
938 |
- return nil, err |
|
935 |
+ c.Fatal(err) |
|
939 | 936 |
} |
940 | 937 |
defer os.Chdir(curdir) |
941 | 938 |
|
942 | 939 |
if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil { |
943 |
- return nil, fmt.Errorf("error trying to init repo: %s (%s)", err, output) |
|
940 |
+ c.Fatalf("error trying to init repo: %s (%s)", err, output) |
|
944 | 941 |
} |
945 | 942 |
err = os.Chdir(ctx.Dir) |
946 | 943 |
if err != nil { |
947 |
- return nil, err |
|
944 |
+ c.Fatal(err) |
|
948 | 945 |
} |
949 | 946 |
if output, err := exec.Command("git", "config", "user.name", "Fake User").CombinedOutput(); err != nil { |
950 |
- return nil, fmt.Errorf("error trying to set 'user.name': %s (%s)", err, output) |
|
947 |
+ c.Fatalf("error trying to set 'user.name': %s (%s)", err, output) |
|
951 | 948 |
} |
952 | 949 |
if output, err := exec.Command("git", "config", "user.email", "fake.user@example.com").CombinedOutput(); err != nil { |
953 |
- return nil, fmt.Errorf("error trying to set 'user.email': %s (%s)", err, output) |
|
950 |
+ c.Fatalf("error trying to set 'user.email': %s (%s)", err, output) |
|
954 | 951 |
} |
955 | 952 |
if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil { |
956 |
- return nil, fmt.Errorf("error trying to add files to repo: %s (%s)", err, output) |
|
953 |
+ c.Fatalf("error trying to add files to repo: %s (%s)", err, output) |
|
957 | 954 |
} |
958 | 955 |
if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil { |
959 |
- return nil, fmt.Errorf("error trying to commit to repo: %s (%s)", err, output) |
|
956 |
+ c.Fatalf("error trying to commit to repo: %s (%s)", err, output) |
|
960 | 957 |
} |
961 | 958 |
|
962 | 959 |
root, err := ioutil.TempDir("", "docker-test-git-repo") |
963 | 960 |
if err != nil { |
964 |
- return nil, err |
|
961 |
+ c.Fatal(err) |
|
965 | 962 |
} |
966 | 963 |
repoPath := filepath.Join(root, name+".git") |
967 | 964 |
if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil { |
968 | 965 |
os.RemoveAll(root) |
969 |
- return nil, fmt.Errorf("error trying to clone --bare: %s (%s)", err, output) |
|
966 |
+ c.Fatalf("error trying to clone --bare: %s (%s)", err, output) |
|
970 | 967 |
} |
971 | 968 |
err = os.Chdir(repoPath) |
972 | 969 |
if err != nil { |
973 | 970 |
os.RemoveAll(root) |
974 |
- return nil, err |
|
971 |
+ c.Fatal(err) |
|
975 | 972 |
} |
976 | 973 |
if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil { |
977 | 974 |
os.RemoveAll(root) |
978 |
- return nil, fmt.Errorf("error trying to git update-server-info: %s (%s)", err, output) |
|
975 |
+ c.Fatalf("error trying to git update-server-info: %s (%s)", err, output) |
|
979 | 976 |
} |
980 | 977 |
err = os.Chdir(curdir) |
981 | 978 |
if err != nil { |
982 | 979 |
os.RemoveAll(root) |
983 |
- return nil, err |
|
980 |
+ c.Fatal(err) |
|
984 | 981 |
} |
985 | 982 |
|
986 | 983 |
var server gitServer |
987 | 984 |
if !enforceLocalServer { |
988 | 985 |
// use fakeStorage server, which might be local or remote (at test daemon) |
989 |
- server, err = fakeStorageWithContext(fakeContextFromDir(root)) |
|
990 |
- if err != nil { |
|
991 |
- return nil, fmt.Errorf("cannot start fake storage: %v", err) |
|
992 |
- } |
|
986 |
+ server = fakeStorageWithContext(c, fakeContextFromDir(root)) |
|
993 | 987 |
} else { |
994 | 988 |
// always start a local http server on CLI test machine |
995 | 989 |
httpServer := httptest.NewServer(http.FileServer(http.Dir(root))) |
... | ... |
@@ -999,7 +832,7 @@ func newFakeGit(name string, files map[string]string, enforceLocalServer bool) ( |
999 | 999 |
root: root, |
1000 | 1000 |
server: server, |
1001 | 1001 |
RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name), |
1002 |
- }, nil |
|
1002 |
+ } |
|
1003 | 1003 |
} |
1004 | 1004 |
|
1005 | 1005 |
// Write `content` to the file at path `dst`, creating it if necessary, |