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.
2419ARG 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
3836ENV GOPATH=/go
3937ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
40-
4138WORKDIR /build
4239COPY . .
43-
4440RUN mkdir /artifacts
45- ARG VERSION="N/A"
46- ARG GIT_COMMIT="unknown"
47- ARG TARGETARCH
48-
4941RUN 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).
5649FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi9
5750
5851ENV NVIDIA_DISABLE_REQUIRE="true"
@@ -72,6 +65,9 @@ LABEL description="NVIDIA DRA Driver for GPUs"
7265LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
7366LABEL 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
7571RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
7672
7773COPY --from=build /artifacts/compute-domain-controller /usr/bin/compute-domain-controller
0 commit comments