Skip to content

Commit 454c79e

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

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

deployments/container/Dockerfile

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@
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
17+
18+
# Require arg to be provided (set invalid default value).
19+
ARG GOLANG_VERSION=x.x.x
20+
21+
# BUILDARCH, TARGETARCH (and others) are defined in the global scope by
22+
# BuiltKit. BUILDARCH is 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
1729

1830
RUN apt-get update && \
19-
apt-get install -y wget make git gcc-aarch64-linux-gnu gcc \
20-
&& \
31+
apt-get install -y \
32+
wget \
33+
make \
34+
git \
35+
gcc-aarch64-linux-gnu \
36+
gcc && \
2137
rm -rf /var/lib/apt/lists/*
2238

23-
# Require build arg.
24-
ARG GOLANG_VERSION=x.x.x
25-
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 \
39+
RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${BUILDARCH}.tar.gz \
3640
| tar -C /usr/local -xz
3741

3842
ENV GOPATH=/go
3943
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
4044

4145
WORKDIR /build
4246
COPY . .
43-
4447
RUN mkdir /artifacts
45-
ARG VERSION="N/A"
46-
ARG GIT_COMMIT="unknown"
47-
ARG TARGETARCH
48-
4948
RUN if [ "$TARGETARCH" = "amd64" ]; then \
5049
cc=gcc; \
5150
elif [ "$TARGETARCH" = "arm64" ]; then \
5251
cc=aarch64-linux-gnu-gcc; \
5352
fi && \
5453
make CC=${cc} GOARCH=${TARGETARCH} PREFIX=/artifacts cmds
5554

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

5858
ENV NVIDIA_DISABLE_REQUIRE="true"
@@ -72,6 +72,9 @@ LABEL description="NVIDIA DRA Driver for GPUs"
7272
LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
7373
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/k8s-dra-driver-gpu"
7474

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

7780
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)