Skip to content

Commit 3eed13d

Browse files
authored
Merge pull request moby#5187 from crazy-max/dockerfile-add
dockerfile: use ADD for fetching sources
2 parents 1a640be + d93b829 commit 3eed13d

File tree

1 file changed

+24
-54
lines changed

1 file changed

+24
-54
lines changed

Dockerfile

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
3232
# go base image
3333
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest
3434

35-
# git stage is used for checking out remote repository sources
36-
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS git
37-
RUN apk add --no-cache git
38-
3935
# gobuild is base stage for compiling go/cgo
4036
FROM golatest AS gobuild-base
4137
RUN apk add --no-cache file bash clang lld musl-dev pkgconfig git make
@@ -48,23 +44,17 @@ RUN --mount=target=/root/.cache,type=cache \
4844
--mount=target=/go/pkg/mod,type=cache \
4945
GOBIN=/usr/bin go install github.com/go-delve/delve/cmd/dlv@${DELVE_VERSION}
5046

51-
# runc source
52-
FROM git AS runc-src
53-
ARG RUNC_VERSION
54-
WORKDIR /usr/src
55-
RUN git clone https://github.com/opencontainers/runc.git runc \
56-
&& cd runc && git checkout -q "$RUNC_VERSION"
57-
5847
# build runc binary
5948
FROM gobuild-base AS runc
6049
WORKDIR $GOPATH/src/github.com/opencontainers/runc
50+
ARG RUNC_VERSION
51+
ADD --keep-git-dir=true "https://github.com/opencontainers/runc.git#$RUNC_VERSION" .
6152
ARG TARGETPLATFORM
6253
# gcc is only installed for libgcc
6354
# lld has issues building static binaries for ppc so prefer ld for it
6455
RUN set -e; xx-apk add musl-dev gcc libseccomp-dev libseccomp-static; \
6556
[ "$(xx-info arch)" != "ppc64le" ] || XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple
66-
RUN --mount=from=runc-src,src=/usr/src/runc,target=. \
67-
--mount=target=/root/.cache,type=cache <<EOT
57+
RUN --mount=target=/root/.cache,type=cache <<EOT
6858
set -ex
6959
CGO_ENABLED=1 xx-go build -mod=vendor -ldflags '-extldflags -static' -tags 'apparmor seccomp netgo cgo static_build osusergo' -o /usr/bin/runc ./
7060
xx-verify --static /usr/bin/runc
@@ -139,19 +129,13 @@ RUN --mount=target=. --mount=target=/root/.cache,type=cache \
139129
fi
140130
EOT
141131

142-
# dnsname source
143-
FROM git AS dnsname-src
144-
ARG DNSNAME_VERSION
145-
WORKDIR /usr/src
146-
RUN git clone https://github.com/containers/dnsname.git dnsname \
147-
&& cd dnsname && git checkout -q "$DNSNAME_VERSION"
148-
149132
# build dnsname CNI plugin for testing
150133
FROM gobuild-base AS dnsname
151134
WORKDIR /go/src/github.com/containers/dnsname
135+
ARG DNSNAME_VERSION
136+
ADD --keep-git-dir=true "https://github.com/containers/dnsname.git#$DNSNAME_VERSION" .
152137
ARG TARGETPLATFORM
153-
RUN --mount=from=dnsname-src,src=/usr/src/dnsname,target=.,rw \
154-
--mount=target=/root/.cache,type=cache \
138+
RUN --mount=target=/root/.cache,type=cache \
155139
CGO_ENABLED=0 xx-go build -o /usr/bin/dnsname ./plugins/meta/dnsname && \
156140
xx-verify --static /usr/bin/dnsname
157141

@@ -216,23 +200,15 @@ RUN apk add --no-cache fuse3 git openssh pigz xz iptables ip6tables \
216200
COPY --link examples/buildctl-daemonless/buildctl-daemonless.sh /usr/bin/
217201
VOLUME /var/lib/buildkit
218202

219-
FROM git AS containerd-src
220-
WORKDIR /usr/src
221-
RUN git clone https://github.com/containerd/containerd.git containerd
222-
223-
FROM gobuild-base AS containerd-base
203+
FROM gobuild-base AS containerd
224204
WORKDIR /go/src/github.com/containerd/containerd
205+
ARG CONTAINERD_VERSION
206+
ADD --keep-git-dir=true "https://github.com/containerd/containerd.git#$CONTAINERD_VERSION" .
225207
ARG TARGETPLATFORM
226208
ENV CGO_ENABLED=1 BUILDTAGS=no_btrfs GO111MODULE=off
227209
RUN xx-apk add musl-dev gcc && xx-go --wrap
228-
229-
FROM containerd-base AS containerd
230-
ARG CONTAINERD_VERSION
231-
RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
232-
--mount=target=/root/.cache,type=cache <<EOT
210+
RUN --mount=target=/root/.cache,type=cache <<EOT
233211
set -ex
234-
git fetch origin
235-
git checkout -q "$CONTAINERD_VERSION"
236212
mkdir /out
237213
ext=""
238214
if [ "$(xx-info os)" = "windows" ]; then
@@ -249,13 +225,15 @@ RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
249225
EOT
250226

251227
# containerd v1.6 for integration tests
252-
FROM containerd-base AS containerd-alt-16
228+
FROM gobuild-base AS containerd-alt-16
229+
WORKDIR /go/src/github.com/containerd/containerd
253230
ARG CONTAINERD_ALT_VERSION_16
254-
RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
255-
--mount=target=/root/.cache,type=cache <<EOT
231+
ADD --keep-git-dir=true "https://github.com/containerd/containerd.git#$CONTAINERD_ALT_VERSION_16" .
232+
ARG TARGETPLATFORM
233+
ENV CGO_ENABLED=1 BUILDTAGS=no_btrfs GO111MODULE=off
234+
RUN xx-apk add musl-dev gcc && xx-go --wrap
235+
RUN --mount=target=/root/.cache,type=cache <<EOT
256236
set -ex
257-
git fetch origin
258-
git checkout -q "$CONTAINERD_ALT_VERSION_16"
259237
mkdir /out
260238
ext=""
261239
if [ "$(xx-info os)" = "windows" ]; then
@@ -271,19 +249,13 @@ RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
271249
fi
272250
EOT
273251

274-
FROM git AS registry-src
275-
WORKDIR /usr/src
276-
RUN git clone https://github.com/distribution/distribution.git distribution
277-
278252
FROM gobuild-base AS registry
253+
WORKDIR /go/src/github.com/docker/distribution
279254
ARG REGISTRY_VERSION
255+
ADD --keep-git-dir=true "https://github.com/distribution/distribution.git#$REGISTRY_VERSION" .
280256
ARG TARGETPLATFORM
281-
WORKDIR /go/src/github.com/docker/distribution
282-
RUN --mount=from=registry-src,src=/usr/src/distribution,rw \
283-
--mount=target=/root/.cache,type=cache <<EOT
257+
RUN --mount=target=/root/.cache,type=cache <<EOT
284258
set -ex
285-
git fetch origin
286-
git checkout -q "$REGISTRY_VERSION"
287259
mkdir /out
288260
export GOPATH="$(pwd)/Godeps/_workspace:$GOPATH"
289261
GO111MODULE=off CGO_ENABLED=0 xx-go build -o /out/registry ./cmd/registry
@@ -294,22 +266,20 @@ RUN --mount=from=registry-src,src=/usr/src/distribution,rw \
294266
EOT
295267

296268
FROM gobuild-base AS rootlesskit
297-
ARG ROOTLESSKIT_VERSION
298-
RUN git clone https://github.com/rootless-containers/rootlesskit.git /go/src/github.com/rootless-containers/rootlesskit
299269
WORKDIR /go/src/github.com/rootless-containers/rootlesskit
270+
ARG ROOTLESSKIT_VERSION
271+
ADD --keep-git-dir=true "https://github.com/rootless-containers/rootlesskit.git#$ROOTLESSKIT_VERSION" .
300272
ARG TARGETPLATFORM
301273
RUN --mount=target=/root/.cache,type=cache \
302-
git checkout -q "$ROOTLESSKIT_VERSION" && \
303274
CGO_ENABLED=0 xx-go build -o /rootlesskit ./cmd/rootlesskit && \
304275
xx-verify --static /rootlesskit
305276

306277
FROM gobuild-base AS stargz-snapshotter
307-
ARG STARGZ_SNAPSHOTTER_VERSION
308-
RUN git clone https://github.com/containerd/stargz-snapshotter.git /go/src/github.com/containerd/stargz-snapshotter
309278
WORKDIR /go/src/github.com/containerd/stargz-snapshotter
279+
ARG STARGZ_SNAPSHOTTER_VERSION
280+
ADD --keep-git-dir=true "https://github.com/containerd/stargz-snapshotter.git#$STARGZ_SNAPSHOTTER_VERSION" .
310281
ARG TARGETPLATFORM
311282
RUN --mount=target=/root/.cache,type=cache \
312-
git checkout -q "$STARGZ_SNAPSHOTTER_VERSION" && \
313283
xx-go --wrap && \
314284
mkdir /out && CGO_ENABLED=0 PREFIX=/out/ make && \
315285
xx-verify --static /out/containerd-stargz-grpc && \

0 commit comments

Comments
 (0)