Skip to content

Commit 66a553a

Browse files
authored
Merge pull request #4259 from apostasie/2025-05-one-build-base
Use only one build base in Dockerfile
2 parents b7a46d6 + d166c3b commit 66a553a

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

Dockerfile

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ ARG KUBO_VERSION=v0.34.1
5555
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.6.1@sha256:923441d7c25f1e2eb5789f82d987693c47b8ed987c4ab3b075d6ed2b5d6779a3 AS xx
5656

5757

58-
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS build-base-debian
58+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS build-base
5959
COPY --from=xx / /
6060
ENV DEBIAN_FRONTEND=noninteractive
6161
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
62+
make \
6263
git \
64+
curl \
6365
dpkg-dev
6466
ARG TARGETARCH
6567
# libbtrfs: for containerd
@@ -74,53 +76,53 @@ RUN xx-apt-get update -qq && xx-apt-get install -qq --no-install-recommends \
7476
RUN git config --global advice.detachedHead false
7577
ADD hack/git-checkout-tag-with-hash.sh /usr/local/bin/
7678

77-
FROM build-base-debian AS build-containerd
79+
FROM build-base AS build-containerd
7880
ARG TARGETARCH
7981
ARG CONTAINERD_VERSION
80-
RUN git clone --quiet --depth 1 --branch "${CONTAINERD_VERSION%@*}" https://github.com/containerd/containerd.git /go/src/github.com/containerd/containerd
82+
RUN git clone --quiet --depth 1 --branch "${CONTAINERD_VERSION%%@*}" https://github.com/containerd/containerd.git /go/src/github.com/containerd/containerd
8183
WORKDIR /go/src/github.com/containerd/containerd
8284
RUN git-checkout-tag-with-hash.sh ${CONTAINERD_VERSION} && \
8385
mkdir -p /out /out/$TARGETARCH && \
8486
cp -a containerd.service /out
8587
RUN GO=xx-go make STATIC=1 && \
8688
cp -a bin/containerd bin/containerd-shim-runc-v2 bin/ctr /out/$TARGETARCH
8789

88-
FROM build-base-debian AS build-runc
90+
FROM build-base AS build-runc
8991
ARG RUNC_VERSION
9092
ARG TARGETARCH
91-
RUN git clone --quiet --depth 1 --branch "${RUNC_VERSION%@*}" https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc
93+
RUN git clone --quiet --depth 1 --branch "${RUNC_VERSION%%@*}" https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc
9294
WORKDIR /go/src/github.com/opencontainers/runc
9395
RUN git-checkout-tag-with-hash.sh ${RUNC_VERSION} && \
9496
mkdir -p /out
9597
ENV CGO_ENABLED=1
9698
RUN GO=xx-go CC=$(xx-info)-gcc STRIP=$(xx-info)-strip make static && \
9799
xx-verify --static runc && cp -v -a runc /out/runc.${TARGETARCH}
98100

99-
FROM build-base-debian AS build-bypass4netns
101+
FROM build-base AS build-bypass4netns
100102
ARG BYPASS4NETNS_VERSION
101103
ARG TARGETARCH
102-
RUN git clone --quiet --depth 1 --branch "${BYPASS4NETNS_VERSION%@*}" https://github.com/rootless-containers/bypass4netns.git /go/src/github.com/rootless-containers/bypass4netns
104+
RUN git clone --quiet --depth 1 --branch "${BYPASS4NETNS_VERSION%%@*}" https://github.com/rootless-containers/bypass4netns.git /go/src/github.com/rootless-containers/bypass4netns
103105
WORKDIR /go/src/github.com/rootless-containers/bypass4netns
104106
RUN git-checkout-tag-with-hash.sh ${BYPASS4NETNS_VERSION} && \
105107
mkdir -p /out/${TARGETARCH}
106108
ENV CGO_ENABLED=1
107109
RUN GO=xx-go make static && \
108110
xx-verify --static bypass4netns && cp -a bypass4netns bypass4netnsd /out/${TARGETARCH}
109111

110-
FROM build-base-debian AS build-gomodjail
112+
FROM build-base AS build-gomodjail
111113
ARG GOMODJAIL_VERSION
112114
ARG TARGETARCH
113-
RUN git clone --quiet --depth 1 --branch "${GOMODJAIL_VERSION%@*}" https://github.com/AkihiroSuda/gomodjail.git /go/src/github.com/AkihiroSuda/gomodjail
115+
RUN git clone --quiet --depth 1 --branch "${GOMODJAIL_VERSION%%@*}" https://github.com/AkihiroSuda/gomodjail.git /go/src/github.com/AkihiroSuda/gomodjail
114116
WORKDIR /go/src/github.com/AkihiroSuda/gomodjail
115117
RUN git-checkout-tag-with-hash.sh ${GOMODJAIL_VERSION} && \
116118
mkdir -p /out/${TARGETARCH}
117119
RUN GO=xx-go make STATIC=1 && \
118120
xx-verify --static _output/bin/gomodjail && cp -a _output/bin/gomodjail /out/${TARGETARCH}
119121

120-
FROM build-base-debian AS build-kubo
122+
FROM build-base AS build-kubo
121123
ARG KUBO_VERSION
122124
ARG TARGETARCH
123-
RUN git clone --quiet --depth 1 --branch "${KUBO_VERSION%@*}" https://github.com/ipfs/kubo.git /go/src/github.com/ipfs/kubo
125+
RUN git clone --quiet --depth 1 --branch "${KUBO_VERSION%%@*}" https://github.com/ipfs/kubo.git /go/src/github.com/ipfs/kubo
124126
WORKDIR /go/src/github.com/ipfs/kubo
125127
RUN git-checkout-tag-with-hash.sh ${KUBO_VERSION} && \
126128
mkdir -p /out/${TARGETARCH}
@@ -129,11 +131,6 @@ RUN xx-go --wrap && \
129131
make build && \
130132
xx-verify --static cmd/ipfs/ipfs && cp -a cmd/ipfs/ipfs /out/${TARGETARCH}
131133

132-
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build-base
133-
RUN apk add --no-cache make git curl
134-
RUN git config --global advice.detachedHead false
135-
ADD hack/git-checkout-tag-with-hash.sh /usr/local/bin/
136-
137134
FROM build-base AS build-minimal
138135
RUN BINDIR=/out/bin make binaries install
139136
# We do not set CMD to `go test` here, because it requires systemd
@@ -148,12 +145,12 @@ RUN mkdir -p /out/share/doc/nerdctl-full && touch /out/share/doc/nerdctl-full/RE
148145
ARG CONTAINERD_VERSION
149146
COPY --from=build-containerd /out/${TARGETARCH:-amd64}/* /out/bin/
150147
COPY --from=build-containerd /out/containerd.service /out/lib/systemd/system/containerd.service
151-
RUN echo "- containerd: ${CONTAINERD_VERSION/@*}" >> /out/share/doc/nerdctl-full/README.md
148+
RUN echo "- containerd: ${CONTAINERD_VERSION%%@*}" >> /out/share/doc/nerdctl-full/README.md
152149
ARG RUNC_VERSION
153150
COPY --from=build-runc /out/runc.${TARGETARCH:-amd64} /out/bin/runc
154-
RUN echo "- runc: ${RUNC_VERSION/@*}" >> /out/share/doc/nerdctl-full/README.md
151+
RUN echo "- runc: ${RUNC_VERSION%%@*}" >> /out/share/doc/nerdctl-full/README.md
155152
ARG CNI_PLUGINS_VERSION
156-
RUN CNI_PLUGINS_VERSION=${CNI_PLUGINS_VERSION/@BINARY}; \
153+
RUN CNI_PLUGINS_VERSION=${CNI_PLUGINS_VERSION%%@*}; \
157154
fname="cni-plugins-${TARGETOS:-linux}-${TARGETARCH:-amd64}-${CNI_PLUGINS_VERSION}.tgz" && \
158155
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/${fname}" && \
159156
grep "${fname}" "/SHA256SUMS.d/cni-plugins-${CNI_PLUGINS_VERSION}" | sha256sum -c && \
@@ -162,7 +159,7 @@ RUN CNI_PLUGINS_VERSION=${CNI_PLUGINS_VERSION/@BINARY}; \
162159
rm -f "${fname}" && \
163160
echo "- CNI plugins: ${CNI_PLUGINS_VERSION}" >> /out/share/doc/nerdctl-full/README.md
164161
ARG BUILDKIT_VERSION
165-
RUN BUILDKIT_VERSION=${BUILDKIT_VERSION/@BINARY}; \
162+
RUN BUILDKIT_VERSION=${BUILDKIT_VERSION%%@*}; \
166163
fname="buildkit-${BUILDKIT_VERSION}.${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
167164
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/moby/buildkit/releases/download/${BUILDKIT_VERSION}/${fname}" && \
168165
grep "${fname}" "/SHA256SUMS.d/buildkit-${BUILDKIT_VERSION}" | sha256sum -c && \
@@ -177,7 +174,7 @@ RUN cd /out/lib/systemd/system && \
177174
echo "" >> buildkit.service && \
178175
echo "# This file was converted from containerd.service, with \`sed -E '${sedcomm}'\`" >> buildkit.service
179176
ARG STARGZ_SNAPSHOTTER_VERSION
180-
RUN STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION/@BINARY}; \
177+
RUN STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION%%@*}; \
181178
fname="stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
182179
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containerd/stargz-snapshotter/releases/download/${STARGZ_SNAPSHOTTER_VERSION}/${fname}" && \
183180
curl -o "stargz-snapshotter.service" -fsSL --proto '=https' --tlsv1.2 "https://raw.githubusercontent.com/containerd/stargz-snapshotter/${STARGZ_SNAPSHOTTER_VERSION}/script/config/etc/systemd/system/stargz-snapshotter.service" && \
@@ -188,13 +185,13 @@ RUN STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION/@BINARY}; \
188185
mv stargz-snapshotter.service /out/lib/systemd/system/stargz-snapshotter.service && \
189186
echo "- Stargz Snapshotter: ${STARGZ_SNAPSHOTTER_VERSION}" >> /out/share/doc/nerdctl-full/README.md
190187
ARG IMGCRYPT_VERSION
191-
RUN git clone --quiet --depth 1 --branch "${IMGCRYPT_VERSION%@*}" https://github.com/containerd/imgcrypt.git /go/src/github.com/containerd/imgcrypt && \
188+
RUN git clone --quiet --depth 1 --branch "${IMGCRYPT_VERSION%%@*}" https://github.com/containerd/imgcrypt.git /go/src/github.com/containerd/imgcrypt && \
192189
cd /go/src/github.com/containerd/imgcrypt && \
193190
git-checkout-tag-with-hash.sh "${IMGCRYPT_VERSION}" && \
194191
CGO_ENABLED=0 make && DESTDIR=/out make install && \
195-
echo "- imgcrypt: ${IMGCRYPT_VERSION/@*}" >> /out/share/doc/nerdctl-full/README.md
192+
echo "- imgcrypt: ${IMGCRYPT_VERSION%%@*}" >> /out/share/doc/nerdctl-full/README.md
196193
ARG SLIRP4NETNS_VERSION
197-
RUN SLIRP4NETNS_VERSION=${SLIRP4NETNS_VERSION/@BINARY}; \
194+
RUN SLIRP4NETNS_VERSION=${SLIRP4NETNS_VERSION%%@*}; \
198195
fname="slirp4netns-$(cat /target_uname_m)" && \
199196
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/rootless-containers/slirp4netns/releases/download/${SLIRP4NETNS_VERSION}/${fname}" && \
200197
grep "${fname}" "/SHA256SUMS.d/slirp4netns-${SLIRP4NETNS_VERSION}" | sha256sum -c && \
@@ -203,40 +200,42 @@ RUN SLIRP4NETNS_VERSION=${SLIRP4NETNS_VERSION/@BINARY}; \
203200
echo "- slirp4netns: ${SLIRP4NETNS_VERSION}" >> /out/share/doc/nerdctl-full/README.md
204201
ARG BYPASS4NETNS_VERSION
205202
COPY --from=build-bypass4netns /out/${TARGETARCH:-amd64}/* /out/bin/
206-
RUN echo "- bypass4netns: ${BYPASS4NETNS_VERSION/@*}" >> /out/share/doc/nerdctl-full/README.md
203+
RUN echo "- bypass4netns: ${BYPASS4NETNS_VERSION%%@*}" >> /out/share/doc/nerdctl-full/README.md
207204
ARG FUSE_OVERLAYFS_VERSION
208-
RUN FUSE_OVERLAYFS_VERSION=${FUSE_OVERLAYFS_VERSION/@BINARY}; \
205+
RUN FUSE_OVERLAYFS_VERSION=${FUSE_OVERLAYFS_VERSION%%@*}; \
209206
fname="fuse-overlayfs-$(cat /target_uname_m)" && \
210207
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containers/fuse-overlayfs/releases/download/${FUSE_OVERLAYFS_VERSION}/${fname}" && \
211208
grep "${fname}" "/SHA256SUMS.d/fuse-overlayfs-${FUSE_OVERLAYFS_VERSION}" | sha256sum -c && \
212209
mv "${fname}" /out/bin/fuse-overlayfs && \
213210
chmod +x /out/bin/fuse-overlayfs && \
214211
echo "- fuse-overlayfs: ${FUSE_OVERLAYFS_VERSION}" >> /out/share/doc/nerdctl-full/README.md
215212
ARG CONTAINERD_FUSE_OVERLAYFS_VERSION
216-
RUN CONTAINERD_FUSE_OVERLAYFS_VERSION=${CONTAINERD_FUSE_OVERLAYFS_VERSION/@BINARY}; \
217-
fname="containerd-fuse-overlayfs-${CONTAINERD_FUSE_OVERLAYFS_VERSION/v}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
213+
RUN CONTAINERD_FUSE_OVERLAYFS_VERSION=${CONTAINERD_FUSE_OVERLAYFS_VERSION%%@*}; \
214+
fname="containerd-fuse-overlayfs-${CONTAINERD_FUSE_OVERLAYFS_VERSION##*v}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
218215
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containerd/fuse-overlayfs-snapshotter/releases/download/${CONTAINERD_FUSE_OVERLAYFS_VERSION}/${fname}" && \
219216
grep "${fname}" "/SHA256SUMS.d/containerd-fuse-overlayfs-${CONTAINERD_FUSE_OVERLAYFS_VERSION}" | sha256sum -c && \
220217
tar xzf "${fname}" -C /out/bin && \
221218
rm -f "${fname}" && \
222219
echo "- containerd-fuse-overlayfs: ${CONTAINERD_FUSE_OVERLAYFS_VERSION}" >> /out/share/doc/nerdctl-full/README.md
223220
ARG TINI_VERSION
224-
RUN TINI_VERSION=${TINI_VERSION/@BINARY}; \
221+
RUN TINI_VERSION=${TINI_VERSION%%@*}; \
225222
fname="tini-static-${TARGETARCH:-amd64}" && \
226223
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/${fname}" && \
227224
grep "${fname}" "/SHA256SUMS.d/tini-${TINI_VERSION}" | sha256sum -c && \
228225
cp -a "${fname}" /out/bin/tini && chmod +x /out/bin/tini && \
229226
echo "- Tini: ${TINI_VERSION}" >> /out/share/doc/nerdctl-full/README.md
230227
ARG BUILDG_VERSION
231-
RUN BUILDG_VERSION=${BUILDG_VERSION/@BINARY}; \
228+
# FIXME: this is a mildly-confusing approach. Buildkit will perform some "smart" replacement at build time and output
229+
# confusing debugging information, eg: BUILDG_VERSION will appear as if the original ARG value was used.
230+
RUN BUILDG_VERSION=${BUILDG_VERSION%%@*}; \
232231
fname="buildg-${BUILDG_VERSION}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
233232
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/ktock/buildg/releases/download/${BUILDG_VERSION}/${fname}" && \
234233
grep "${fname}" "/SHA256SUMS.d/buildg-${BUILDG_VERSION}" | sha256sum -c && \
235234
tar xzf "${fname}" -C /out/bin && \
236235
rm -f "${fname}" && \
237236
echo "- buildg: ${BUILDG_VERSION}" >> /out/share/doc/nerdctl-full/README.md
238237
ARG ROOTLESSKIT_VERSION
239-
RUN ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION/@BINARY}; \
238+
RUN ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION%%@*}; \
240239
fname="rootlesskit-$(cat /target_uname_m).tar.gz" && \
241240
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/rootless-containers/rootlesskit/releases/download/${ROOTLESSKIT_VERSION}/${fname}" && \
242241
grep "${fname}" "/SHA256SUMS.d/rootlesskit-${ROOTLESSKIT_VERSION}" | sha256sum -c && \
@@ -249,10 +248,10 @@ RUN echo "- gomodjail: ${GOMODJAIL_VERSION}" >> /out/share/doc/nerdctl-full/READ
249248

250249
RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
251250
echo "## License" >> /out/share/doc/nerdctl-full/README.md && \
252-
echo "- bin/slirp4netns: [GNU GENERAL PUBLIC LICENSE, Version 2](https://github.com/rootless-containers/slirp4netns/blob/${SLIRP4NETNS_VERSION/@*}/COPYING)" >> /out/share/doc/nerdctl-full/README.md && \
253-
echo "- bin/fuse-overlayfs: [GNU GENERAL PUBLIC LICENSE, Version 2](https://github.com/containers/fuse-overlayfs/blob/${FUSE_OVERLAYFS_VERSION/@*}/COPYING)" >> /out/share/doc/nerdctl-full/README.md && \
251+
echo "- bin/slirp4netns: [GNU GENERAL PUBLIC LICENSE, Version 2](https://github.com/rootless-containers/slirp4netns/blob/${SLIRP4NETNS_VERSION%%@*}/COPYING)" >> /out/share/doc/nerdctl-full/README.md && \
252+
echo "- bin/fuse-overlayfs: [GNU GENERAL PUBLIC LICENSE, Version 2](https://github.com/containers/fuse-overlayfs/blob/${FUSE_OVERLAYFS_VERSION%%@*}/COPYING)" >> /out/share/doc/nerdctl-full/README.md && \
254253
echo "- bin/{runc,bypass4netns,bypass4netnsd}: Apache License 2.0, statically linked with libseccomp ([LGPL 2.1](https://github.com/seccomp/libseccomp/blob/main/LICENSE), source code available at https://github.com/seccomp/libseccomp/)" >> /out/share/doc/nerdctl-full/README.md && \
255-
echo "- bin/tini: [MIT License](https://github.com/krallin/tini/blob/${TINI_VERSION/@*}/LICENSE)" >> /out/share/doc/nerdctl-full/README.md && \
254+
echo "- bin/tini: [MIT License](https://github.com/krallin/tini/blob/${TINI_VERSION%%@*}/LICENSE)" >> /out/share/doc/nerdctl-full/README.md && \
256255
echo "- Other files: [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)" >> /out/share/doc/nerdctl-full/README.md
257256

258257
FROM build-dependencies AS build-full
@@ -310,7 +309,7 @@ RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
310309
git \
311310
make
312311
# We wouldn't need this if Docker Hub could have "golang:${GO_VERSION}-ubuntu"
313-
COPY --from=build-base-debian /usr/local/go /usr/local/go
312+
COPY --from=build-base /usr/local/go /usr/local/go
314313
ARG TARGETARCH
315314
ENV PATH=/usr/local/go/bin:$PATH
316315
ARG GOTESTSUM_VERSION

0 commit comments

Comments
 (0)