Skip to content

Commit 5292c24

Browse files
committed
Use native binaries for amd64->arm64 build
Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
1 parent dc61b93 commit 5292c24

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

deployments/container/Dockerfile

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,40 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# We use an ubuntu20.04 base image to allow for a more efficient multi-arch builds.
16-
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu20.04 AS build
15+
# Run build with binaries native to the current build platform.
16+
FROM --platform=$BUILDPLATFORM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu20.04 AS build
1717

18-
RUN apt-get update && \
19-
apt-get install -y wget make git gcc-aarch64-linux-gnu gcc \
20-
&& \
21-
rm -rf /var/lib/apt/lists/*
22-
23-
# Require build arg.
18+
# Require GOLANG_VERSION arg to be provided.
2419
ARG GOLANG_VERSION=x.x.x
2520

26-
RUN set -eux; \
27-
\
28-
arch="$(uname -m)"; \
29-
case "${arch##*-}" in \
30-
x86_64 | amd64) ARCH='amd64' ;; \
31-
ppc64el | ppc64le) ARCH='ppc64le' ;; \
32-
aarch64) ARCH='arm64' ;; \
33-
*) echo "unsupported architecture" ; exit 1 ;; \
34-
esac; \
35-
wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \
21+
# BUILDARCH, TARGETARCH, etc are defined in the global scope by BuiltKit.
22+
# BUILDARCH is reflecting the architecture of the build platform. TARGETARCH is
23+
# set via the --platform arg provided to the `docker buildx build ...` command.
24+
# Redefining those variables here without new values makes the outer-context
25+
# values available to in-stage RUN commands. Arch values are of the form
26+
# amd64/arm64.
27+
ARG BUILDARCH
28+
ARG TARGETARCH
29+
30+
RUN apt-get update && \
31+
apt-get install -y wget make git gcc-aarch64-linux-gnu gcc && \
32+
rm -rf /var/lib/apt/lists/*
33+
RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-$BUILDARCH.tar.gz \
3634
| tar -C /usr/local -xz
3735

3836
ENV GOPATH=/go
3937
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
40-
4138
WORKDIR /build
4239
COPY . .
43-
4440
RUN mkdir /artifacts
45-
ARG VERSION="N/A"
46-
ARG GIT_COMMIT="unknown"
47-
ARG TARGETARCH
48-
4941
RUN if [ "$TARGETARCH" = "amd64" ]; then \
5042
cc=gcc; \
5143
elif [ "$TARGETARCH" = "arm64" ]; then \
5244
cc=aarch64-linux-gnu-gcc; \
5345
fi && \
5446
make CC=${cc} GOARCH=${TARGETARCH} PREFIX=/artifacts cmds
5547

48+
# Construct production image (arch: TARGETPLATFORM, set via --platform).
5649
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi9
5750

5851
ENV NVIDIA_DISABLE_REQUIRE="true"
@@ -72,6 +65,9 @@ LABEL description="NVIDIA DRA Driver for GPUs"
7265
LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
7366
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/k8s-dra-driver-gpu"
7467

68+
# When doing a cross-platform build (e.g., amd64 -> arm64) then mkdir/mv below
69+
# require virtualization. To support that you might have to install qemu:
70+
# https://docs.docker.com/build/building/multi-platform/#install-qemu-manually
7571
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
7672

7773
COPY --from=build /artifacts/compute-domain-controller /usr/bin/compute-domain-controller

deployments/container/native-only.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
PUSH_ON_BUILD ?= false
16+
17+
# Override ARCH in env to set the target build platform
1618
ARCH ?= $(shell uname -m | sed -e 's,aarch64,arm64,' -e 's,x86_64,amd64,')
1719
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)
1820

0 commit comments

Comments
 (0)