Skip to content

Commit 2e5cdac

Browse files
authored
Merge pull request #2007 from manugupt1/build-arch
Build containerd and runc for specific arch with xx
2 parents a16d314 + fa9f627 commit 2e5cdac

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

Dockerfile

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,53 +51,55 @@ ARG UBUNTU_VERSION=22.04
5151
ARG CONTAINERIZED_SYSTEMD_VERSION=v0.1.1
5252
ARG GOTESTSUM_VERSION=v1.9.0
5353

54+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.2.1 AS xx
55+
56+
5457
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bullseye AS build-base-debian
58+
COPY --from=xx / /
59+
ENV DEBIAN_FRONTEND=noninteractive
60+
RUN apt-get update && \
61+
apt-get install -y git pkg-config dpkg-dev
62+
ARG TARGETARCH
5563
# libbtrfs: for containerd
5664
# libseccomp: for runc and bypass4netns
57-
RUN dpkg --add-architecture arm64 && \
58-
dpkg --add-architecture amd64 && \
59-
apt-get update && \
60-
apt-get install -y crossbuild-essential-amd64 crossbuild-essential-arm64 git libbtrfs-dev:amd64 libbtrfs-dev:arm64 libseccomp-dev:amd64 libseccomp-dev:arm64
65+
RUN xx-apt-get update && \
66+
xx-apt-get install -y binutils gcc libc6-dev libbtrfs-dev libseccomp-dev
6167

6268
FROM build-base-debian AS build-containerd
69+
ARG TARGETARCH
6370
ARG CONTAINERD_VERSION
6471
RUN git clone https://github.com/containerd/containerd.git /go/src/github.com/containerd/containerd
6572
WORKDIR /go/src/github.com/containerd/containerd
6673
RUN git checkout ${CONTAINERD_VERSION} && \
67-
mkdir -p /out /out/amd64 /out/arm64 && \
74+
mkdir -p /out /out/$TARGETARCH && \
6875
cp -a containerd.service /out
6976
ENV CGO_ENABLED=1
7077
ENV GO111MODULE=off
7178
# TODO: how to build containerd as static binaries? https://github.com/containerd/containerd/issues/6158
72-
RUN GOARCH=amd64 CC=x86_64-linux-gnu-gcc make && \
73-
cp -a bin/containerd bin/containerd-shim-runc-v2 bin/ctr /out/amd64
74-
RUN git clean -xfd
75-
RUN GOARCH=arm64 CC=aarch64-linux-gnu-gcc make && \
76-
cp -a bin/containerd bin/containerd-shim-runc-v2 bin/ctr /out/arm64
79+
RUN GO=xx-go make && \
80+
cp -a bin/containerd bin/containerd-shim-runc-v2 bin/ctr /out/$TARGETARCH
7781

7882
FROM build-base-debian AS build-runc
7983
ARG RUNC_VERSION
84+
ARG TARGETARCH
8085
RUN git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc
8186
WORKDIR /go/src/github.com/opencontainers/runc
8287
RUN git checkout ${RUNC_VERSION} && \
8388
mkdir -p /out
8489
ENV CGO_ENABLED=1
85-
RUN GOARCH=amd64 CC=x86_64-linux-gnu-gcc make static && \
86-
cp -a runc /out/runc.amd64
87-
RUN GOARCH=arm64 CC=aarch64-linux-gnu-gcc make static && \
88-
cp -a runc /out/runc.arm64
90+
RUN GO=xx-go make static && \
91+
xx-verify --static runc && cp -v -a runc /out/runc.${TARGETARCH}
8992

9093
FROM build-base-debian AS build-bypass4netns
9194
ARG BYPASS4NETNS_VERSION
95+
ARG TARGETARCH
9296
RUN git clone https://github.com/rootless-containers/bypass4netns.git /go/src/github.com/rootless-containers/bypass4netns
9397
WORKDIR /go/src/github.com/rootless-containers/bypass4netns
9498
RUN git checkout ${BYPASS4NETNS_VERSION} && \
95-
mkdir -p /out/amd64 /out/arm64
99+
mkdir -p /out/${TARGETARCH}
96100
ENV CGO_ENABLED=1
97-
RUN GOARCH=amd64 CC=x86_64-linux-gnu-gcc make static && \
98-
cp -a bypass4netns bypass4netnsd /out/amd64
99-
RUN GOARCH=arm64 CC=aarch64-linux-gnu-gcc make static && \
100-
cp -a bypass4netns bypass4netnsd /out/arm64
101+
RUN GO=xx-go make static && \
102+
xx-verify --static bypass4netns && cp -a bypass4netns bypass4netnsd /out/${TARGETARCH}
101103

102104
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build-base
103105
RUN apk add --no-cache make git curl

0 commit comments

Comments
 (0)