From 9d13cbae070e6716cbfd93680282d13ea375e1ed Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Wed, 6 Sep 2023 17:42:12 -0400 Subject: [PATCH] test: add a fully containerized (via Compose) e2e setup `dind.compose.yaml` has a Docker-in-Docker setup, which is then referenced via `include` in `e2e.compose.yaml`. Not all tests currently pass, as some rely on bind mounts, for example. Signed-off-by: Milas Bowman --- Dockerfile | 30 ++++++++++++++++++++++++++ dind.compose.yaml | 55 +++++++++++++++++++++++++++++++++++++++++++++++ e2e.compose.yaml | 17 +++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 dind.compose.yaml create mode 100644 e2e.compose.yaml diff --git a/Dockerfile b/Dockerfile index c282f758e8..13b1ed33b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 / / @@ -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 \ diff --git a/dind.compose.yaml b/dind.compose.yaml new file mode 100644 index 0000000000..44447500f9 --- /dev/null +++ b/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: diff --git a/e2e.compose.yaml b/e2e.compose.yaml new file mode 100644 index 0000000000..e4a05d6010 --- /dev/null +++ b/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