Clean more build utils in integration cli
- 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>
This commit is contained in:
parent
8c7651998f
commit
c10f6ef43f
28 changed files with 587 additions and 1194 deletions
|
@ -791,6 +791,7 @@ func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time
|
|||
}
|
||||
|
||||
// BuildImageCmdWithHost create a build command with the specified arguments.
|
||||
// Deprecated
|
||||
// FIXME(vdemeester) move this away
|
||||
func BuildImageCmdWithHost(dockerBinary, name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd {
|
||||
args := []string{}
|
||||
|
|
|
@ -28,8 +28,7 @@ COPY * /tmp/
|
|||
RUN find / -xdev -name ba*
|
||||
RUN find /tmp/`
|
||||
}
|
||||
server, err := fakeStorage(map[string]string{"testD": testD})
|
||||
c.Assert(err, checker.IsNil)
|
||||
server := fakeStorage(c, map[string]string{"testD": testD})
|
||||
defer server.Close()
|
||||
|
||||
res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json", daemonHost())
|
||||
|
@ -66,11 +65,9 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
|||
// failed to close tar archive
|
||||
c.Assert(tw.Close(), checker.IsNil)
|
||||
|
||||
server, err := fakeBinaryStorage(map[string]*bytes.Buffer{
|
||||
server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
||||
"testT.tar": buffer,
|
||||
})
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
defer server.Close()
|
||||
|
||||
res, b, err := request.SockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar", daemonHost())
|
||||
|
@ -115,12 +112,11 @@ RUN echo 'right'
|
|||
// failed to close tar archive
|
||||
c.Assert(tw.Close(), checker.IsNil)
|
||||
|
||||
server, err := fakeBinaryStorage(map[string]*bytes.Buffer{
|
||||
server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
||||
"testT.tar": buffer,
|
||||
})
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
defer server.Close()
|
||||
|
||||
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
||||
res, body, err := request.SockRequestRaw("POST", url, nil, "application/tar", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
@ -135,11 +131,10 @@ RUN echo 'right'
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) {
|
||||
git, err := newFakeGit("repo", map[string]string{
|
||||
git := newFakeGit(c, "repo", map[string]string{
|
||||
"dockerfile": `FROM busybox
|
||||
RUN echo from dockerfile`,
|
||||
}, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer git.Close()
|
||||
|
||||
res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost())
|
||||
|
@ -154,13 +149,12 @@ RUN echo from dockerfile`,
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) {
|
||||
git, err := newFakeGit("repo", map[string]string{
|
||||
git := newFakeGit(c, "repo", map[string]string{
|
||||
"baz": `FROM busybox
|
||||
RUN echo from baz`,
|
||||
"Dockerfile": `FROM busybox
|
||||
RUN echo from Dockerfile`,
|
||||
}, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer git.Close()
|
||||
|
||||
// Make sure it tries to 'dockerfile' query param value
|
||||
|
@ -177,13 +171,12 @@ RUN echo from Dockerfile`,
|
|||
|
||||
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) {
|
||||
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
|
||||
git, err := newFakeGit("repo", map[string]string{
|
||||
git := newFakeGit(c, "repo", map[string]string{
|
||||
"Dockerfile": `FROM busybox
|
||||
RUN echo from Dockerfile`,
|
||||
"dockerfile": `FROM busybox
|
||||
RUN echo from dockerfile`,
|
||||
}, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer git.Close()
|
||||
|
||||
// Make sure it tries to 'dockerfile' query param value
|
||||
|
|
|
@ -1766,19 +1766,18 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
|||
destPath := prefix + slash + "foo"
|
||||
|
||||
var (
|
||||
err error
|
||||
testImg string
|
||||
)
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
testImg, err = buildImage("test-mount-config", `
|
||||
testImg = "test-mount-config"
|
||||
buildImageSuccessfully(c, testImg, withDockerfile(`
|
||||
FROM busybox
|
||||
RUN mkdir `+destPath+` && touch `+destPath+slash+`bar
|
||||
CMD cat `+destPath+slash+`bar
|
||||
`, true)
|
||||
`))
|
||||
} else {
|
||||
testImg = "busybox"
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
type testCase struct {
|
||||
cfg mounttypes.Mount
|
||||
|
|
|
@ -52,9 +52,8 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
|||
// TODO Windows to Windows CI: Investigate further why this test fails.
|
||||
testRequires(c, Network)
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, err := buildImage("saveandload", "FROM busybox\nENV FOO bar", false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
id := strings.TrimSpace(out)
|
||||
buildImageSuccessfully(c, "saveandload", withDockerfile("FROM busybox\nENV FOO bar"))
|
||||
id := getIDByName(c, "saveandload")
|
||||
|
||||
res, body, err := request.SockRequestRaw("GET", "/images/"+id+"/get", nil, "", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
@ -77,9 +76,8 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
|||
testRequires(c, Network)
|
||||
}
|
||||
name := "test-api-images-delete"
|
||||
out, err := buildImage(name, "FROM busybox\nENV FOO bar", false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
id := strings.TrimSpace(out)
|
||||
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar"))
|
||||
id := getIDByName(c, name)
|
||||
|
||||
dockerCmd(c, "tag", name, "test:tag1")
|
||||
|
||||
|
@ -101,10 +99,8 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
|||
testRequires(c, Network)
|
||||
}
|
||||
name := "test-api-images-history"
|
||||
out, err := buildImage(name, "FROM busybox\nENV FOO bar", false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV FOO bar"))
|
||||
id := getIDByName(c, name)
|
||||
|
||||
status, body, err := request.SockRequest("GET", "/images/"+id+"/history", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,13 +25,11 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|||
testRequires(c, cpuCfsQuota)
|
||||
name := "testbuildresourceconstraints"
|
||||
|
||||
ctx, err := fakeContext(`
|
||||
ctx := fakeContext(c, `
|
||||
FROM hello-world:frozen
|
||||
RUN ["/hello"]
|
||||
`, map[string]string{})
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
_, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".")
|
||||
_, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
@ -114,9 +112,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
|
|||
|
||||
defer ctx.Close()
|
||||
|
||||
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||
c.Fatalf("build failed to complete for TestBuildAddChangeOwnership: %v", err)
|
||||
}
|
||||
buildImageSuccessfully(c, name, withExternalBuildContext(ctx))
|
||||
}
|
||||
|
||||
// Test that an infinite sleep during a build is killed if the client disconnects.
|
||||
|
@ -137,10 +133,7 @@ func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) {
|
|||
defer observer.Stop()
|
||||
|
||||
// (Note: one year, will never finish)
|
||||
ctx, err := fakeContext("FROM busybox\nRUN sleep 31536000", nil)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
ctx := fakeContext(c, "FROM busybox\nRUN sleep 31536000", nil)
|
||||
defer ctx.Close()
|
||||
|
||||
buildCmd := exec.Command(dockerBinary, "build", "-t", name, ".")
|
||||
|
|
|
@ -193,10 +193,9 @@ func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) {
|
|||
|
||||
// do the build
|
||||
name := "buildbydigest"
|
||||
_, err = buildImage(name, fmt.Sprintf(
|
||||
buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(
|
||||
`FROM %s
|
||||
CMD ["/bin/echo", "Hello World"]`, imageReference),
|
||||
true)
|
||||
CMD ["/bin/echo", "Hello World"]`, imageReference)))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// get the build's image id
|
||||
|
@ -417,20 +416,17 @@ func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c
|
|||
|
||||
// build an image from it
|
||||
imageName1 := "images_ps_filter_test"
|
||||
_, err = buildImage(imageName1, fmt.Sprintf(
|
||||
buildImageSuccessfully(c, imageName1, withDockerfile(fmt.Sprintf(
|
||||
`FROM %s
|
||||
LABEL match me 1`, imageReference), true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
LABEL match me 1`, imageReference)))
|
||||
|
||||
// run a container based on that
|
||||
dockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello")
|
||||
expectedID, err := getIDByName("test1")
|
||||
c.Assert(err, check.IsNil)
|
||||
expectedID := getIDByName(c, "test1")
|
||||
|
||||
// run a container based on the a descendant of that too
|
||||
dockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello")
|
||||
expectedID1, err := getIDByName("test2")
|
||||
c.Assert(err, check.IsNil)
|
||||
expectedID1 := getIDByName(c, "test2")
|
||||
|
||||
expectedIDs := []string{expectedID, expectedID1}
|
||||
|
||||
|
|
|
@ -204,12 +204,8 @@ func (s *DockerSuite) TestCreateLabels(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) {
|
||||
imageName := "testcreatebuildlabel"
|
||||
_, err := buildImage(imageName,
|
||||
`FROM busybox
|
||||
LABEL k1=v1 k2=v2`,
|
||||
true)
|
||||
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox
|
||||
LABEL k1=v1 k2=v2`))
|
||||
|
||||
name := "test_create_labels_from_image"
|
||||
expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"}
|
||||
|
@ -263,13 +259,9 @@ func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestCreateByImageID(c *check.C) {
|
||||
imageName := "testcreatebyimageid"
|
||||
imageID, err := buildImage(imageName,
|
||||
`FROM busybox
|
||||
MAINTAINER dockerio`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio`))
|
||||
imageID := getIDByName(c, imageName)
|
||||
truncatedImageID := stringid.TruncateID(imageID)
|
||||
|
||||
dockerCmd(c, "create", imageID)
|
||||
|
@ -444,16 +436,14 @@ RUN chmod 755 /entrypoint.sh
|
|||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD echo foobar`
|
||||
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||
ctx := fakeContext(c, dockerfile, map[string]string{
|
||||
"entrypoint.sh": `#!/bin/sh
|
||||
echo "I am an entrypoint"
|
||||
exec "$@"`,
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
defer ctx.Close()
|
||||
|
||||
_, err = buildImageFromContext(name, ctx, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, name, withExternalBuildContext(ctx))
|
||||
|
||||
out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo")
|
||||
id := strings.TrimSpace(out)
|
||||
|
|
|
@ -379,11 +379,9 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
|
|||
label := "io.docker.testing=image"
|
||||
|
||||
// Build a test image.
|
||||
_, err := buildImage(name, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(`
|
||||
FROM busybox:latest
|
||||
LABEL %s`, label), true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
|
||||
|
||||
LABEL %s`, label)))
|
||||
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
||||
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
||||
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
||||
|
@ -462,10 +460,10 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestEventsCopy(c *check.C) {
|
||||
// Build a test image.
|
||||
id, err := buildImage("cpimg", `
|
||||
buildImageSuccessfully(c, "cpimg", withDockerfile(`
|
||||
FROM busybox
|
||||
RUN echo HI > /file`, true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
|
||||
RUN echo HI > /file`))
|
||||
id := getIDByName(c, "cpimg")
|
||||
|
||||
// Create an empty test file.
|
||||
tempFile, err := ioutil.TempFile("", "test-events-copy-")
|
||||
|
@ -595,11 +593,9 @@ func (s *DockerSuite) TestEventsFilterType(c *check.C) {
|
|||
label := "io.docker.testing=image"
|
||||
|
||||
// Build a test image.
|
||||
_, err := buildImage(name, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, name, withDockerfile(fmt.Sprintf(`
|
||||
FROM busybox:latest
|
||||
LABEL %s`, label), true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
|
||||
|
||||
LABEL %s`, label)))
|
||||
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
||||
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
||||
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
||||
|
|
|
@ -310,11 +310,9 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
|
|||
defer observer.Stop()
|
||||
|
||||
name := "testimageevents"
|
||||
imageID, err := buildImage(name,
|
||||
`FROM scratch
|
||||
MAINTAINER "docker"`,
|
||||
true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM scratch
|
||||
MAINTAINER "docker"`))
|
||||
imageID := getIDByName(c, name)
|
||||
c.Assert(deleteImages(name), checker.IsNil)
|
||||
|
||||
testActions := map[string]chan bool{
|
||||
|
|
|
@ -473,13 +473,9 @@ func (s *DockerSuite) TestExecWithImageUser(c *check.C) {
|
|||
// Not applicable on Windows
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testbuilduser"
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
|
||||
USER dockerio`,
|
||||
true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
USER dockerio`))
|
||||
dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top")
|
||||
|
||||
out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami")
|
||||
|
|
|
@ -40,16 +40,12 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
imageName := "testhealth"
|
||||
_, err := buildImage(imageName,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox
|
||||
RUN echo OK > /status
|
||||
CMD ["/bin/sleep", "120"]
|
||||
STOPSIGNAL SIGKILL
|
||||
HEALTHCHECK --interval=1s --timeout=30s \
|
||||
CMD cat /status`,
|
||||
true)
|
||||
|
||||
c.Check(err, check.IsNil)
|
||||
CMD cat /status`))
|
||||
|
||||
// No health status before starting
|
||||
name := "test_health"
|
||||
|
@ -91,10 +87,8 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
dockerCmd(c, "rm", "noh")
|
||||
|
||||
// Disable the check with a new build
|
||||
_, err = buildImage("no_healthcheck",
|
||||
`FROM testhealth
|
||||
HEALTHCHECK NONE`, true)
|
||||
c.Check(err, check.IsNil)
|
||||
buildImageSuccessfully(c, "no_healthcheck", withDockerfile(`FROM testhealth
|
||||
HEALTHCHECK NONE`))
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format={{.ContainerConfig.Healthcheck.Test}}", "no_healthcheck")
|
||||
c.Check(out, checker.Equals, "[NONE]\n")
|
||||
|
@ -137,15 +131,12 @@ func (s *DockerSuite) TestHealth(c *check.C) {
|
|||
dockerCmd(c, "rm", "-f", "test")
|
||||
|
||||
// Check JSON-format
|
||||
_, err = buildImage(imageName,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, imageName, withDockerfile(`FROM busybox
|
||||
RUN echo OK > /status
|
||||
CMD ["/bin/sleep", "120"]
|
||||
STOPSIGNAL SIGKILL
|
||||
HEALTHCHECK --interval=1s --timeout=30s \
|
||||
CMD ["cat", "/my status"]`,
|
||||
true)
|
||||
c.Check(err, check.IsNil)
|
||||
CMD ["cat", "/my status"]`))
|
||||
out, _ = dockerCmd(c, "inspect",
|
||||
"--format={{.Config.Healthcheck.Test}}", imageName)
|
||||
c.Check(out, checker.Equals, "[CMD cat /my status]\n")
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// sort is not predictable it doesn't always fail.
|
||||
func (s *DockerSuite) TestBuildHistory(c *check.C) {
|
||||
name := "testbuildhistory"
|
||||
_, err := buildImage(name, `FROM `+minimalBaseImage()+`
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL label.A="A"
|
||||
LABEL label.B="B"
|
||||
LABEL label.C="C"
|
||||
|
@ -40,12 +40,9 @@ LABEL label.V="V"
|
|||
LABEL label.W="W"
|
||||
LABEL label.X="X"
|
||||
LABEL label.Y="Y"
|
||||
LABEL label.Z="Z"`,
|
||||
true)
|
||||
LABEL label.Z="Z"`))
|
||||
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out, _ := dockerCmd(c, "history", "testbuildhistory")
|
||||
out, _ := dockerCmd(c, "history", name)
|
||||
actualValues := strings.Split(out, "\n")[1:27]
|
||||
expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -45,20 +46,17 @@ func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
||||
id1, err := buildImage("order:test_a",
|
||||
`FROM busybox
|
||||
MAINTAINER dockerio1`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, "order:test_a", withDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio1`))
|
||||
id1 := getIDByName(c, "order:test_a")
|
||||
time.Sleep(1 * time.Second)
|
||||
id2, err := buildImage("order:test_c",
|
||||
`FROM busybox
|
||||
MAINTAINER dockerio2`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, "order:test_c", withDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio2`))
|
||||
id2 := getIDByName(c, "order:test_c")
|
||||
time.Sleep(1 * time.Second)
|
||||
id3, err := buildImage("order:test_b",
|
||||
`FROM busybox
|
||||
MAINTAINER dockerio3`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, "order:test_b", withDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio3`))
|
||||
id3 := getIDByName(c, "order:test_b")
|
||||
|
||||
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
|
||||
imgs := strings.Split(out, "\n")
|
||||
|
@ -77,20 +75,17 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
|||
imageName1 := "images_filter_test1"
|
||||
imageName2 := "images_filter_test2"
|
||||
imageName3 := "images_filter_test3"
|
||||
image1ID, err := buildImage(imageName1,
|
||||
`FROM busybox
|
||||
LABEL match me`, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox
|
||||
LABEL match me`))
|
||||
image1ID := getIDByName(c, imageName1)
|
||||
|
||||
image2ID, err := buildImage(imageName2,
|
||||
`FROM busybox
|
||||
LABEL match="me too"`, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, imageName2, withDockerfile(`FROM busybox
|
||||
LABEL match="me too"`))
|
||||
image2ID := getIDByName(c, imageName2)
|
||||
|
||||
image3ID, err := buildImage(imageName3,
|
||||
`FROM busybox
|
||||
LABEL nomatch me`, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, imageName3, withDockerfile(`FROM busybox
|
||||
LABEL nomatch me`))
|
||||
image3ID := getIDByName(c, imageName3)
|
||||
|
||||
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
|
||||
out = strings.TrimSpace(out)
|
||||
|
@ -117,15 +112,15 @@ func (s *DockerSuite) TestImagesFilterLabelWithCommit(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) {
|
||||
imageID1, err := buildImage("image:1", `FROM `+minimalBaseImage()+`
|
||||
LABEL number=1`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
imageID2, err := buildImage("image:2", `FROM `+minimalBaseImage()+`
|
||||
LABEL number=2`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
imageID3, err := buildImage("image:3", `FROM `+minimalBaseImage()+`
|
||||
LABEL number=3`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, "image:1", withDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL number=1`))
|
||||
imageID1 := getIDByName(c, "image:1")
|
||||
buildImageSuccessfully(c, "image:2", withDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL number=2`))
|
||||
imageID2 := getIDByName(c, "image:2")
|
||||
buildImageSuccessfully(c, "image:3", withDockerfile(`FROM `+minimalBaseImage()+`
|
||||
LABEL number=3`))
|
||||
imageID3 := getIDByName(c, "image:3")
|
||||
|
||||
expected := []string{imageID3, imageID2}
|
||||
|
||||
|
@ -185,13 +180,16 @@ func assertImageList(out string, expected []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test on `docker image ls`
|
||||
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
||||
imageName := "images_filter_test"
|
||||
buildImage(imageName,
|
||||
`FROM busybox
|
||||
// Build a image and fail to build so that we have dangling images ?
|
||||
buildImage(imageName, withDockerfile(`FROM busybox
|
||||
RUN touch /test/foo
|
||||
RUN touch /test/bar
|
||||
RUN touch /test/baz`, true)
|
||||
RUN touch /test/baz`)).Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
})
|
||||
|
||||
filters := []string{
|
||||
"dangling=true",
|
||||
|
@ -250,6 +248,7 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test for `docker image ls`
|
||||
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {
|
||||
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
|
||||
c.Assert(err, check.NotNil)
|
||||
|
@ -261,32 +260,33 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
|
|||
FROM busybox
|
||||
MAINTAINER docker
|
||||
ENV foo bar`
|
||||
|
||||
head, out, err := buildImageWithOut("scratch-image", dockerfile, false)
|
||||
c.Assert(err, check.IsNil)
|
||||
name := "scratch-image"
|
||||
result := buildImage(name, withDockerfile(dockerfile))
|
||||
result.Assert(c, icmd.Success)
|
||||
id := getIDByName(c, name)
|
||||
|
||||
// this is just the output of docker build
|
||||
// we're interested in getting the image id of the MAINTAINER instruction
|
||||
// and that's located at output, line 5, from 7 to end
|
||||
split := strings.Split(out, "\n")
|
||||
split := strings.Split(result.Combined(), "\n")
|
||||
intermediate := strings.TrimSpace(split[5][7:])
|
||||
|
||||
out, _ = dockerCmd(c, "images")
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images shouldn't show non-heads images
|
||||
c.Assert(out, checker.Not(checker.Contains), intermediate)
|
||||
// images should contain final built images
|
||||
c.Assert(out, checker.Contains, stringid.TruncateID(head))
|
||||
c.Assert(out, checker.Contains, stringid.TruncateID(id))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch
|
||||
|
||||
dockerfile := `
|
||||
FROM scratch
|
||||
MAINTAINER docker`
|
||||
|
||||
id, _, err := buildImageWithOut("scratch-image", dockerfile, false)
|
||||
c.Assert(err, check.IsNil)
|
||||
name := "scratch-image"
|
||||
buildImageSuccessfully(c, name, withDockerfile(dockerfile))
|
||||
id := getIDByName(c, name)
|
||||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images should contain images built from scratch
|
||||
|
@ -299,9 +299,10 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) {
|
|||
dockerfile := `
|
||||
FROM busybox
|
||||
MAINTAINER docker`
|
||||
name := "busybox-image"
|
||||
|
||||
id, _, err := buildImageWithOut("busybox-image", dockerfile, false)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, name, withDockerfile(dockerfile))
|
||||
id := getIDByName(c, name)
|
||||
|
||||
out, _ := dockerCmd(c, "images")
|
||||
// images should contain images built from busybox
|
||||
|
|
|
@ -130,8 +130,7 @@ func (s *DockerSuite) TestLogsTail(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
||||
dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello")
|
||||
id, err := getIDByName("test")
|
||||
c.Assert(err, check.IsNil)
|
||||
id := getIDByName(c, "test")
|
||||
|
||||
logsCmd := exec.Command(dockerBinary, "logs", "-f", id)
|
||||
c.Assert(logsCmd.Start(), checker.IsNil)
|
||||
|
|
|
@ -157,8 +157,7 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
|||
|
||||
name := "test_size"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
|
||||
id, err := getIDByName(name)
|
||||
c.Assert(err, checker.IsNil)
|
||||
id := getIDByName(c, name)
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
||||
var out string
|
||||
|
@ -286,8 +285,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
|||
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
||||
// start container
|
||||
dockerCmd(c, "run", "--name=a_name_to_match", "busybox")
|
||||
id, err := getIDByName("a_name_to_match")
|
||||
c.Assert(err, check.IsNil)
|
||||
id := getIDByName(c, "a_name_to_match")
|
||||
|
||||
// start another container
|
||||
runSleepingContainer(c, "--name=b_name_to_match")
|
||||
|
@ -309,47 +307,39 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
|||
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
|
||||
// Build images
|
||||
imageName1 := "images_ps_filter_test1"
|
||||
imageID1, err := buildImage(imageName1,
|
||||
`FROM busybox
|
||||
LABEL match me 1`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, imageName1, withDockerfile(`FROM busybox
|
||||
LABEL match me 1`))
|
||||
imageID1 := getIDByName(c, imageName1)
|
||||
|
||||
imageName1Tagged := "images_ps_filter_test1:tag"
|
||||
imageID1Tagged, err := buildImage(imageName1Tagged,
|
||||
`FROM busybox
|
||||
LABEL match me 1 tagged`, true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, imageName1Tagged, withDockerfile(`FROM busybox
|
||||
LABEL match me 1 tagged`))
|
||||
imageID1Tagged := getIDByName(c, imageName1Tagged)
|
||||
|
||||
imageName2 := "images_ps_filter_test2"
|
||||
imageID2, err := buildImage(imageName2,
|
||||
fmt.Sprintf(`FROM %s
|
||||
LABEL match me 2`, imageName1), true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, imageName2, withDockerfile(fmt.Sprintf(`FROM %s
|
||||
LABEL match me 2`, imageName1)))
|
||||
imageID2 := getIDByName(c, imageName2)
|
||||
|
||||
// start containers
|
||||
dockerCmd(c, "run", "--name=first", "busybox", "echo", "hello")
|
||||
firstID, err := getIDByName("first")
|
||||
c.Assert(err, check.IsNil)
|
||||
firstID := getIDByName(c, "first")
|
||||
|
||||
// start another container
|
||||
dockerCmd(c, "run", "--name=second", "busybox", "echo", "hello")
|
||||
secondID, err := getIDByName("second")
|
||||
c.Assert(err, check.IsNil)
|
||||
secondID := getIDByName(c, "second")
|
||||
|
||||
// start third container
|
||||
dockerCmd(c, "run", "--name=third", imageName1, "echo", "hello")
|
||||
thirdID, err := getIDByName("third")
|
||||
c.Assert(err, check.IsNil)
|
||||
thirdID := getIDByName(c, "third")
|
||||
|
||||
// start fourth container
|
||||
dockerCmd(c, "run", "--name=fourth", imageName1Tagged, "echo", "hello")
|
||||
fourthID, err := getIDByName("fourth")
|
||||
c.Assert(err, check.IsNil)
|
||||
fourthID := getIDByName(c, "fourth")
|
||||
|
||||
// start fifth container
|
||||
dockerCmd(c, "run", "--name=fifth", imageName2, "echo", "hello")
|
||||
fifthID, err := getIDByName("fifth")
|
||||
c.Assert(err, check.IsNil)
|
||||
fifthID := getIDByName(c, "fifth")
|
||||
|
||||
var filterTestSuite = []struct {
|
||||
filterName string
|
||||
|
@ -410,18 +400,15 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
|
|||
func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
|
||||
// start container
|
||||
dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox")
|
||||
firstID, err := getIDByName("first")
|
||||
c.Assert(err, check.IsNil)
|
||||
firstID := getIDByName(c, "first")
|
||||
|
||||
// start another container
|
||||
dockerCmd(c, "run", "--name=second", "-l", "match=me too", "busybox")
|
||||
secondID, err := getIDByName("second")
|
||||
c.Assert(err, check.IsNil)
|
||||
secondID := getIDByName(c, "second")
|
||||
|
||||
// start third container
|
||||
dockerCmd(c, "run", "--name=third", "-l", "nomatch=me", "busybox")
|
||||
thirdID, err := getIDByName("third")
|
||||
c.Assert(err, check.IsNil)
|
||||
thirdID := getIDByName(c, "third")
|
||||
|
||||
// filter containers by exact match
|
||||
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
|
||||
|
@ -450,23 +437,19 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
|||
runSleepingContainer(c, "--name=sleep")
|
||||
|
||||
dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
|
||||
firstZero, err := getIDByName("zero1")
|
||||
c.Assert(err, checker.IsNil)
|
||||
firstZero := getIDByName(c, "zero1")
|
||||
|
||||
dockerCmd(c, "run", "--name", "zero2", "busybox", "true")
|
||||
secondZero, err := getIDByName("zero2")
|
||||
c.Assert(err, checker.IsNil)
|
||||
secondZero := getIDByName(c, "zero2")
|
||||
|
||||
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
||||
|
||||
firstNonZero, err := getIDByName("nonzero1")
|
||||
c.Assert(err, checker.IsNil)
|
||||
firstNonZero := getIDByName(c, "nonzero1")
|
||||
|
||||
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
|
||||
secondNonZero, err := getIDByName("nonzero2")
|
||||
c.Assert(err, checker.IsNil)
|
||||
secondNonZero := getIDByName(c, "nonzero2")
|
||||
|
||||
// filter containers by exited=0
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
|
||||
|
@ -671,8 +654,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|||
|
||||
icmd.RunCommand(dockerBinary, "tag", "busybox:latest", originalImageName).Assert(c, icmd.Success)
|
||||
|
||||
originalImageID, err := getIDByName(originalImageName)
|
||||
c.Assert(err, checker.IsNil)
|
||||
originalImageID := getIDByName(c, originalImageName)
|
||||
|
||||
result := icmd.RunCommand(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...)
|
||||
result.Assert(c, icmd.Success)
|
||||
|
|
|
@ -65,14 +65,13 @@ func testConcurrentPullWholeRepo(c *check.C) {
|
|||
repos := []string{}
|
||||
for _, tag := range []string{"recent", "fresh", "todays"} {
|
||||
repo := fmt.Sprintf("%v:%v", repoName, tag)
|
||||
_, err := buildImage(repo, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(`
|
||||
FROM busybox
|
||||
ENTRYPOINT ["/bin/echo"]
|
||||
ENV FOO foo
|
||||
ENV BAR bar
|
||||
CMD echo %s
|
||||
`, repo), true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
`, repo)))
|
||||
dockerCmd(c, "push", repo)
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
@ -154,14 +153,13 @@ func testConcurrentPullMultipleTags(c *check.C) {
|
|||
repos := []string{}
|
||||
for _, tag := range []string{"recent", "fresh", "todays"} {
|
||||
repo := fmt.Sprintf("%v:%v", repoName, tag)
|
||||
_, err := buildImage(repo, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(`
|
||||
FROM busybox
|
||||
ENTRYPOINT ["/bin/echo"]
|
||||
ENV FOO foo
|
||||
ENV BAR bar
|
||||
CMD echo %s
|
||||
`, repo), true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
`, repo)))
|
||||
dockerCmd(c, "push", repo)
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
@ -209,21 +207,15 @@ func testPullIDStability(c *check.C) {
|
|||
derivedImage := privateRegistryURL + "/dockercli/id-stability"
|
||||
baseImage := "busybox"
|
||||
|
||||
_, err := buildImage(derivedImage, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, derivedImage, withDockerfile(fmt.Sprintf(`
|
||||
FROM %s
|
||||
ENV derived true
|
||||
ENV asdf true
|
||||
RUN dd if=/dev/zero of=/file bs=1024 count=1024
|
||||
CMD echo %s
|
||||
`, baseImage, derivedImage), true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
`, baseImage, derivedImage)))
|
||||
|
||||
originalID, err := getIDByName(derivedImage)
|
||||
if err != nil {
|
||||
c.Fatalf("error inspecting: %v", err)
|
||||
}
|
||||
originalID := getIDByName(c, derivedImage)
|
||||
dockerCmd(c, "push", derivedImage)
|
||||
|
||||
// Pull
|
||||
|
@ -232,10 +224,7 @@ func testPullIDStability(c *check.C) {
|
|||
c.Fatalf("repull redownloaded a layer: %s", out)
|
||||
}
|
||||
|
||||
derivedIDAfterPull, err := getIDByName(derivedImage)
|
||||
if err != nil {
|
||||
c.Fatalf("error inspecting: %v", err)
|
||||
}
|
||||
derivedIDAfterPull := getIDByName(c, derivedImage)
|
||||
|
||||
if derivedIDAfterPull != originalID {
|
||||
c.Fatal("image's ID unexpectedly changed after a repush/repull")
|
||||
|
@ -252,17 +241,11 @@ func testPullIDStability(c *check.C) {
|
|||
dockerCmd(c, "rmi", derivedImage)
|
||||
dockerCmd(c, "pull", derivedImage)
|
||||
|
||||
derivedIDAfterPull, err = getIDByName(derivedImage)
|
||||
if err != nil {
|
||||
c.Fatalf("error inspecting: %v", err)
|
||||
}
|
||||
derivedIDAfterPull = getIDByName(c, derivedImage)
|
||||
|
||||
if derivedIDAfterPull != originalID {
|
||||
c.Fatal("image's ID unexpectedly changed after a repush/repull")
|
||||
}
|
||||
if err != nil {
|
||||
c.Fatalf("error inspecting: %v", err)
|
||||
}
|
||||
|
||||
// Make sure the image still runs
|
||||
out, _ = dockerCmd(c, "run", "--rm", derivedImage)
|
||||
|
@ -283,14 +266,9 @@ func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *check.C) {
|
|||
func testPullNoLayers(c *check.C) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL)
|
||||
|
||||
_, err := buildImage(repoName, `
|
||||
buildImageSuccessfully(c, repoName, withDockerfile(`
|
||||
FROM scratch
|
||||
ENV foo bar`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
ENV foo bar`))
|
||||
dockerCmd(c, "push", repoName)
|
||||
dockerCmd(c, "rmi", repoName)
|
||||
dockerCmd(c, "pull", repoName)
|
||||
|
|
|
@ -149,11 +149,10 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) {
|
|||
func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) {
|
||||
repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, "trusted-pull-delete")
|
||||
// tag the image and upload it to the private registry
|
||||
_, err := buildImage(repoName, `
|
||||
buildImageSuccessfully(c, repoName, withDockerfile(`
|
||||
FROM busybox
|
||||
CMD echo trustedpulldelete
|
||||
`, true)
|
||||
|
||||
`))
|
||||
icmd.RunCmd(icmd.Command(dockerBinary, "push", repoName), trustedCmd).Assert(c, SuccessSigningAndPushing)
|
||||
|
||||
dockerCmd(c, "rmi", repoName)
|
||||
|
@ -176,7 +175,7 @@ func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) {
|
|||
// rmi of tag should also remove the digest reference
|
||||
dockerCmd(c, "rmi", repoName)
|
||||
|
||||
_, err = inspectFieldWithError(imageByDigest, "Id")
|
||||
_, err := inspectFieldWithError(imageByDigest, "Id")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("digest reference should have been removed"))
|
||||
|
||||
_, err = inspectFieldWithError(imageID, "Id")
|
||||
|
|
|
@ -161,14 +161,13 @@ func testConcurrentPush(c *check.C) {
|
|||
repos := []string{}
|
||||
for _, tag := range []string{"push1", "push2", "push3"} {
|
||||
repo := fmt.Sprintf("%v:%v", repoName, tag)
|
||||
_, err := buildImage(repo, fmt.Sprintf(`
|
||||
buildImageSuccessfully(c, repo, withDockerfile(fmt.Sprintf(`
|
||||
FROM busybox
|
||||
ENTRYPOINT ["/bin/echo"]
|
||||
ENV FOO foo
|
||||
ENV BAR bar
|
||||
CMD echo %s
|
||||
`, repo), true)
|
||||
c.Assert(err, checker.IsNil)
|
||||
`, repo)))
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ import (
|
|||
|
||||
func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
|
||||
dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar")
|
||||
cleanedContainerID, err := getIDByName("test")
|
||||
c.Assert(err, check.IsNil)
|
||||
cleanedContainerID := getIDByName(c, "test")
|
||||
|
||||
out, _ := dockerCmd(c, "logs", cleanedContainerID)
|
||||
c.Assert(out, checker.Equals, "foobar\n")
|
||||
|
@ -21,7 +20,7 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
|
|||
dockerCmd(c, "restart", cleanedContainerID)
|
||||
|
||||
// Wait until the container has stopped
|
||||
err = waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second)
|
||||
err := waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "logs", cleanedContainerID)
|
||||
|
|
|
@ -58,13 +58,12 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
|||
MAINTAINER Integration Tests`
|
||||
|
||||
// build first dockerfile
|
||||
img1, err := buildImage(img, dockerfile1, true)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
|
||||
buildImageSuccessfully(c, img, withDockerfile(dockerfile1))
|
||||
img1 := getIDByName(c, img)
|
||||
// run container on first image
|
||||
dockerCmd(c, "run", img)
|
||||
// rebuild dockerfile with a small addition at the end
|
||||
_, err = buildImage(img, dockerfile2, true)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
|
||||
buildImageSuccessfully(c, img, withDockerfile(dockerfile2))
|
||||
// try to remove the image, should not error out.
|
||||
out, _, err := dockerCmdWithError("rmi", img)
|
||||
c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out))
|
||||
|
|
|
@ -147,8 +147,8 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
|||
// See https://github.com/docker/docker/issues/14116
|
||||
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) {
|
||||
dockerfile := "FROM busybox\nRUN echo test 14116\n"
|
||||
imgID, err := buildImage("test-14116", dockerfile, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, "test-14116", withDockerfile(dockerfile))
|
||||
imgID := getIDByName(c, "test-14116")
|
||||
|
||||
newTag := "newtag"
|
||||
dockerCmd(c, "tag", imgID, newTag)
|
||||
|
@ -205,14 +205,8 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
|
|||
tag1 := imageName + ":tag1"
|
||||
tag2 := imageName + ":tag2"
|
||||
|
||||
_, err := buildImage(tag1,
|
||||
`FROM busybox
|
||||
MAINTAINER "docker"`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
buildImageSuccessfully(c, tag1, withDockerfile(`FROM busybox
|
||||
MAINTAINER "docker"`))
|
||||
dockerCmd(c, "tag", tag1, tag2)
|
||||
|
||||
out, _ := dockerCmd(c, "rmi", "-f", tag2)
|
||||
|
@ -240,8 +234,8 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
|
|||
imageIds := make([]string, 2)
|
||||
for i, name := range imageNames {
|
||||
dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name)
|
||||
id, err := buildImage(name, dockerfile, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
buildImageSuccessfully(c, name, withoutCache, withDockerfile(dockerfile))
|
||||
id := getIDByName(c, name)
|
||||
imageIds[i] = id
|
||||
}
|
||||
|
||||
|
@ -269,9 +263,7 @@ RUN echo 0 #layer0
|
|||
RUN echo 1 #layer1
|
||||
RUN echo 2 #layer2
|
||||
`
|
||||
_, err := buildImage(image, dockerfile, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
buildImageSuccessfully(c, image, withoutCache, withDockerfile(dockerfile))
|
||||
out, _ := dockerCmd(c, "history", "-q", image)
|
||||
ids := strings.Split(out, "\n")
|
||||
idToTag := ids[2]
|
||||
|
@ -294,7 +286,7 @@ RUN echo 2 #layer2
|
|||
|
||||
// At this point we have 2 containers, one based on layer2 and another based on layer0.
|
||||
// Try to untag "tmp2" without the -f flag.
|
||||
out, _, err = dockerCmdWithError("rmi", newTag)
|
||||
out, _, err := dockerCmdWithError("rmi", newTag)
|
||||
// should not be untagged without the -f flag
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(out, checker.Contains, cid[:12])
|
||||
|
@ -307,10 +299,9 @@ RUN echo 2 #layer2
|
|||
}
|
||||
|
||||
func (*DockerSuite) TestRmiParentImageFail(c *check.C) {
|
||||
_, err := buildImage("test", `
|
||||
buildImageSuccessfully(c, "test", withDockerfile(`
|
||||
FROM busybox
|
||||
RUN echo hello`, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
RUN echo hello`))
|
||||
|
||||
id := inspectField(c, "busybox", "ID")
|
||||
out, _, err := dockerCmdWithError("rmi", id)
|
||||
|
|
|
@ -410,10 +410,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) {
|
|||
containerPath = "/test/test"
|
||||
cmd = "true"
|
||||
}
|
||||
if _, err := buildImage(name, dockerFile, false); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
buildImageSuccessfully(c, name, withDockerfile(dockerFile))
|
||||
dockerCmd(c, "run", "-v", containerPath, name, cmd)
|
||||
}
|
||||
|
||||
|
@ -438,10 +435,7 @@ func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir2(c *check.C) {
|
|||
containerPath = "/test/test"
|
||||
cmd = "true"
|
||||
}
|
||||
if _, err := buildImage(name, dockerFile, false); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
buildImageSuccessfully(c, name, withDockerfile(dockerFile))
|
||||
dockerCmd(c, "run", "-v", containerPath, name, cmd)
|
||||
}
|
||||
|
||||
|
@ -1409,10 +1403,7 @@ func (s *DockerSuite) TestRunNonRootUserResolvName(c *check.C) {
|
|||
|
||||
dockerCmd(c, "run", "--name=testperm", "--user=nobody", "busybox", "nslookup", "apt.dockerproject.org")
|
||||
|
||||
cID, err := getIDByName("testperm")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
cID := getIDByName(c, "testperm")
|
||||
|
||||
fmode := (os.FileMode)(0644)
|
||||
finfo, err := os.Stat(containerStorageFile(cID, "resolv.conf"))
|
||||
|
@ -1462,10 +1453,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
|
|||
|
||||
//1. test that a restarting container gets an updated resolv.conf
|
||||
dockerCmd(c, "run", "--name=first", "busybox", "true")
|
||||
containerID1, err := getIDByName("first")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
containerID1 := getIDByName(c, "first")
|
||||
|
||||
// replace resolv.conf with our temporary copy
|
||||
bytesResolvConf := []byte(tmpResolvConf)
|
||||
|
@ -1492,10 +1480,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
|
|||
//2. test that a restarting container does not receive resolv.conf updates
|
||||
// if it modified the container copy of the starting point resolv.conf
|
||||
dockerCmd(c, "run", "--name=second", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf")
|
||||
containerID2, err := getIDByName("second")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
containerID2 := getIDByName(c, "second")
|
||||
|
||||
//make a change to resolv.conf (in this case replacing our tmp copy with orig copy)
|
||||
if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil {
|
||||
|
@ -1581,10 +1566,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
|
|||
|
||||
// Run the container so it picks up the old settings
|
||||
dockerCmd(c, "run", "--name=third", "busybox", "true")
|
||||
containerID3, err := getIDByName("third")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
containerID3 := getIDByName(c, "third")
|
||||
|
||||
// Create a modified resolv.conf.aside and override resolv.conf with it
|
||||
bytesResolvConf = []byte(tmpResolvConf)
|
||||
|
@ -1698,15 +1680,10 @@ func (s *DockerSuite) TestRunCopyVolumeUIDGID(c *check.C) {
|
|||
// Not applicable on Windows as it does not support uid or gid in this way
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testrunvolumesuidgid"
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
|
||||
RUN echo 'dockerio:x:1001:' >> /etc/group
|
||||
RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`))
|
||||
|
||||
// Test that the uid and gid is copied from the image to the volume
|
||||
out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'")
|
||||
|
@ -1722,13 +1699,8 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) {
|
|||
// that copies from the image to the volume.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testruncopyvolumecontent"
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
RUN mkdir -p /hello/local && echo hello > /hello/local/world`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN mkdir -p /hello/local && echo hello > /hello/local/world`))
|
||||
|
||||
// Test that the content is copied from the image to the volume
|
||||
out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello")
|
||||
|
@ -1739,13 +1711,9 @@ func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) {
|
||||
name := "testrunmdcleanuponentrypoint"
|
||||
if _, err := buildImage(name,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
ENTRYPOINT ["echo"]
|
||||
CMD ["testingpoint"]`,
|
||||
true); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
CMD ["testingpoint"]`))
|
||||
|
||||
out, exit := dockerCmd(c, "run", "--entrypoint", "whoami", name)
|
||||
if exit != 0 {
|
||||
|
@ -1879,9 +1847,7 @@ func testRunWriteSpecialFilesAndNotCommit(c *check.C, name, path string) {
|
|||
func eqToBaseDiff(out string, c *check.C) bool {
|
||||
name := "eqToBaseDiff" + stringutils.GenerateRandomAlphaOnlyString(32)
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "echo", "hello")
|
||||
cID, err := getIDByName(name)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
cID := getIDByName(c, name)
|
||||
baseDiff, _ := dockerCmd(c, "diff", cID)
|
||||
baseArr := strings.Split(baseDiff, "\n")
|
||||
sort.Strings(baseArr)
|
||||
|
@ -2229,14 +2195,9 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
|
|||
// are pre-populated such as is built in the dockerfile used in this test.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
if _, err := buildImage("dataimage",
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, "dataimage", withDockerfile(`FROM busybox
|
||||
RUN ["mkdir", "-p", "/foo"]
|
||||
RUN ["touch", "/foo/bar"]`,
|
||||
true); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
RUN ["touch", "/foo/bar"]`))
|
||||
dockerCmd(c, "run", "--name", "test", "-v", prefix+slash+"foo", "busybox")
|
||||
|
||||
if out, _, err := dockerCmdWithError("run", "--volumes-from", "test", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
|
@ -2265,13 +2226,8 @@ func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) {
|
|||
func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
if _, err := buildImage("run_volumes_clean_paths",
|
||||
`FROM busybox
|
||||
VOLUME `+prefix+`/foo/`,
|
||||
true); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
buildImageSuccessfully(c, "run_volumes_clean_paths", withDockerfile(`FROM busybox
|
||||
VOLUME `+prefix+`/foo/`))
|
||||
dockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths")
|
||||
|
||||
out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash)
|
||||
|
@ -3444,8 +3400,7 @@ func testRunContainerWithCgroupParent(c *check.C, cgroupParent, name string) {
|
|||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
c.Assert(err, check.IsNil)
|
||||
id := getIDByName(c, name)
|
||||
expectedCgroup := path.Join(cgroupParent, id)
|
||||
found := false
|
||||
for _, path := range cgroupPaths {
|
||||
|
@ -3485,8 +3440,7 @@ func testRunInvalidCgroupParent(c *check.C, cgroupParent, cleanCgroupParent, nam
|
|||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
c.Assert(err, check.IsNil)
|
||||
id := getIDByName(c, name)
|
||||
expectedCgroup := path.Join(cleanCgroupParent, id)
|
||||
found := false
|
||||
for _, path := range cgroupPaths {
|
||||
|
@ -3919,15 +3873,10 @@ func (s *DockerSuite) TestRunInitLayerPathOwnership(c *check.C) {
|
|||
// Not applicable on Windows as it does not support Linux uid/gid ownership
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "testetcfileownership"
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
|
||||
RUN echo 'dockerio:x:1001:' >> /etc/group
|
||||
RUN chown dockerio:dockerio /etc`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
RUN chown dockerio:dockerio /etc`))
|
||||
|
||||
// Test that dockerio ownership of /etc is retained at runtime
|
||||
out, _ := dockerCmd(c, "run", "--rm", name, "stat", "-c", "%U:%G", "/etc")
|
||||
|
@ -4056,11 +4005,10 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) {
|
|||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
testImg := "testvolumecopy"
|
||||
_, err := buildImage(testImg, `
|
||||
buildImageSuccessfully(c, testImg, withDockerfile(`
|
||||
FROM busybox
|
||||
RUN mkdir -p /foo && echo hello > /foo/hello
|
||||
`, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
`))
|
||||
|
||||
dockerCmd(c, "run", "-v", "foo:/foo", testImg)
|
||||
out, _ := dockerCmd(c, "run", "-v", "foo:/foo", "busybox", "cat", "/foo/hello")
|
||||
|
@ -4136,14 +4084,9 @@ func (s *DockerSuite) TestRunVolumeWithOneCharacter(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux) // Windows does not support copying data from image to the volume
|
||||
_, err := buildImage("volumecopy",
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, "volumecopy", withDockerfile(`FROM busybox
|
||||
RUN mkdir /foo && echo hello > /foo/bar
|
||||
CMD cat /foo/bar`,
|
||||
true,
|
||||
)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
CMD cat /foo/bar`))
|
||||
dockerCmd(c, "volume", "create", "test")
|
||||
|
||||
// test with the nocopy flag
|
||||
|
@ -4232,22 +4175,20 @@ RUN chmod 755 /entrypoint.sh
|
|||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD echo foobar`
|
||||
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||
ctx := fakeContext(c, dockerfile, map[string]string{
|
||||
"entrypoint.sh": `#!/bin/sh
|
||||
echo "I am an entrypoint"
|
||||
exec "$@"`,
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
defer ctx.Close()
|
||||
|
||||
_, err = buildImageFromContext(name, ctx, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
buildImageSuccessfully(c, name, withExternalBuildContext(ctx))
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
|
||||
|
||||
// CMD will be reset as well (the same as setting a custom entrypoint)
|
||||
_, _, err = dockerCmdWithError("run", "--entrypoint=", "-t", name)
|
||||
_, _, err := dockerCmdWithError("run", "--entrypoint=", "-t", name)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err.Error(), checker.Contains, "No command specified")
|
||||
}
|
||||
|
|
|
@ -828,17 +828,11 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
|
||||
name := "img-with-volumes"
|
||||
_, err := buildImage(
|
||||
name,
|
||||
`
|
||||
buildImageSuccessfully(c, name, withDockerfile(`
|
||||
FROM busybox
|
||||
VOLUME /run
|
||||
RUN touch /run/stuff
|
||||
`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
`))
|
||||
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run")
|
||||
c.Assert(out, checker.Not(checker.Contains), "stuff")
|
||||
}
|
||||
|
|
|
@ -260,12 +260,9 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|||
os.Mkdir(extractionDirectory, 0777)
|
||||
|
||||
defer os.RemoveAll(tmpDir)
|
||||
_, err = buildImage(name,
|
||||
`FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
||||
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`,
|
||||
true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("%v", err))
|
||||
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`))
|
||||
|
||||
out, _, err := testutil.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", name),
|
||||
|
@ -358,9 +355,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|||
|
||||
name := "saveloadnotag"
|
||||
|
||||
_, err := buildImage(name, "FROM busybox\nENV foo=bar", true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("%v", err))
|
||||
|
||||
buildImageSuccessfully(c, name, withDockerfile("FROM busybox\nENV foo=bar"))
|
||||
id := inspectField(c, name, "Id")
|
||||
|
||||
// Test to make sure that save w/o name just shows imageID during load
|
||||
|
|
|
@ -72,11 +72,9 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) {
|
||||
name := "test-load"
|
||||
_, err := buildImage(name, `
|
||||
FROM busybox
|
||||
buildImageSuccessfully(c, name, withDockerfile(`FROM busybox
|
||||
RUN touch aa
|
||||
`, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
`))
|
||||
|
||||
tmptar := name + ".tar"
|
||||
dockerCmd(c, "save", "-o", tmptar, name)
|
||||
|
|
|
@ -142,13 +142,9 @@ func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) {
|
|||
|
||||
// ensure tags cannot create ambiguity with image ids
|
||||
func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) {
|
||||
imageID, err := buildImage("notbusybox:latest",
|
||||
`FROM busybox
|
||||
MAINTAINER dockerio`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
buildImageSuccessfully(c, "notbusybox:latest", withDockerfile(`FROM busybox
|
||||
MAINTAINER dockerio`))
|
||||
imageID := getIDByName(c, "notbusybox:latest")
|
||||
truncatedImageID := stringid.TruncateID(imageID)
|
||||
truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID)
|
||||
|
||||
|
@ -159,7 +155,7 @@ func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) {
|
|||
c.Logf("Built image: %s", imageID)
|
||||
|
||||
// test setting tag fails
|
||||
_, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag)
|
||||
_, _, err := dockerCmdWithError("tag", "busybox:latest", truncatedTag)
|
||||
if err != nil {
|
||||
c.Fatalf("Error tagging with an image id: %s", err)
|
||||
}
|
||||
|
|
|
@ -368,52 +368,41 @@ func (f *FakeContext) Close() error {
|
|||
return os.RemoveAll(f.Dir)
|
||||
}
|
||||
|
||||
func fakeContextFromNewTempDir() (*FakeContext, error) {
|
||||
func fakeContextFromNewTempDir(c *check.C) *FakeContext {
|
||||
tmp, err := ioutil.TempDir("", "fake-context")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
if err := os.Chmod(tmp, 0755); err != nil {
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
return fakeContextFromDir(tmp), nil
|
||||
return fakeContextFromDir(tmp)
|
||||
}
|
||||
|
||||
func fakeContextFromDir(dir string) *FakeContext {
|
||||
return &FakeContext{dir}
|
||||
}
|
||||
|
||||
func fakeContextWithFiles(files map[string]string) (*FakeContext, error) {
|
||||
ctx, err := fakeContextFromNewTempDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func fakeContextWithFiles(c *check.C, files map[string]string) *FakeContext {
|
||||
ctx := fakeContextFromNewTempDir(c)
|
||||
for file, content := range files {
|
||||
if err := ctx.Add(file, content); err != nil {
|
||||
ctx.Close()
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
return ctx, nil
|
||||
return ctx
|
||||
}
|
||||
|
||||
func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error {
|
||||
func fakeContextAddDockerfile(c *check.C, ctx *FakeContext, dockerfile string) {
|
||||
if err := ctx.Add("Dockerfile", dockerfile); err != nil {
|
||||
ctx.Close()
|
||||
return err
|
||||
c.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) {
|
||||
ctx, err := fakeContextWithFiles(files)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ctx, nil
|
||||
func fakeContext(c *check.C, dockerfile string, files map[string]string) *FakeContext {
|
||||
ctx := fakeContextWithFiles(c, files)
|
||||
fakeContextAddDockerfile(c, ctx, dockerfile)
|
||||
return ctx
|
||||
}
|
||||
|
||||
// FakeStorage is a static file server. It might be running locally or remotely
|
||||
|
@ -424,34 +413,28 @@ type FakeStorage interface {
|
|||
CtxDir() string
|
||||
}
|
||||
|
||||
func fakeBinaryStorage(archives map[string]*bytes.Buffer) (FakeStorage, error) {
|
||||
ctx, err := fakeContextFromNewTempDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func fakeBinaryStorage(c *check.C, archives map[string]*bytes.Buffer) FakeStorage {
|
||||
ctx := fakeContextFromNewTempDir(c)
|
||||
for name, content := range archives {
|
||||
if err := ctx.addFile(name, content.Bytes()); err != nil {
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
return fakeStorageWithContext(ctx)
|
||||
return fakeStorageWithContext(c, ctx)
|
||||
}
|
||||
|
||||
// fakeStorage returns either a local or remote (at daemon machine) file server
|
||||
func fakeStorage(files map[string]string) (FakeStorage, error) {
|
||||
ctx, err := fakeContextWithFiles(files)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fakeStorageWithContext(ctx)
|
||||
func fakeStorage(c *check.C, files map[string]string) FakeStorage {
|
||||
ctx := fakeContextWithFiles(c, files)
|
||||
return fakeStorageWithContext(c, ctx)
|
||||
}
|
||||
|
||||
// fakeStorageWithContext returns either a local or remote (at daemon machine) file server
|
||||
func fakeStorageWithContext(ctx *FakeContext) (FakeStorage, error) {
|
||||
func fakeStorageWithContext(c *check.C, ctx *FakeContext) FakeStorage {
|
||||
if testEnv.LocalDaemon() {
|
||||
return newLocalFakeStorage(ctx)
|
||||
return newLocalFakeStorage(c, ctx)
|
||||
}
|
||||
return newRemoteFileServer(ctx)
|
||||
return newRemoteFileServer(c, ctx)
|
||||
}
|
||||
|
||||
// localFileStorage is a file storage on the running machine
|
||||
|
@ -473,13 +456,13 @@ func (s *localFileStorage) Close() error {
|
|||
return s.FakeContext.Close()
|
||||
}
|
||||
|
||||
func newLocalFakeStorage(ctx *FakeContext) (*localFileStorage, error) {
|
||||
func newLocalFakeStorage(c *check.C, ctx *FakeContext) *localFileStorage {
|
||||
handler := http.FileServer(http.Dir(ctx.Dir))
|
||||
server := httptest.NewServer(handler)
|
||||
return &localFileStorage{
|
||||
FakeContext: ctx,
|
||||
Server: server,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// remoteFileServer is a containerized static file server started on the remote
|
||||
|
@ -517,58 +500,45 @@ func (f *remoteFileServer) Close() error {
|
|||
return deleteContainer(false, f.container)
|
||||
}
|
||||
|
||||
func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) {
|
||||
func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer {
|
||||
var (
|
||||
image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
||||
container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
||||
)
|
||||
|
||||
if err := ensureHTTPServerImage(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Assert(ensureHTTPServerImage(), checker.IsNil)
|
||||
|
||||
// Build the image
|
||||
if err := fakeContextAddDockerfile(ctx, `FROM httpserver
|
||||
COPY . /static`); err != nil {
|
||||
return nil, fmt.Errorf("Cannot add Dockerfile to context: %v", err)
|
||||
}
|
||||
if _, err := buildImageFromContext(image, ctx, false); err != nil {
|
||||
return nil, fmt.Errorf("failed building file storage container image: %v", err)
|
||||
}
|
||||
fakeContextAddDockerfile(c, ctx, `FROM httpserver
|
||||
COPY . /static`)
|
||||
buildImageSuccessfully(c, image, withoutCache, withExternalBuildContext(ctx))
|
||||
|
||||
// Start the container
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--name", container, image)
|
||||
if out, ec, err := runCommandWithOutput(runCmd); err != nil {
|
||||
return nil, fmt.Errorf("failed to start file storage container. ec=%v\nout=%s\nerr=%v", ec, out, err)
|
||||
}
|
||||
dockerCmd(c, "run", "-d", "-P", "--name", container, image)
|
||||
|
||||
// Find out the system assigned port
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "port", container, "80/tcp"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find container port: err=%v\nout=%s", err, out)
|
||||
}
|
||||
|
||||
out, _ := dockerCmd(c, "port", container, "80/tcp")
|
||||
fileserverHostPort := strings.Trim(out, "\n")
|
||||
_, port, err := net.SplitHostPort(fileserverHostPort)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse file server host:port: %v", err)
|
||||
c.Fatalf("unable to parse file server host:port: %v", err)
|
||||
}
|
||||
|
||||
dockerHostURL, err := url.Parse(daemonHost())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse daemon host URL: %v", err)
|
||||
c.Fatalf("unable to parse daemon host URL: %v", err)
|
||||
}
|
||||
|
||||
host, _, err := net.SplitHostPort(dockerHostURL.Host)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse docker daemon host:port: %v", err)
|
||||
c.Fatalf("unable to parse docker daemon host:port: %v", err)
|
||||
}
|
||||
|
||||
return &remoteFileServer{
|
||||
container: container,
|
||||
image: image,
|
||||
host: fmt.Sprintf("%s:%s", host, port),
|
||||
ctx: ctx}, nil
|
||||
ctx: ctx}
|
||||
}
|
||||
|
||||
func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) {
|
||||
|
@ -671,51 +641,17 @@ func inspectImage(name, filter string) (string, error) {
|
|||
return strings.TrimSpace(out), nil
|
||||
}
|
||||
|
||||
func getIDByName(name string) (string, error) {
|
||||
return inspectFieldWithError(name, "Id")
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageCmd(name, dockerfile string, useCache bool, buildFlags ...string) *exec.Cmd {
|
||||
return daemon.BuildImageCmdWithHost(dockerBinary, name, dockerfile, "", useCache, buildFlags...)
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, error) {
|
||||
buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...)
|
||||
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", out, fmt.Errorf("failed to build the image: %s", out)
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", out, err
|
||||
}
|
||||
return id, out, nil
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) {
|
||||
buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...)
|
||||
result := icmd.RunCmd(transformCmd(buildCmd))
|
||||
err := result.Error
|
||||
exitCode := result.ExitCode
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
func getIDByName(c *check.C, name string) string {
|
||||
id, err := inspectFieldWithError(name, "Id")
|
||||
c.Assert(err, checker.IsNil)
|
||||
return id
|
||||
}
|
||||
|
||||
func buildImageSuccessfully(c *check.C, name string, cmdOperators ...func(*icmd.Cmd) func()) {
|
||||
buildImageNew(name, cmdOperators...).Assert(c, icmd.Success)
|
||||
buildImage(name, cmdOperators...).Assert(c, icmd.Success)
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) rename this buildImage once deprecated buildImage is no more
|
||||
func buildImageNew(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result {
|
||||
func buildImage(name string, cmdOperators ...func(*icmd.Cmd) func()) *icmd.Result {
|
||||
cmd := icmd.Command(dockerBinary, "build", "-t", name)
|
||||
for _, op := range cmdOperators {
|
||||
deferFn := op(&cmd)
|
||||
|
@ -733,11 +669,16 @@ func withBuildContextPath(path string) func(*icmd.Cmd) func() {
|
|||
}
|
||||
}
|
||||
|
||||
func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() {
|
||||
ctx, err := fakeContextFromNewTempDir()
|
||||
if err != nil {
|
||||
c.Fatalf("error creating build context : %v", err)
|
||||
func withExternalBuildContext(ctx *FakeContext) func(*icmd.Cmd) func() {
|
||||
return func(cmd *icmd.Cmd) func() {
|
||||
cmd.Dir = ctx.Dir
|
||||
cmd.Command = append(cmd.Command, ".")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() {
|
||||
ctx := fakeContextFromNewTempDir(c)
|
||||
for _, op := range contextOperators {
|
||||
if err := op(ctx); err != nil {
|
||||
c.Fatal(err)
|
||||
|
@ -796,108 +737,6 @@ func withEnvironmentVariales(envs ...string) func(cmd *icmd.Cmd) func() {
|
|||
}
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) {
|
||||
id, _, err := buildImageWithOut(name, dockerfile, useCache, buildFlags...)
|
||||
return id, err
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageFromContext(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, error) {
|
||||
id, _, err := buildImageFromContextWithOut(name, ctx, useCache, buildFlags...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageFromContextWithOut(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, error) {
|
||||
args := []string{"build", "-t", name}
|
||||
if !useCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, ".")
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
Dir: ctx.Dir,
|
||||
})
|
||||
out := result.Combined()
|
||||
if result.Error != nil || result.ExitCode != 0 {
|
||||
return "", "", fmt.Errorf("failed to build the image: %s", out)
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return id, out, nil
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, string, error) {
|
||||
args := []string{"build", "-t", name}
|
||||
if !useCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, ".")
|
||||
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
Dir: ctx.Dir,
|
||||
})
|
||||
exitCode := result.ExitCode
|
||||
err := result.Error
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) {
|
||||
args := []string{"build", "-t", name}
|
||||
if !useCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, ctx.RepoURL)
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
})
|
||||
exitCode := result.ExitCode
|
||||
err := result.Error
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) {
|
||||
args := []string{"build", "-t", name}
|
||||
if !useCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, path)
|
||||
buildCmd := exec.Command(dockerBinary, args...)
|
||||
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", fmt.Errorf("failed to build the image: %s", out)
|
||||
}
|
||||
return getIDByName(name)
|
||||
}
|
||||
|
||||
type gitServer interface {
|
||||
URL() string
|
||||
Close() error
|
||||
|
@ -927,69 +766,63 @@ func (g *fakeGit) Close() {
|
|||
os.RemoveAll(g.root)
|
||||
}
|
||||
|
||||
func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (*fakeGit, error) {
|
||||
ctx, err := fakeContextWithFiles(files)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalServer bool) *fakeGit {
|
||||
ctx := fakeContextWithFiles(c, files)
|
||||
defer ctx.Close()
|
||||
curdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
defer os.Chdir(curdir)
|
||||
|
||||
if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("error trying to init repo: %s (%s)", err, output)
|
||||
c.Fatalf("error trying to init repo: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(ctx.Dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
if output, err := exec.Command("git", "config", "user.name", "Fake User").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("error trying to set 'user.name': %s (%s)", err, output)
|
||||
c.Fatalf("error trying to set 'user.name': %s (%s)", err, output)
|
||||
}
|
||||
if output, err := exec.Command("git", "config", "user.email", "fake.user@example.com").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("error trying to set 'user.email': %s (%s)", err, output)
|
||||
c.Fatalf("error trying to set 'user.email': %s (%s)", err, output)
|
||||
}
|
||||
if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("error trying to add files to repo: %s (%s)", err, output)
|
||||
c.Fatalf("error trying to add files to repo: %s (%s)", err, output)
|
||||
}
|
||||
if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("error trying to commit to repo: %s (%s)", err, output)
|
||||
c.Fatalf("error trying to commit to repo: %s (%s)", err, output)
|
||||
}
|
||||
|
||||
root, err := ioutil.TempDir("", "docker-test-git-repo")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
repoPath := filepath.Join(root, name+".git")
|
||||
if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, fmt.Errorf("error trying to clone --bare: %s (%s)", err, output)
|
||||
c.Fatalf("error trying to clone --bare: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(repoPath)
|
||||
if err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, fmt.Errorf("error trying to git update-server-info: %s (%s)", err, output)
|
||||
c.Fatalf("error trying to git update-server-info: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(curdir)
|
||||
if err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, err
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
var server gitServer
|
||||
if !enforceLocalServer {
|
||||
// use fakeStorage server, which might be local or remote (at test daemon)
|
||||
server, err = fakeStorageWithContext(fakeContextFromDir(root))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot start fake storage: %v", err)
|
||||
}
|
||||
server = fakeStorageWithContext(c, fakeContextFromDir(root))
|
||||
} else {
|
||||
// always start a local http server on CLI test machine
|
||||
httpServer := httptest.NewServer(http.FileServer(http.Dir(root)))
|
||||
|
@ -999,7 +832,7 @@ func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (
|
|||
root: root,
|
||||
server: server,
|
||||
RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Write `content` to the file at path `dst`, creating it if necessary,
|
||||
|
|
Loading…
Reference in a new issue