forked from docker/packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
277 lines (252 loc) · 9.88 KB
/
Dockerfile
File metadata and controls
277 lines (252 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# syntax=docker/dockerfile:1
# Copyright 2022 Docker Packaging authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG XX_VERSION="1.6.1"
ARG DEBIAN_FRONTEND="noninteractive"
# https://github.com/containerd/containerd/blob/main/.github/workflows/ci.yml#L111
ARG MD2MAN_VERSION="v2.0.2"
ARG RUNC_REPO="https://github.com/opencontainers/runc.git"
ARG RUNHCS_REPO="https://github.com/Microsoft/hcsshim.git"
ARG DISTRO_NAME="debian12"
ARG DISTRO_TYPE="deb"
ARG DISTRO_RELEASE="debian"
ARG DISTRO_ID="12"
ARG DISTRO_SUITE="bookworm"
ARG DISTRO_IMAGE="debian:bookworm"
ARG PKG_NAME="containerd.io"
ARG PKG_REPO="https://github.com/containerd/containerd.git"
ARG PKG_REF="main"
ARG GO_IMAGE="golang"
ARG GO_VERSION="1.24.6"
ARG GO_IMAGE_VARIANT="bookworm"
# stage used as named context that mounts hack/scripts
# see pkg target in docker-bake.hcl
FROM scratch AS scripts
# cross compilation helper
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
# go base image to retrieve /usr/local/go
FROM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go
FROM --platform=$BUILDPLATFORM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS gocross
# md2man
FROM go AS go-md2man
ENV GOPROXY="https://proxy.golang.org|direct"
ENV GOTOOLCHAIN="local"
ENV GO111MODULE="on"
ARG MD2MAN_VERSION
RUN go install github.com/cpuguy83/go-md2man/v2@${MD2MAN_VERSION}
# src
FROM --platform=$BUILDPLATFORM alpine AS src-base
RUN apk add --no-cache bash curl file git zip tar
FROM src-base AS src
WORKDIR /src
ARG PKG_REPO
RUN git init . && git remote add origin "${PKG_REPO}"
ARG PKG_REF
RUN <<EOT
set -ex
git fetch origin "${PKG_REF}" +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
git checkout -q FETCH_HEAD
EOT
FROM src-base AS src-tgz
RUN --mount=from=src,source=/src,target=/containerd \
mkdir /out && tar -C / -zcf /out/containerd.tgz --exclude .git containerd
FROM src-base AS runc-src
WORKDIR /src
ARG RUNC_REPO
ARG RUNC_REF
RUN git init . && git remote add origin "${RUNC_REPO}"
RUN --mount=from=src,source=/src,target=/containerd <<EOT
set -e
[ -z "$RUNC_REF" ] && RUNC_REF=$(cat /containerd/script/setup/runc-version)
set -x
git fetch origin "$RUNC_REF" +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
git checkout -q FETCH_HEAD
EOT
FROM src-base AS runc-src-tgz
RUN --mount=from=runc-src,source=/src,target=/runc \
mkdir /out && tar -C / -zcf /out/runc.tgz --exclude .git runc
FROM src-base AS runhcs-src
WORKDIR /src
ARG RUNHCS_REPO
ARG RUNHCS_REF
RUN git init . && git remote add origin "${RUNHCS_REPO}"
RUN --mount=from=src,source=/src,target=/containerd <<EOT
set -e
[ -z "$RUNHCS_REF" ] && RUNHCS_REF=$(cat /containerd/script/setup/runhcs-version)
set -x
git fetch origin "$RUNHCS_REF" +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
git checkout -q FETCH_HEAD
EOT
FROM src-base AS libseccomp-src
WORKDIR /src
RUN --mount=from=runc-src,source=/src,target=/runc <<EOT
set -e
LIBSECCOMP_VERSION=$(grep '^ARG LIBSECCOMP_VERSION=' /runc/Dockerfile | cut -d'=' -f2)
set -x
curl -sSL "https://github.com/seccomp/libseccomp/releases/download/v${LIBSECCOMP_VERSION}/libseccomp-${LIBSECCOMP_VERSION}.tar.gz" | tar -xz --strip-components=1
EOT
# metadata
FROM src-base AS metadata-builder
ARG PKG_REPO
ARG PKG_REF
ARG RUNC_REPO
ARG RUNC_REF
ARG RUNHCS_REPO
ARG RUNHCS_REF
ARG NIGHTLY_BUILD
RUN --mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=src,source=/src,target=/src \
--mount=type=bind,from=runc-src,source=/src,target=/runc-src \
--mount=type=bind,from=runhcs-src,source=/src,target=/runhcs-src <<EOT
set -e
mkdir -p /out
for l in $(gen-ver "/src"); do
export "${l?}"
done
cat > "/out/metadata.env" <<-EOF
REPO=${PKG_REPO%.*}
REF=${PKG_REF}
VERSION=${GENVER_VERSION}
COMMIT=${GENVER_COMMIT}
EOF
[ -z "$RUNC_REF" ] && RUNC_REF=$(cat /src/script/setup/runc-version)
for l in $(gen-ver "/runc-src"); do
export "${l?}"
done
cat >> "/out/metadata.env" <<-EOF
RUNC_REPO=${RUNC_REPO%.*}
RUNC_REF=${RUNC_REF}
RUNC_VERSION=${GENVER_VERSION}
RUNC_COMMIT=${GENVER_COMMIT}
EOF
[ -z "$RUNHCS_REF" ] && RUNHCS_REF=$(cat /src/script/setup/runhcs-version)
for l in $(gen-ver "/runhcs-src"); do
export "${l?}"
done
cat >> "/out/metadata.env" <<-EOF
RUNHCS_REPO=${RUNHCS_REPO%.*}
RUNHCS_REF=${RUNHCS_REF}
RUNHCS_VERSION=${GENVER_VERSION}
RUNHCS_COMMIT=${GENVER_COMMIT}
EOF
EOT
FROM scratch AS metadata
COPY --from=metadata-builder /out /
# deb
FROM ${DISTRO_IMAGE} AS builder-deb
COPY --from=xx / /
ARG DEBIAN_FRONTEND
ENV GOPROXY="https://proxy.golang.org|direct"
ENV GOPATH="/go"
ENV GOTOOLCHAIN="local"
ENV GO111MODULE="on"
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
COPY --from=go-md2man /go/bin/go-md2man $GOPATH/bin/go-md2man
ARG DISTRO_NAME
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils bash ca-certificates curl devscripts equivs git lsb-release
COPY deb /root/package/debian
ARG TARGETPLATFORM
RUN mk-build-deps -t "xx-apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/package/debian/control
WORKDIR /root/package
ARG NIGHTLY_BUILD
ARG DISTRO_RELEASE
ARG DISTRO_ID
ARG DISTRO_SUITE
ARG PKG_NAME
ARG PKG_REF
ARG PKG_PACKAGER
ARG PKG_DEB_BUILDFLAGS
ARG PKG_DEB_REVISION
ARG PKG_DEB_EPOCH
ARG SOURCE_DATE_EPOCH
RUN --mount=type=bind,source=scripts/pkg-deb-build.sh,target=/usr/local/bin/pkg-deb-build \
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=scripts,source=gen-deb-changelog.sh,target=/usr/local/bin/gen-deb-changelog \
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
--mount=type=bind,source=common,target=/common,rw \
--mount=type=bind,from=src,source=/src,target=/go/src/github.com/containerd/containerd,rw \
--mount=type=bind,from=runc-src,source=/src,target=/go/src/github.com/opencontainers/runc,rw \
--mount=type=bind,from=go,source=/usr/local/go,target=/usr/local/go \
OUTDIR=/out SRCDIR=/go/src/github.com/containerd/containerd pkg-deb-build
# rpm
FROM ${DISTRO_IMAGE} AS builder-rpm
COPY --from=xx / /
ENV GOPROXY="https://proxy.golang.org|direct"
ENV GOPATH="/go"
ENV GOTOOLCHAIN="local"
ENV GO111MODULE="on"
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
COPY --from=go-md2man /go/bin/go-md2man $GOPATH/bin/go-md2man
ARG DISTRO_NAME
RUN --mount=type=bind,from=scripts,source=rpm-init.sh,target=/usr/local/bin/rpm-init \
--mount=type=secret,id=RH_USER,env=RH_USER \
--mount=type=secret,id=RH_PASS,env=RH_PASS \
rpm-init $DISTRO_NAME
COPY rpm /root/rpmbuild/SPECS
ARG TARGETPLATFORM
RUN --mount=type=bind,from=scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \
rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS
WORKDIR /root/rpmbuild
ARG NIGHTLY_BUILD
ARG DISTRO_RELEASE
ARG DISTRO_ID
ARG DISTRO_SUITE
ARG PKG_NAME
ARG PKG_REF
ARG PKG_PACKAGER
ARG PKG_RPM_BUILDFLAGS
ARG PKG_RPM_RELEASE
ARG SOURCE_DATE_EPOCH
RUN --mount=type=bind,source=scripts/pkg-rpm-build.sh,target=/usr/local/bin/pkg-rpm-build \
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
--mount=type=bind,source=common/containerd.toml,target=/root/rpmbuild/SOURCES/containerd.toml \
--mount=type=bind,from=src-tgz,source=/out/containerd.tgz,target=/root/rpmbuild/SOURCES/containerd.tgz \
--mount=type=bind,from=runc-src-tgz,source=/out/runc.tgz,target=/root/rpmbuild/SOURCES/runc.tgz \
--mount=type=bind,from=src,source=/src,target=/go/src/github.com/containerd/containerd,rw \
--mount=type=bind,from=runc-src,source=/src,target=/go/src/github.com/opencontainers/runc,rw \
--mount=type=bind,from=go,source=/usr/local/go,target=/usr/local/go \
OUTDIR=/out SRCDIR=/go/src/github.com/containerd/containerd pkg-rpm-build
# static
FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static
COPY --from=xx / /
ARG DEBIAN_FRONTEND
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git gperf zip tar \
dpkg-dev clang make pkg-config
ENV GOPROXY="https://proxy.golang.org|direct"
ENV GOPATH="/go"
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
ENV GOTOOLCHAIN="local"
ENV GO111MODULE="on"
ENV CGO_ENABLED="1"
ARG PKG_NAME
ARG PKG_REF
ARG NIGHTLY_BUILD
ARG RUNC_REF
WORKDIR /build
ARG TARGETPLATFORM
RUN xx-apt-get install -y gcc
RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/pkg-static-build \
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
--mount=type=bind,from=src,source=/src,target=/go/src/github.com/containerd/containerd,rw \
--mount=type=bind,from=runc-src,source=/src,target=/go/src/github.com/opencontainers/runc,rw \
--mount=type=bind,from=runhcs-src,source=/src,target=/go/src/github.com/Microsoft/hcsshim,rw \
--mount=type=bind,from=libseccomp-src,source=/src,target=/usr/local/src/libseccomp,rw \
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
OUTDIR=/out BUILDDIR=/build SRCDIR=/go/src/github.com/containerd/containerd RUNC_SRCDIR=/go/src/github.com/opencontainers/runc RUNHCS_SRCDIR=/go/src/github.com/Microsoft/hcsshim LIBSECCOMP_SRCDIR=/usr/local/src/libseccomp pkg-static-build
FROM builder-${DISTRO_TYPE} AS build-pkg
ARG BUILDKIT_SBOM_SCAN_STAGE=true
FROM scratch AS pkg
COPY --from=build-pkg /out /