Merge pull request #1550 from docker/local-test-cleanup

Local test cleanup
This commit is contained in:
Guillaume Tardif 2021-04-19 17:51:01 +02:00 committed by GitHub
commit 66f90098cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 60 additions and 75 deletions

View File

@ -12,24 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# BUILD
FROM ubuntu:latest
# Update and upgrade repo
RUN apt-get update -y -q && apt-get upgrade -y -q
# Install tools we might need
RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y -q curl build-essential ca-certificates git
# Download Go 1.2.2 and install it to /usr/local/go
RUN curl -s https://storage.googleapis.com/golang/go1.2.2.linux-amd64.tar.gz| tar -v -C /usr/local -xz
# Let's people find our Go binaries
ENV PATH $PATH:/usr/local/go/bin
FROM golang:1.16-alpine AS build
COPY dispatcher.go .
RUN go build dispatcher.go
RUN mkdir -p /out && go build -o /out/dispatcher dispatcher.go
FROM alpine AS run
EXPOSE 80
CMD ["/dispatcher"]
COPY static /static/
COPY --from=build /out/dispatcher /dispatcher

View File

@ -18,7 +18,7 @@
FROM golang:1.16-alpine AS build
COPY main.go .
RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o server main.go
go build -trimpath -ldflags="-s -w" -o server main.go
FROM alpine
RUN apk --no-cache add curl

View File

@ -145,7 +145,7 @@ func TestAttachRestart(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
defer c.RunDockerCmd("compose", "-p", "attach-restart", "down")
defer c.RunDockerOrExitError("compose", "-p", "attach-restart", "down")
output := res.Stdout()
exitRegex := regexp.MustCompile("another_1 exited with code 1")
@ -159,7 +159,7 @@ func TestInitContainer(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/init-container", "up")
defer c.RunDockerCmd("compose", "-p", "init-container", "down")
defer c.RunDockerOrExitError("compose", "-p", "init-container", "down")
output := res.Stdout()
assert.Assert(t, strings.Contains(output, "foo_1 | hello\nbar_1 | world"), res.Combined())

View File

@ -1,9 +1,9 @@
services:
simple:
image: busybox:1.31.0-uclibc
image: alpine
command: sh -c "sleep 5"
another:
image: busybox:1.31.0-uclibc
image: alpine
command: sh -c "sleep 0.1 && echo world && /bin/false"
deploy:
restart_policy:

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM nginx
FROM nginx:alpine
ARG FOO
LABEL FOO=$FOO

View File

@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM nginx
FROM nginx:alpine
COPY static2 /usr/share/nginx/html

View File

@ -1,7 +1,7 @@
services:
should_fail:
image: busybox:1.27.2
image: alpine
command: ls /does_not_exist
sleep: # will be killed
image: busybox:1.27.2
image: alpine
command: ping localhost

View File

@ -1,13 +1,13 @@
services:
service:
image: busybox
image: alpine
command: top
ipc: "service:shareable"
container:
image: busybox
image: alpine
command: top
ipc: "container:ipc_mode_container"
shareable:
image: busybox
image: alpine
command: top
ipc: shareable

View File

@ -1,7 +1,7 @@
services:
ping:
image: busybox:1.27.2
image: alpine
command: ping localhost -c 1
hello:
image: busybox:1.31.0-uclibc
image: alpine
command: echo hello

View File

@ -1,6 +1,6 @@
services:
mydb:
image: mysql
image: mariadb
network_mode: "service:db"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes

View File

@ -1,4 +1,4 @@
services:
restart:
image: busybox
image: alpine
command: ash -c "if [[ -f /tmp/restart.lock ]] ; then sleep infinity; else touch /tmp/restart.lock; fi"

View File

@ -8,13 +8,13 @@ services:
networks:
- backnet
db:
image: nginx
image: nginx:alpine
networks:
- backnet
volumes:
- data:/test
front:
image: nginx
image: nginx:alpine
networks:
- frontnet
networks:

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM nginx
FROM nginx:alpine
ARG FOO
LABEL FOO=$FOO

View File

@ -1,7 +1,7 @@
services:
simple:
image: busybox:1.27.2
image: alpine
command: top
another:
image: busybox:1.31.0-uclibc
image: alpine
command: top

View File

@ -1,5 +1,5 @@
services:
simple:
image: nginx
image: nginx:alpine
another:
image: nginx
image: nginx:alpine

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM nginx
FROM nginx:alpine

View File

@ -1,4 +1,4 @@
services:
simple:
image: nginx
image: nginx:alpine
wrongField: test

View File

@ -32,7 +32,7 @@ func TestIPC(t *testing.T) {
const projectName = "ipc_e2e"
var cid string
t.Run("create ipc mode container", func(t *testing.T) {
res := c.RunDockerCmd("run", "-d", "--rm", "--ipc=shareable", "--name", "ipc_mode_container", "busybox", "top")
res := c.RunDockerCmd("run", "-d", "--rm", "--ipc=shareable", "--name", "ipc_mode_container", "alpine", "top")
cid = strings.Trim(res.Stdout(), "\n")
})

View File

@ -42,23 +42,23 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
t.Run("display when docker build", func(t *testing.T) {
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/simple-build-test/nginx-build")
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg")
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg")
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
})
t.Run("do not display with docker build and quiet flag", func(t *testing.T) {
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg-quiet", "--quiet", "./fixtures/simple-build-test/nginx-build")
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg-quiet")
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg-quiet")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"))
res = c.RunDockerCmd("build", "-t", "test-image-scan-msg-q", "-q", "./fixtures/simple-build-test/nginx-build")
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg-q")
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg-q")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"))
})
t.Run("do not display if envvar DOCKER_SCAN_SUGGEST=false", func(t *testing.T) {
cmd := c.NewDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/build-test/nginx-build")
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg")
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg")
cmd.Env = append(cmd.Env, "DOCKER_SCAN_SUGGEST=false")
res := icmd.StartCmd(cmd)
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
@ -66,7 +66,7 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
t.Run("display on compose build", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test-compose-build", "build")
defer c.RunDockerCmd("rmi", "-f", "scan-msg-test-compose-build_nginx")
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-compose-build_nginx")
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
})
@ -77,7 +77,7 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
assert.Assert(t, !strings.Contains(res.Combined(), "No such image"))
res = c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test-q", "build", "-q")
defer c.RunDockerCmd("rmi", "-f", "scan-msg-test-q_nginx")
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-q_nginx")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
})
@ -85,13 +85,13 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
t.Run("display on compose up if image is built", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
defer c.RunDockerOrExitError("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
})
t.Run("do not display on compose up if no image built", func(t *testing.T) { // re-run the same Compose aproject
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down", "--rmi", "all")
defer c.RunDockerOrExitError("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down", "--rmi", "all")
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
})

View File

@ -44,55 +44,52 @@ func TestStartStop(t *testing.T) {
}
t.Run("Up a project", func(t *testing.T) {
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "up", "-d")
assert.Assert(t, strings.Contains("Container e2e-start-stop_simple_1 Started", res.Stdout()), res.Stdout())
res := c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "up", "-d")
assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop_simple_1 Started"), res.Combined())
res = c.RunDockerOrExitError("compose", "ls", "--all")
res = c.RunDockerCmd("compose", "ls", "--all")
testify.Regexp(t, getProjectRegx("running"), res.Stdout())
res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps")
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps")
testify.Regexp(t, getServiceRegx("simple", "running"), res.Stdout())
testify.Regexp(t, getServiceRegx("another", "running"), res.Stdout())
})
t.Run("stop project", func(t *testing.T) {
c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "stop")
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "stop")
res := c.RunDockerOrExitError("compose", "ls")
assert.Assert(t, !strings.Contains("e2e-start-stop", res.Combined()), res.Combined())
res := c.RunDockerCmd("compose", "ls")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop"), res.Combined())
res = c.RunDockerOrExitError("compose", "ls", "--all")
res = c.RunDockerCmd("compose", "ls", "--all")
testify.Regexp(t, getProjectRegx("exited"), res.Stdout())
res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps")
assert.Assert(t, !strings.Contains("e2e-start-stop_words_1", res.Combined()), res.Combined())
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop_words_1"), res.Combined())
res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps", "--all")
res = c.RunDockerCmd("compose", "--project-name", projectName, "ps", "--all")
testify.Regexp(t, getServiceRegx("simple", "exited"), res.Stdout())
testify.Regexp(t, getServiceRegx("another", "exited"), res.Stdout())
})
t.Run("start project", func(t *testing.T) {
c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "start")
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "start")
res := c.RunDockerOrExitError("compose", "ls")
res := c.RunDockerCmd("compose", "ls")
testify.Regexp(t, getProjectRegx("running"), res.Stdout())
})
t.Run("pause project", func(t *testing.T) {
c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "pause")
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "pause")
res := c.RunDockerOrExitError("compose", "ls")
assert.Assert(t, !strings.Contains("e2e-start-stop", res.Combined()), res.Combined())
res = c.RunDockerOrExitError("compose", "ls", "--all")
res := c.RunDockerCmd("compose", "ls", "--all")
testify.Regexp(t, getProjectRegx("paused"), res.Stdout())
})
t.Run("unpause project", func(t *testing.T) {
c.RunDockerOrExitError("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "unpause")
c.RunDockerCmd("compose", "-f", "./fixtures/start-stop/compose.yml", "--project-name", projectName, "unpause")
res := c.RunDockerOrExitError("compose", "ls")
res := c.RunDockerCmd("compose", "ls")
testify.Regexp(t, getProjectRegx("running"), res.Stdout())
})

View File

@ -53,7 +53,7 @@ func TestLocalBackendRun(t *testing.T) {
t.Run("run", func(t *testing.T) {
t.Parallel()
res := c.RunDockerCmd("run", "-d", "nginx")
res := c.RunDockerCmd("run", "-d", "nginx:alpine")
containerName := strings.TrimSpace(res.Combined())
t.Cleanup(func() {
_ = c.RunDockerOrExitError("rm", "-f", containerName)
@ -64,7 +64,7 @@ func TestLocalBackendRun(t *testing.T) {
t.Run("run rm", func(t *testing.T) {
t.Parallel()
res := c.RunDockerCmd("run", "--rm", "-d", "nginx")
res := c.RunDockerCmd("run", "--rm", "-d", "nginx:alpine")
containerName := strings.TrimSpace(res.Combined())
t.Cleanup(func() {
_ = c.RunDockerOrExitError("rm", "-f", containerName)
@ -81,7 +81,7 @@ func TestLocalBackendRun(t *testing.T) {
})
t.Run("run with ports", func(t *testing.T) {
res := c.RunDockerCmd("run", "-d", "-p", "85:80", "nginx")
res := c.RunDockerCmd("run", "-d", "-p", "85:80", "nginx:alpine")
containerName := strings.TrimSpace(res.Combined())
t.Cleanup(func() {
_ = c.RunDockerOrExitError("rm", "-f", containerName)
@ -101,7 +101,7 @@ func TestLocalBackendRun(t *testing.T) {
fields := strings.Fields(line)
if fields[0] == nginxID {
nginxFound = true
assert.Equal(t, fields[1], "nginx", res.Combined())
assert.Equal(t, fields[1], "nginx:alpine", res.Combined())
assert.Equal(t, fields[2], "/docker-entrypoint.sh", res.Combined())
assert.Equal(t, fields[len(fields)-1], "0.0.0.0:85->80/tcp", res.Combined())
}
@ -109,7 +109,7 @@ func TestLocalBackendRun(t *testing.T) {
assert.Assert(t, nginxFound, res.Stdout())
res = c.RunDockerCmd("ps", "--format", "json")
res.Assert(t, icmd.Expected{Out: `"Image":"nginx","Status":"Up Less than a second","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Ports":["0.0.0.0:85->80/tcp"`})
res.Assert(t, icmd.Expected{Out: `"Image":"nginx:alpine","Status":"Up Less than a second","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Ports":["0.0.0.0:85->80/tcp"`})
res = c.RunDockerCmd("ps", "--quiet")
res.Assert(t, icmd.Expected{Out: nginxID + "\n"})