Debian Codegraph @

Dockerfile

raw
1 # syntax=docker/dockerfile:1
2
3 ARG GO_VERSION=1.24
4 ARG ALPINE_VERSION=3.22
5 ARG XX_VERSION=1.6.1
6
7 # for testing
8 ARG DOCKER_VERSION=28.4
9 ARG DOCKER_VERSION_ALT_27=27.5.1
10 ARG DOCKER_VERSION_ALT_26=26.1.3
11 ARG DOCKER_CLI_VERSION=${DOCKER_VERSION}
12 ARG GOTESTSUM_VERSION=v1.12.0
13 ARG REGISTRY_VERSION=3.0.0
14 ARG BUILDKIT_VERSION=v0.24.0
15 ARG COMPOSE_VERSION=v2.39.1
16 ARG UNDOCK_VERSION=0.9.0
17
18 FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
19 FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest
20 FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine
21 FROM dockereng/cli-bin:$DOCKER_CLI_VERSION AS docker-cli
22 FROM moby/moby-bin:$DOCKER_VERSION_ALT_27 AS docker-engine-alt27
23 FROM moby/moby-bin:$DOCKER_VERSION_ALT_26 AS docker-engine-alt26
24 FROM dockereng/cli-bin:$DOCKER_VERSION_ALT_27 AS docker-cli-alt27
25 FROM dockereng/cli-bin:$DOCKER_VERSION_ALT_26 AS docker-cli-alt26
26 FROM registry:$REGISTRY_VERSION AS registry
27 FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit
28 FROM docker/compose-bin:$COMPOSE_VERSION AS compose
29 FROM crazymax/undock:$UNDOCK_VERSION AS undock
30
31 FROM golatest AS gobase
32 COPY --from=xx / /
33 RUN apk add --no-cache file git
34 ENV GOFLAGS=-mod=vendor
35 ENV CGO_ENABLED=0
36 WORKDIR /src
37
38 FROM gobase AS gotestsum
39 ARG GOTESTSUM_VERSION
40 ENV GOFLAGS=""
41 RUN --mount=target=/root/.cache,type=cache <<EOT
42 set -ex
43 go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}"
44 go install "github.com/wadey/gocovmerge@latest"
45 mkdir /out
46 /go/bin/gotestsum --version
47 mv /go/bin/gotestsum /out
48 mv /go/bin/gocovmerge /out
49 EOT
50 COPY --chmod=755 <<"EOF" /out/gotestsumandcover
51 #!/bin/sh
52 set -x
53 if [ -z "$GO_TEST_COVERPROFILE" ]; then
54 exec gotestsum "$@"
55 fi
56 coverdir="$(dirname "$GO_TEST_COVERPROFILE")"
57 mkdir -p "$coverdir/helpers"
58 gotestsum "$@" "-coverprofile=$GO_TEST_COVERPROFILE"
59 ecode=$?
60 go tool covdata textfmt -i=$coverdir/helpers -o=$coverdir/helpers-report.txt
61 gocovmerge "$coverdir/helpers-report.txt" "$GO_TEST_COVERPROFILE" > "$coverdir/merged-report.txt"
62 mv "$coverdir/merged-report.txt" "$GO_TEST_COVERPROFILE"
63 rm "$coverdir/helpers-report.txt"
64 for f in "$coverdir/helpers"/*; do
65 rm "$f"
66 done
67 rmdir "$coverdir/helpers"
68 exit $ecode
69 EOF
70
71 FROM gobase AS buildx-version
72 RUN --mount=type=bind,target=. <<EOT
73 set -e
74 mkdir /buildx-version
75 echo -n "$(./hack/git-meta version)" | tee /buildx-version/version
76 echo -n "$(./hack/git-meta revision)" | tee /buildx-version/revision
77 EOT
78
79 FROM gobase AS buildx-build
80 ARG TARGETPLATFORM
81 ARG GO_EXTRA_FLAGS
82 RUN --mount=type=bind,target=. \
83 --mount=type=cache,target=/root/.cache \
84 --mount=type=cache,target=/go/pkg/mod \
85 --mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
86 set -e
87 xx-go --wrap
88 DESTDIR=/usr/bin VERSION=$(cat /buildx-version/version) REVISION=$(cat /buildx-version/revision) GO_EXTRA_LDFLAGS="-s -w" ./hack/build
89 file /usr/bin/docker-buildx
90 xx-verify --static /usr/bin/docker-buildx
91 EOT
92
93 FROM gobase AS test
94 ENV SKIP_INTEGRATION_TESTS=1
95 RUN --mount=type=bind,target=. \
96 --mount=type=cache,target=/root/.cache \
97 --mount=type=cache,target=/go/pkg/mod \
98 go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./... && \
99 go tool cover -func=/tmp/coverage.txt
100
101 FROM scratch AS test-coverage
102 COPY --from=test /tmp/coverage.txt /coverage.txt
103
104 FROM scratch AS binaries-unix
105 COPY --link --from=buildx-build /usr/bin/docker-buildx /buildx
106
107 FROM binaries-unix AS binaries-darwin
108 FROM binaries-unix AS binaries-freebsd
109 FROM binaries-unix AS binaries-linux
110 FROM binaries-unix AS binaries-netbsd
111 FROM binaries-unix AS binaries-openbsd
112
113 FROM scratch AS binaries-windows
114 COPY --link --from=buildx-build /usr/bin/docker-buildx /buildx.exe
115
116 FROM binaries-$TARGETOS AS binaries
117 # enable scanning for this stage
118 ARG BUILDKIT_SBOM_SCAN_STAGE=true
119
120 FROM gobase AS integration-test-base
121 # https://github.com/docker/docker/blob/master/project/PACKAGERS.md#runtime-dependencies
122 RUN apk add --no-cache \
123 btrfs-progs \
124 e2fsprogs \
125 e2fsprogs-extra \
126 ip6tables \
127 iptables \
128 openssl \
129 shadow-uidmap \
130 xfsprogs \
131 xz
132 COPY --link --from=gotestsum /out /usr/bin/
133 COPY --link --from=registry /bin/registry /usr/bin/
134 COPY --link --from=docker-engine / /usr/bin/
135 COPY --link --from=docker-cli / /usr/bin/
136 COPY --link --from=docker-engine-alt27 / /opt/docker-alt-27/
137 COPY --link --from=docker-engine-alt26 / /opt/docker-alt-26/
138 COPY --link --from=docker-cli-alt27 / /opt/docker-alt-27/
139 COPY --link --from=docker-cli-alt26 / /opt/docker-alt-26/
140 COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/
141 COPY --link --from=buildkit /usr/bin/buildctl /usr/bin/
142 COPY --link --from=compose /docker-compose /usr/bin/compose
143 COPY --link --from=undock /usr/local/bin/undock /usr/bin/
144 COPY --link --from=binaries /buildx /usr/bin/
145 RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx
146 ENV TEST_DOCKER_EXTRA="[email protected]=/opt/docker-alt-27,[email protected]=/opt/docker-alt-26"
147
148 FROM integration-test-base AS integration-test
149 COPY . .
150
151 # Release
152 FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS releaser
153 WORKDIR /work
154 ARG TARGETPLATFORM
155 RUN --mount=from=binaries \
156 --mount=type=bind,from=buildx-version,source=/buildx-version,target=/buildx-version <<EOT
157 set -e
158 mkdir -p /out
159 cp buildx* "/out/buildx-$(cat /buildx-version/version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')"
160 EOT
161
162 FROM scratch AS release
163 COPY --from=releaser /out/ /
164
165 # Shell
166 FROM docker:$DOCKER_VERSION AS dockerd-release
167 FROM alpine:${ALPINE_VERSION} AS shell
168 RUN apk add --no-cache iptables tmux git vim less openssh
169 RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/local/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx
170 COPY ./hack/demo-env/entrypoint.sh /usr/local/bin
171 COPY ./hack/demo-env/tmux.conf /root/.tmux.conf
172 COPY --from=dockerd-release /usr/local/bin /usr/local/bin
173 WORKDIR /work
174 COPY ./hack/demo-env/examples .
175 COPY --from=binaries / /usr/local/bin/
176 VOLUME /var/lib/docker
177 ENTRYPOINT ["entrypoint.sh"]
178
179 FROM binaries