Debian Codegraph @

cli/Dockerfile

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