# syntax=docker/dockerfile:1 ARG GO_VERSION=1.20.7 ARG XX_VERSION=1.2.1 ARG DOCKER_VERSION=24.0.2 ARG GOTESTSUM_VERSION=v1.9.0 ARG REGISTRY_VERSION=2.8.0 ARG BUILDKIT_VERSION=v0.11.6 # xx is a helper for cross-compilation FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest FROM golatest AS gobase COPY --from=xx / / RUN apk add --no-cache file git ENV GOFLAGS=-mod=vendor ENV CGO_ENABLED=0 WORKDIR /src FROM registry:$REGISTRY_VERSION AS registry FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit FROM gobase AS docker ARG TARGETPLATFORM ARG DOCKER_VERSION WORKDIR /opt/docker RUN DOCKER_ARCH=$(case ${TARGETPLATFORM:-linux/amd64} in \ "linux/amd64") echo "x86_64" ;; \ "linux/arm/v6") echo "armel" ;; \ "linux/arm/v7") echo "armhf" ;; \ "linux/arm64") echo "aarch64" ;; \ "linux/ppc64le") echo "ppc64le" ;; \ "linux/s390x") echo "s390x" ;; \ *) echo "" ;; esac) \ && echo "DOCKER_ARCH=$DOCKER_ARCH" \ && wget -qO- "https://download.docker.com/linux/static/stable/${DOCKER_ARCH}/docker-${DOCKER_VERSION}.tgz" | tar xvz --strip 1 RUN ./dockerd --version && ./containerd --version && ./ctr --version && ./runc --version FROM gobase AS gotestsum ARG GOTESTSUM_VERSION ENV GOFLAGS= RUN --mount=target=/root/.cache,type=cache \ GOBIN=/out/ go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" && \ /out/gotestsum --version FROM gobase AS buildx-version RUN --mount=type=bind,target=. <