...
1# syntax=docker/dockerfile:1
2
3ARG BASE_VARIANT=alpine
4ARG ALPINE_VERSION=3.18
5ARG BASE_DEBIAN_DISTRO=bookworm
6
7ARG GO_VERSION=1.21.8
8ARG XX_VERSION=1.2.1
9ARG GOVERSIONINFO_VERSION=v1.3.0
10ARG GOTESTSUM_VERSION=v1.10.0
11ARG BUILDX_VERSION=0.12.1
12ARG COMPOSE_VERSION=v2.24.3
13
14FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
15
16FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
17ENV GOTOOLCHAIN=local
18COPY --link --from=xx / /
19RUN apk add --no-cache bash clang lld llvm file git
20WORKDIR /go/src/github.com/docker/cli
21
22FROM build-base-alpine AS build-alpine
23ARG TARGETPLATFORM
24# gcc is installed for libgcc only
25RUN xx-apk add --no-cache musl-dev gcc
26
27FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO} AS build-base-debian
28ENV GOTOOLCHAIN=local
29COPY --link --from=xx / /
30RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld llvm file
31WORKDIR /go/src/github.com/docker/cli
32
33FROM build-base-debian AS build-debian
34ARG TARGETPLATFORM
35RUN xx-apt-get install --no-install-recommends -y libc6-dev libgcc-12-dev pkgconf
36
37FROM build-base-${BASE_VARIANT} AS goversioninfo
38ARG GOVERSIONINFO_VERSION
39RUN --mount=type=cache,target=/root/.cache/go-build \
40 --mount=type=cache,target=/go/pkg/mod \
41 GOBIN=/out GO111MODULE=on CGO_ENABLED=0 go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
42
43FROM build-base-${BASE_VARIANT} AS gotestsum
44ARG GOTESTSUM_VERSION
45RUN --mount=type=cache,target=/root/.cache/go-build \
46 --mount=type=cache,target=/go/pkg/mod \
47 GOBIN=/out GO111MODULE=on CGO_ENABLED=0 go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
48 && /out/gotestsum --version
49
50FROM build-${BASE_VARIANT} AS build
51# GO_LINKMODE defines if static or dynamic binary should be produced
52ARG GO_LINKMODE=static
53# GO_BUILDTAGS defines additional build tags
54ARG GO_BUILDTAGS
55# GO_STRIP strips debugging symbols if set
56ARG GO_STRIP
57# CGO_ENABLED manually sets if cgo is used
58ARG CGO_ENABLED
59# VERSION sets the version for the produced binary
60ARG VERSION
61# PACKAGER_NAME sets the company that produced the windows binary
62ARG PACKAGER_NAME
63COPY --link --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
64RUN --mount=type=bind,target=.,ro \
65 --mount=type=cache,target=/root/.cache \
66 --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
67 --mount=type=tmpfs,target=cli/winresources \
68 # override the default behavior of go with xx-go
69 xx-go --wrap && \
70 # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
71 TARGET=/out ./scripts/build/binary && \
72 xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
73
74FROM build-${BASE_VARIANT} AS test
75COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
76ENV GO111MODULE=auto
77RUN --mount=type=bind,target=.,rw \
78 --mount=type=cache,target=/root/.cache \
79 --mount=type=cache,target=/go/pkg/mod \
80 gotestsum -- -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '/vendor/|/e2e/')
81
82FROM scratch AS test-coverage
83COPY --from=test /tmp/coverage.txt /coverage.txt
84
85FROM build-${BASE_VARIANT} AS build-plugins
86ARG GO_LINKMODE=static
87ARG GO_BUILDTAGS
88ARG GO_STRIP
89ARG CGO_ENABLED
90ARG VERSION
91RUN --mount=ro --mount=type=cache,target=/root/.cache \
92 --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
93 xx-go --wrap && \
94 TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
95
96FROM build-base-alpine AS e2e-base-alpine
97RUN apk add --no-cache build-base curl openssl openssh-client
98
99FROM build-base-debian AS e2e-base-debian
100RUN apt-get update && apt-get install -y build-essential curl openssl openssh-client
101
102FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
103FROM docker/compose-bin:${COMPOSE_VERSION} AS compose
104
105FROM e2e-base-${BASE_VARIANT} AS e2e
106ARG NOTARY_VERSION=v0.6.1
107ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
108COPY --link e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert
109RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
110COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
111COPY --link --from=build /out ./build/
112COPY --link --from=build-plugins /out ./build/
113COPY --link --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
114COPY --link --from=compose /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
115COPY --link . .
116ENV DOCKER_BUILDKIT=1
117ENV PATH=/go/src/github.com/docker/cli/build:$PATH
118CMD ./scripts/test/e2e/entry
119
120FROM build-base-${BASE_VARIANT} AS dev
121COPY --link . .
122
123FROM scratch AS plugins
124COPY --from=build-plugins /out .
125
126FROM scratch AS bin-image
127COPY --from=build /out/docker /docker
128
129FROM scratch AS binary
130COPY --from=build /out .
View as plain text