Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add a fully containerized (via Compose) e2e setup #10980

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions Dockerfile
Expand Up @@ -32,6 +32,15 @@ FROM crazymax/osxcross:11.3-alpine AS osxcross

FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
FROM docker.io/curlimages/curl AS curl

FROM --platform=${BUILDPLATFORM} alpine AS gotestsum

ARG TARGETARCH
ARG GOTESTSUM_VERSION=1.10.1
ADD https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_${TARGETARCH}.tar.gz /tmp/
RUN mkdir /out && \
tar xzf /tmp/gotestsum_${GOTESTSUM_VERSION}_linux_arm64.tar.gz -C /out

FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base
COPY --from=xx / /
Expand Down Expand Up @@ -112,6 +121,27 @@ RUN --mount=type=bind,target=. \
FROM scratch AS test-coverage
COPY --from=test --link /tmp/coverage /

FROM build-base AS e2e-build

RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
go test -c -o /out/compose.e2e.test --tags=standalone ./pkg/e2e

FROM base AS e2e

COPY --link --from=curl /usr/bin/curl /usr/local/bin/
COPY --link --from=gotestsum /out/gotestsum /usr/local/bin/

USER 1000
ENV USER=moby
COPY --link --from=build /out/docker-compose /src/bin/build/
COPY ./pkg/e2e /src/pkg/e2e
COPY --link --from=e2e-build /out/compose.e2e.test /src/pkg/e2e/

WORKDIR /src/pkg/e2e
CMD gotestsum --format=testname --raw-command -- go tool test2json -t -p e2e ./compose.e2e.test -test.v -test.count=1 -test.parallel=1

FROM base AS license-set
ARG LICENSE_FILES
RUN --mount=type=bind,target=.,rw \
Expand Down
55 changes: 55 additions & 0 deletions dind.compose.yaml
@@ -0,0 +1,55 @@
services:
docker:
image: ${DIND_IMAGE:-docker.io/docker}:${DIND_TAG:-git}
privileged: true
environment:
DOCKER_TLS_CERTDIR: /certs
volumes:
- type: volume
source: dind-sock
target: /var/run
- type: volume
source: dind-certs-ca
target: /certs/ca
- type: volume
source: dind-certs-client
target: /certs/client
networks: [dind]
healthcheck:
test: ["CMD", "docker", "version", "--format='{{ .Server.Version }}'"]
interval: 1s
# start_interval: 1s
start_period: 15s
timeout: 5s

cli-sock:
image: ${DIND_IMAGE:-docker.io/docker}:${DIND_CLI_TAG:-cli}
command: ["docker", "version"]
volumes:
- type: volume
source: dind-sock
target: /var/run
depends_on:
docker:
condition: service_healthy
cli-tls:
image: ${DIND_IMAGE:-docker.io/docker}:${DIND_CLI_TAG:-cli}
environment:
DOCKER_TLS_CERTDIR: /certs
volumes:
- type: volume
source: dind-certs-client
target: /certs/client
command: [ "docker", "version" ]
depends_on:
docker:
condition: service_healthy
networks: [dind]

volumes:
dind-certs-ca:
dind-certs-client:
dind-sock:

networks:
dind:
17 changes: 17 additions & 0 deletions e2e.compose.yaml
@@ -0,0 +1,17 @@
include:
- ./dind.compose.yaml

services:
e2e:
pull_policy: build
build:
context: .
target: e2e
volumes:
- type: volume
source: dind-sock
target: /var/run
network_mode: service:docker
depends_on:
docker:
condition: service_healthy