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
1830RUN 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
3842ENV GOPATH=/go
3943ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
4044
4145WORKDIR /build
4246COPY . .
43-
4447RUN mkdir /artifacts
45- ARG VERSION="N/A"
46- ARG GIT_COMMIT="unknown"
47- ARG TARGETARCH
48-
4948RUN 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).
5656FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi9
5757
5858ENV NVIDIA_DISABLE_REQUIRE="true"
@@ -72,6 +72,9 @@ LABEL description="NVIDIA DRA Driver for GPUs"
7272LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
7373LABEL 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
7578RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
7679
7780COPY --from=build /artifacts/compute-domain-controller /usr/bin/compute-domain-controller
0 commit comments