Dockerfile: runc cross build with TARGETPLATFORM

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-11-19 02:22:09 +01:00
parent 81d704d15d
commit 5e19d7ec54
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7

View file

@ -280,13 +280,39 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/go/pkg/mod \
PREFIX=/build /install.sh dockercli PREFIX=/build /install.sh dockercli
FROM runtime-dev AS runc # runc
ARG RUNC_VERSION FROM base AS runc-src
ARG RUNC_BUILDTAGS WORKDIR /usr/src/runc
COPY /hack/dockerfile/install/install.sh /hack/dockerfile/install/runc.installer / RUN git init . && git remote add origin "https://github.com/opencontainers/runc.git"
RUN --mount=type=cache,target=/root/.cache/go-build \ # RUNC_VERSION should match the version that is used by the containerd version
--mount=type=cache,target=/go/pkg/mod \ # that is used. If you need to update runc, open a pull request in the containerd
PREFIX=/build /install.sh runc # project first, and update both after that is merged. When updating RUNC_VERSION,
# consider updating runc in vendor.mod accordingly.
ARG RUNC_VERSION=v1.1.4
RUN git fetch -q --depth 1 origin "${RUNC_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
FROM base AS runc-build
WORKDIR /go/src/github.com/opencontainers/runc
ARG DEBIAN_FRONTEND
ARG TARGETPLATFORM
RUN --mount=type=cache,sharing=locked,id=moby-runc-aptlib,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=moby-runc-aptcache,target=/var/cache/apt \
apt-get update && xx-apt-get install -y --no-install-recommends \
dpkg-dev gcc libc6-dev libseccomp-dev
ARG DOCKER_STATIC
RUN --mount=from=runc-src,src=/usr/src/runc,rw \
--mount=type=cache,target=/root/.cache/go-build,id=runc-build-$TARGETPLATFORM <<EOT
set -e
xx-go --wrap
CGO_ENABLED=1 make "$([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "runc")"
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") runc
mkdir /build
mv runc /build/
EOT
FROM runc-build AS runc-linux
FROM binary-dummy AS runc-windows
FROM runc-${TARGETOS} AS runc
FROM dev-base AS tini FROM dev-base AS tini
ARG DEBIAN_FRONTEND ARG DEBIAN_FRONTEND