mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use tempdir instead of working directory as build-context
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>
This commit is contained in:
parent
dd790d0e37
commit
ebe66b1d0f
2 changed files with 29 additions and 30 deletions
|
@ -2,7 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/docker/docker/integration-cli/registry"
|
||||
|
@ -100,10 +102,14 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
|||
"--insecure-registry", pushReg.URL(),
|
||||
"--insecure-registry", loginReg.URL())
|
||||
|
||||
dockerfileName, cleanup1, err := makefile(fmt.Sprintf("FROM %s", buildRepoName))
|
||||
tmp, err := ioutil.TempDir("", "integration-cli-")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s", buildRepoName))
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
defer cleanup1()
|
||||
s.d.Cmd("build", "--file", dockerfileName, ".")
|
||||
|
||||
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
||||
regexpCheckUA(c, buildUA)
|
||||
|
||||
s.d.Cmd("login", "-u", "richard", "-p", "testtest", loginReg.URL())
|
||||
|
@ -112,10 +118,9 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
|||
s.d.Cmd("pull", pullRepoName)
|
||||
regexpCheckUA(c, pullUA)
|
||||
|
||||
dockerfileName, cleanup2, err := makefile(`FROM scratch
|
||||
dockerfileName, err = makefile(tmp, `FROM scratch
|
||||
ENV foo bar`)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
defer cleanup2()
|
||||
s.d.Cmd("build", "-t", pushRepoName, "--file", dockerfileName, ".")
|
||||
|
||||
s.d.Cmd("push", pushRepoName)
|
||||
|
|
|
@ -10,28 +10,16 @@ import (
|
|||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func makefile(contents string) (string, func(), error) {
|
||||
cleanup := func() {
|
||||
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile(".", "tmp")
|
||||
func makefile(path string, contents string) (string, error) {
|
||||
f, err := ioutil.TempFile(path, "tmp")
|
||||
if err != nil {
|
||||
return "", cleanup, err
|
||||
return "", err
|
||||
}
|
||||
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
|
||||
if err != nil {
|
||||
return "", cleanup, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
cleanup = func() {
|
||||
err := os.Remove(f.Name())
|
||||
if err != nil {
|
||||
fmt.Println("Error removing tmpfile")
|
||||
}
|
||||
}
|
||||
return f.Name(), cleanup, nil
|
||||
|
||||
return f.Name(), nil
|
||||
}
|
||||
|
||||
// TestV2Only ensures that a daemon by default does not
|
||||
|
@ -53,11 +41,14 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
|||
|
||||
s.d.Start(c, "--insecure-registry", reg.URL())
|
||||
|
||||
dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
defer cleanup()
|
||||
tmp, err := ioutil.TempDir("", "integration-cli-")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
s.d.Cmd("build", "--file", dockerfileName, ".")
|
||||
dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
|
||||
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
||||
|
||||
s.d.Cmd("run", repoName)
|
||||
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
||||
|
@ -102,11 +93,14 @@ func (s *DockerRegistrySuite) TestV1(c *check.C) {
|
|||
|
||||
s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=false")
|
||||
|
||||
dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
defer cleanup()
|
||||
tmp, err := ioutil.TempDir("", "integration-cli-")
|
||||
c.Assert(err, check.IsNil)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
s.d.Cmd("build", "--file", dockerfileName, ".")
|
||||
dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
||||
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
||||
|
||||
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
||||
c.Assert(v1Repo, check.Equals, 1, check.Commentf("Expected v1 repository access after build"))
|
||||
|
||||
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
||||
|
|
Loading…
Reference in a new issue