Skip to content

Commit 81d704d

Browse files
committed
Dockerfile: containerd cross build with TARGETPLATFORM
Signed-off-by: CrazyMax <[email protected]>
1 parent b19c116 commit 81d704d

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

Dockerfile

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,46 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
209209
GOBIN=/build/ GO111MODULE=on go install "github.com/tc-hib/go-winres@${GOWINRES_VERSION}" \
210210
&& /build/go-winres --help
211211

212-
FROM dev-base AS containerd
212+
# containerd
213+
FROM base AS containerd-src
214+
WORKDIR /usr/src/containerd
215+
RUN git init . && git remote add origin "https://github.com/containerd/containerd.git"
216+
# CONTAINERD_VERSION is used to build containerd binaries, and used for the
217+
# integration tests. The distributed docker .deb and .rpm packages depend on a
218+
# separate (containerd.io) package, which may be a different version as is
219+
# specified here. The containerd golang package is also pinned in vendor.mod.
220+
# When updating the binary version you may also need to update the vendor
221+
# version to pick up bug fixes or new APIs, however, usually the Go packages
222+
# are built from a commit from the master branch.
223+
ARG CONTAINERD_VERSION=v1.7.0-beta.0
224+
RUN git fetch -q --depth 1 origin "${CONTAINERD_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
225+
226+
FROM base AS containerd-build
227+
WORKDIR /go/src/github.com/containerd/containerd
213228
ARG DEBIAN_FRONTEND
229+
ARG TARGETPLATFORM
214230
RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \
215231
--mount=type=cache,sharing=locked,id=moby-containerd-aptcache,target=/var/cache/apt \
216-
apt-get update && apt-get install -y --no-install-recommends \
217-
libbtrfs-dev
218-
ARG CONTAINERD_VERSION
219-
COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/containerd.installer /
220-
RUN --mount=type=cache,target=/root/.cache/go-build \
221-
--mount=type=cache,target=/go/pkg/mod \
222-
PREFIX=/build /install.sh containerd
232+
apt-get update && xx-apt-get install -y --no-install-recommends \
233+
gcc libbtrfs-dev libsecret-1-dev
234+
ARG DOCKER_STATIC
235+
RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
236+
--mount=type=cache,target=/root/.cache/go-build,id=containerd-build-$TARGETPLATFORM <<EOT
237+
set -e
238+
export CC=$(xx-info)-gcc
239+
export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
240+
xx-go --wrap
241+
make $([ "$DOCKER_STATIC" = "1" ] && echo "STATIC=1") binaries
242+
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd
243+
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd-shim-runc-v2
244+
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/ctr
245+
mkdir /build
246+
mv bin/containerd bin/containerd-shim-runc-v2 bin/ctr /build
247+
EOT
248+
249+
FROM containerd-build AS containerd-linux
250+
FROM binary-dummy AS containerd-windows
251+
FROM containerd-${TARGETOS} AS containerd
223252

224253
FROM base AS golangci_lint
225254
# FIXME: when updating golangci-lint, remove the temporary "nolint" in https://github.com/moby/moby/blob/7860686a8df15eea9def9e6189c6f9eca031bb6f/libnetwork/networkdb/cluster.go#L246

0 commit comments

Comments
 (0)