The `makefile()` utility was used to create a temporary Dockerfile, and after
tests completed, this file was deleted.
However, the _build_ used the current path (`/usr/local/bin/docker`) as
build-context. As a result, roughtly 20 MB was sent as build-context for each
build, but none of the builds actually required a build-context.
This patch;
- creates a temp-dir for the test, which can be used as build-context
- changes the `makefile()` utility and removes the `cleanup` functionality
- instead, the `temp-dir` is removed after the test finishes (which also removes the temporary `Dockerfile`)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -2,7 +2,9 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
+ "io/ioutil" |
|
| 5 | 6 |
"net/http" |
| 7 |
+ "os" |
|
| 6 | 8 |
"regexp" |
| 7 | 9 |
|
| 8 | 10 |
"github.com/docker/docker/integration-cli/registry" |
| ... | ... |
@@ -100,10 +102,14 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
| 100 | 100 |
"--insecure-registry", pushReg.URL(), |
| 101 | 101 |
"--insecure-registry", loginReg.URL()) |
| 102 | 102 |
|
| 103 |
- dockerfileName, cleanup1, err := makefile(fmt.Sprintf("FROM %s", buildRepoName))
|
|
| 103 |
+ tmp, err := ioutil.TempDir("", "integration-cli-")
|
|
| 104 |
+ c.Assert(err, check.IsNil) |
|
| 105 |
+ defer os.RemoveAll(tmp) |
|
| 106 |
+ |
|
| 107 |
+ dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s", buildRepoName))
|
|
| 104 | 108 |
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
| 105 |
- defer cleanup1() |
|
| 106 |
- s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 109 |
+ |
|
| 110 |
+ s.d.Cmd("build", "--file", dockerfileName, tmp)
|
|
| 107 | 111 |
regexpCheckUA(c, buildUA) |
| 108 | 112 |
|
| 109 | 113 |
s.d.Cmd("login", "-u", "richard", "-p", "testtest", loginReg.URL())
|
| ... | ... |
@@ -112,10 +118,9 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
| 112 | 112 |
s.d.Cmd("pull", pullRepoName)
|
| 113 | 113 |
regexpCheckUA(c, pullUA) |
| 114 | 114 |
|
| 115 |
- dockerfileName, cleanup2, err := makefile(`FROM scratch |
|
| 115 |
+ dockerfileName, err = makefile(tmp, `FROM scratch |
|
| 116 | 116 |
ENV foo bar`) |
| 117 | 117 |
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
| 118 |
- defer cleanup2() |
|
| 119 | 118 |
s.d.Cmd("build", "-t", pushRepoName, "--file", dockerfileName, ".")
|
| 120 | 119 |
|
| 121 | 120 |
s.d.Cmd("push", pushRepoName)
|
| ... | ... |
@@ -10,28 +10,16 @@ import ( |
| 10 | 10 |
"github.com/go-check/check" |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 |
-func makefile(contents string) (string, func(), error) {
|
|
| 14 |
- cleanup := func() {
|
|
| 15 |
- |
|
| 16 |
- } |
|
| 17 |
- |
|
| 18 |
- f, err := ioutil.TempFile(".", "tmp")
|
|
| 13 |
+func makefile(path string, contents string) (string, error) {
|
|
| 14 |
+ f, err := ioutil.TempFile(path, "tmp") |
|
| 19 | 15 |
if err != nil {
|
| 20 |
- return "", cleanup, err |
|
| 16 |
+ return "", err |
|
| 21 | 17 |
} |
| 22 | 18 |
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm) |
| 23 | 19 |
if err != nil {
|
| 24 |
- return "", cleanup, err |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- cleanup = func() {
|
|
| 28 |
- err := os.Remove(f.Name()) |
|
| 29 |
- if err != nil {
|
|
| 30 |
- fmt.Println("Error removing tmpfile")
|
|
| 31 |
- } |
|
| 20 |
+ return "", err |
|
| 32 | 21 |
} |
| 33 |
- return f.Name(), cleanup, nil |
|
| 34 |
- |
|
| 22 |
+ return f.Name(), nil |
|
| 35 | 23 |
} |
| 36 | 24 |
|
| 37 | 25 |
// TestV2Only ensures that a daemon by default does not |
| ... | ... |
@@ -53,11 +41,14 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
| 53 | 53 |
|
| 54 | 54 |
s.d.Start(c, "--insecure-registry", reg.URL()) |
| 55 | 55 |
|
| 56 |
- dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
|
| 56 |
+ tmp, err := ioutil.TempDir("", "integration-cli-")
|
|
| 57 |
+ c.Assert(err, check.IsNil) |
|
| 58 |
+ defer os.RemoveAll(tmp) |
|
| 59 |
+ |
|
| 60 |
+ dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
|
| 57 | 61 |
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
| 58 |
- defer cleanup() |
|
| 59 | 62 |
|
| 60 |
- s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 63 |
+ s.d.Cmd("build", "--file", dockerfileName, tmp)
|
|
| 61 | 64 |
|
| 62 | 65 |
s.d.Cmd("run", repoName)
|
| 63 | 66 |
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
| ... | ... |
@@ -102,11 +93,14 @@ func (s *DockerRegistrySuite) TestV1(c *check.C) {
|
| 102 | 102 |
|
| 103 | 103 |
s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=false") |
| 104 | 104 |
|
| 105 |
- dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
|
| 105 |
+ tmp, err := ioutil.TempDir("", "integration-cli-")
|
|
| 106 |
+ c.Assert(err, check.IsNil) |
|
| 107 |
+ defer os.RemoveAll(tmp) |
|
| 108 |
+ |
|
| 109 |
+ dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
|
| 106 | 110 |
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
| 107 |
- defer cleanup() |
|
| 108 | 111 |
|
| 109 |
- s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
| 112 |
+ s.d.Cmd("build", "--file", dockerfileName, tmp)
|
|
| 110 | 113 |
c.Assert(v1Repo, check.Equals, 1, check.Commentf("Expected v1 repository access after build"))
|
| 111 | 114 |
|
| 112 | 115 |
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|