From 0deb18ab42094f897d9996aa23fabe3c6a76a67f Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 27 Apr 2019 04:38:55 +0000 Subject: [PATCH 1/2] Dockerfile.e2e: copy test sources Package "gotest.tools/assert" uses source introspection to print more info in case of assertion failure. When source code is not available, it prints an error instead. In other words, before this commit: > --- SKIP: TestCgroupDriverSystemdMemoryLimit (0.00s) > cgroupdriver_systemd_test.go:32: failed to parse source file: /go/src/github.com/docker/docker/integration/system/cgroupdriver_systemd_test.go: open /go/src/github.com/docker/docker/integration/system/cgroupdriver_systemd_test.go: no such file or directory > cgroupdriver_systemd_test.go:32: and after: > --- SKIP: TestCgroupDriverSystemdMemoryLimit (0.09s) > cgroupdriver_systemd_test.go:32: !hasSystemd() This increases the resulting image size by about 2 MB on my system (from 758 to 760 MB). Signed-off-by: Kir Kolyshkin --- Dockerfile.e2e | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index d1bd9a37c1..a1b5ab7934 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -43,8 +43,11 @@ FROM base AS builder ARG DOCKER_GITCOMMIT ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT:-undefined} COPY . . +# Copy test sources tests that use assert can print errors +RUN mkdir -p /build${PWD} && find integration integration-cli -name \*_test.go -exec cp --parents '{}' /build${PWD} \; +# Build and install test binaries RUN hack/make.sh build-integration-test-binary -RUN mkdir -p /build/ && find . -name test.main -exec cp --parents '{}' /build \; +RUN mkdir -p /build/tests && find . -name test.main -exec cp --parents '{}' /build/tests \; ## Generate testing image FROM alpine:3.9 as runner @@ -77,4 +80,4 @@ COPY integration-cli/fixtures /tests/integration-cli/fixtures COPY --from=frozen-images /build/ /docker-frozen-images COPY --from=dockercli /build/ /usr/bin/ COPY --from=contrib /build/ /tests/contrib/ -COPY --from=builder /build/ /tests/ +COPY --from=builder /build/ / From c3b24944ca10edb835de6e806ad6cd9e952ebc11 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 30 Apr 2019 00:22:22 -0700 Subject: [PATCH 2/2] Dockerfile.e2e: fix DOCKER_GITCOMMIT handling 1. There is no need to persist DOCKER_GITCOMMIT, as it's not needed for runtime, only for build. So, remove ENV. 2. In case $GITCOMMIT is not defined during build time (and it happens if .git directory is not present), we still need to have some value set, so set it to `undefined`. Otherwise we'll have something like > => ERROR [builder 2/3] RUN hack/make.sh build-integration-test-binary > ------ > > [builder 2/3] RUN hack/make.sh build-integration-test-binary: > #32 0.488 > #32 0.505 error: .git directory missing and DOCKER_GITCOMMIT not specified > #32 0.505 Please either build with the .git directory accessible, or specify the > #32 0.505 exact (--short) commit hash you are building using DOCKER_GITCOMMIT for > #32 0.505 future accountability in diagnosing build issues. Thanks! Signed-off-by: Kir Kolyshkin --- Dockerfile.e2e | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index a1b5ab7934..261ebd0253 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -40,12 +40,11 @@ RUN CGO_ENABLED=0 go build -buildmode=pie -o /build/httpserver/httpserver github FROM base AS builder # Set tag and add sources -ARG DOCKER_GITCOMMIT -ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT:-undefined} COPY . . # Copy test sources tests that use assert can print errors RUN mkdir -p /build${PWD} && find integration integration-cli -name \*_test.go -exec cp --parents '{}' /build${PWD} \; # Build and install test binaries +ARG DOCKER_GITCOMMIT=undefined RUN hack/make.sh build-integration-test-binary RUN mkdir -p /build/tests && find . -name test.main -exec cp --parents '{}' /build/tests \;