mirror of https://github.com/docker/docs.git
Merge pull request #6051 from LK4D4/move_some_build_tests_to_integration_cli
Move some build tests to integration cli
This commit is contained in:
commit
b904d0af56
|
@ -10,6 +10,25 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkSimpleBuild(t *testing.T, dockerfile, name, inspectFormat, expected string) {
|
||||||
|
buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-")
|
||||||
|
buildCmd.Stdin = strings.NewReader(dockerfile)
|
||||||
|
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||||
|
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
t.Fatal("failed to build the image")
|
||||||
|
}
|
||||||
|
inspectCmd := exec.Command(dockerBinary, "inspect", "-f", inspectFormat, name)
|
||||||
|
out, exitCode, err = runCommandWithOutput(inspectCmd)
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
t.Fatalf("failed to inspect the image: %s", out)
|
||||||
|
}
|
||||||
|
out = strings.TrimSpace(out)
|
||||||
|
if out != expected {
|
||||||
|
t.Fatalf("From format %s expected %s, got %s", inspectFormat, expected, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildCacheADD(t *testing.T) {
|
func TestBuildCacheADD(t *testing.T) {
|
||||||
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1")
|
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1")
|
||||||
buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".")
|
buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".")
|
||||||
|
@ -413,6 +432,128 @@ func TestBuildRm(t *testing.T) {
|
||||||
logDone("build - ensure --rm=false overrides the default")
|
logDone("build - ensure --rm=false overrides the default")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildWithVolume(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
VOLUME /test
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.Volumes}}",
|
||||||
|
`{"/test":{}}`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - with volume")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildMaintainer(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
MAINTAINER dockerio
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .author}}",
|
||||||
|
`"dockerio"`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - maintainer")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildUser(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
|
||||||
|
USER dockerio
|
||||||
|
RUN [ $(whoami) = 'dockerio' ]
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.User}}",
|
||||||
|
`"dockerio"`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - user")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildRelativeWorkdir(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
RUN [ "$PWD" = '/' ]
|
||||||
|
WORKDIR test1
|
||||||
|
RUN [ "$PWD" = '/test1' ]
|
||||||
|
WORKDIR /test2
|
||||||
|
RUN [ "$PWD" = '/test2' ]
|
||||||
|
WORKDIR test3
|
||||||
|
RUN [ "$PWD" = '/test2/test3' ]
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.WorkingDir}}",
|
||||||
|
`"/test2/test3"`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - relative workdir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnv(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM busybox
|
||||||
|
ENV PORT 4243
|
||||||
|
RUN [ $(env | grep PORT) = 'PORT=4243' ]
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.Env}}",
|
||||||
|
`["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","PORT=4243"]`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - env")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildCmd(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
CMD ["/bin/echo", "Hello World"]
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.Cmd}}",
|
||||||
|
`["/bin/echo","Hello World"]`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - cmd")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildExpose(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
EXPOSE 4243
|
||||||
|
`,
|
||||||
|
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.ExposedPorts}}",
|
||||||
|
`{"4243/tcp":{}}`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - expose")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEntrypoint(t *testing.T) {
|
||||||
|
checkSimpleBuild(t,
|
||||||
|
`
|
||||||
|
FROM scratch
|
||||||
|
ENTRYPOINT ["/bin/echo"]
|
||||||
|
`,
|
||||||
|
"testbuildimg",
|
||||||
|
"{{json .config.Entrypoint}}",
|
||||||
|
`["/bin/echo"]`)
|
||||||
|
|
||||||
|
deleteImages("testbuildimg")
|
||||||
|
logDone("build - entrypoint")
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: TestCaching
|
// TODO: TestCaching
|
||||||
|
|
||||||
// TODO: TestADDCacheInvalidation
|
// TODO: TestADDCacheInvalidation
|
||||||
|
|
|
@ -414,146 +414,6 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u
|
||||||
return image, err
|
return image, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVolume(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
volume /test
|
|
||||||
cmd Hello world
|
|
||||||
`, nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(img.Config.Volumes) == 0 {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
for key := range img.Config.Volumes {
|
|
||||||
if key != "/test" {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildMaintainer(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
maintainer dockerio
|
|
||||||
`, nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if img.Author != "dockerio" {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildUser(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
user dockerio
|
|
||||||
`, nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if img.Config.User != "dockerio" {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildRelativeWorkdir(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
FROM {IMAGE}
|
|
||||||
RUN [ "$PWD" = '/' ]
|
|
||||||
WORKDIR test1
|
|
||||||
RUN [ "$PWD" = '/test1' ]
|
|
||||||
WORKDIR /test2
|
|
||||||
RUN [ "$PWD" = '/test2' ]
|
|
||||||
WORKDIR test3
|
|
||||||
RUN [ "$PWD" = '/test2/test3' ]
|
|
||||||
`, nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if img.Config.WorkingDir != "/test2/test3" {
|
|
||||||
t.Fatalf("Expected workdir to be '/test2/test3', received '%s'", img.Config.WorkingDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildEnv(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
env port 4243
|
|
||||||
`,
|
|
||||||
nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
hasEnv := false
|
|
||||||
for _, envVar := range img.Config.Env {
|
|
||||||
if envVar == "port=4243" {
|
|
||||||
hasEnv = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !hasEnv {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildCmd(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
cmd ["/bin/echo", "Hello World"]
|
|
||||||
`,
|
|
||||||
nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if img.Config.Cmd[0] != "/bin/echo" {
|
|
||||||
t.Log(img.Config.Cmd[0])
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
if img.Config.Cmd[1] != "Hello World" {
|
|
||||||
t.Log(img.Config.Cmd[1])
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildExpose(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
expose 4243
|
|
||||||
`,
|
|
||||||
nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := img.Config.ExposedPorts[nat.NewPort("tcp", "4243")]; !exists {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildEntrypoint(t *testing.T) {
|
|
||||||
img, err := buildImage(testContextTemplate{`
|
|
||||||
from {IMAGE}
|
|
||||||
entrypoint ["/bin/echo"]
|
|
||||||
`,
|
|
||||||
nil, nil}, t, nil, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if img.Config.Entrypoint[0] != "/bin/echo" {
|
|
||||||
t.Log(img.Config.Entrypoint[0])
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// testing #1405 - config.Cmd does not get cleaned up if
|
// testing #1405 - config.Cmd does not get cleaned up if
|
||||||
// utilizing cache
|
// utilizing cache
|
||||||
func TestBuildEntrypointRunCleanup(t *testing.T) {
|
func TestBuildEntrypointRunCleanup(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue