2020ARG TOOLKIT_CONTAINER_IMAGE=unknown
2121
2222# Run build with binaries native to the current build platform.
23- FROM --platform=$BUILDPLATFORM nvcr .io/nvidia/cuda :12.9.1-base-ubuntu20.04 AS build
23+ FROM --platform=$BUILDPLATFORM docker .io/debian :12 AS build
2424
2525# Require arg to be provided (set invalid default value).
2626ARG GOLANG_VERSION=x.x.x
27+ ARG BASH_STATIC_GIT_REF=unknown
2728
2829# BUILDARCH, TARGETARCH (and others) are defined in the global scope by
2930# BuiltKit. BUILDARCH is the architecture of the build platform. TARGETARCH is
@@ -34,14 +35,35 @@ ARG GOLANG_VERSION=x.x.x
3435ARG BUILDARCH
3536ARG TARGETARCH
3637
38+ # Install dependencies for Go build. Do not clear apt cache (does not
39+ # leak into prod stage).
3740RUN apt-get update && \
3841 apt-get install -y \
3942 wget \
4043 make \
4144 git \
4245 gcc-aarch64-linux-gnu \
43- gcc && \
44- rm -rf /var/lib/apt/lists/*
46+ gcc
47+
48+ # Install dependencies for `bash-static` build.
49+ RUN apt-get install -y gpg curl autoconf
50+
51+ # Build static bash binary (against musl).
52+ WORKDIR /bashbuild
53+ RUN git clone https://github.com/robxu9/bash-static/
54+ RUN ARCH="$TARGETARCH" && \
55+ [ "$ARCH" = "arm64" ] && ARCH="aarch64" || true && \
56+ [ "$ARCH" = "amd64" ] && ARCH="x86_64" || true && \
57+ echo "detected arch: $ARCH" && \
58+ cd bash-static && git checkout ${BASH_STATIC_GIT_REF} && \
59+ sed -i 's|https://ftp\. gnu\. org/gnu|https://ftpmirror.gnu.org/|g' ./build.sh && \
60+ sed -i 's/-sLO/-sSfLO --retry 300 --connect-timeout 20 --retry-delay 2/g' ./build.sh && \
61+ bash version-52.sh && ./build.sh linux $ARCH
62+
63+ # With above's commit, this emits
64+ # 'GNU bash, version 5.2.37(1)-release (aarch64-unknown-linux-musl)'
65+ RUN cd /bashbuild/bash-static/releases && ./bash*-static --version
66+ RUN mv /bashbuild/bash-static/releases/bash-*-static /bashbuild/bash
4567
4668RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${BUILDARCH}.tar.gz \
4769 | tar -C /usr/local -xz
@@ -77,8 +99,13 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \
7799# (arch: TARGETPLATFORM, set via --platform).
78100FROM ${TOOLKIT_CONTAINER_IMAGE} AS toolkit
79101
80- # Construct production image (arch: TARGETPLATFORM, set via --platform).
81- FROM nvcr.io/nvidia/cuda:13.0.0-base-ubi9
102+ # Construct production image (arch: TARGETPLATFORM, set via the `--platform` CLI
103+ # arg). Note that nvcr.io/nvidia/distroless/cc is based on
104+ # https://github.com/GoogleContainerTools/distroless; specifically on debian12.
105+ # For consistency, the build stage above derives from Debian 12 directly. The
106+ # `-dev` suffic is to get busybox as a shell added. For RUN directives to pick
107+ # that up, use `SHELL ["/busybox/sh", "-c"]`.
108+ FROM nvcr.io/nvidia/distroless/cc:v3.1.11-dev
82109
83110ENV NVIDIA_DISABLE_REQUIRE="true"
84111ENV NVIDIA_VISIBLE_DEVICES=all
@@ -97,15 +124,24 @@ LABEL description="NVIDIA DRA Driver for GPUs"
97124LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
98125LABEL org.opencontainers.image.source="https://github.com/NVIDIA/k8s-dra-driver-gpu"
99126
100- # When doing a cross-platform build (e.g., amd64 -> arm64) then mkdir/mv below
101- # require virtualization. To support that you might have to install qemu:
102- # https://docs.docker.com/build/building/multi-platform/#install-qemu-manually
103- RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
127+ # Add top-level license (AL2) file into the container image
128+ COPY LICENSE /
104129
105130COPY --from=toolkit /artifacts/rpm/usr/bin/nvidia-cdi-hook /usr/bin/nvidia-cdi-hook
131+ COPY --from=build /bashbuild/bash /bin/bash
106132COPY --from=build /artifacts/compute-domain-controller /usr/bin/compute-domain-controller
107133COPY --from=build /artifacts/compute-domain-kubelet-plugin /usr/bin/compute-domain-kubelet-plugin
108134COPY --from=build /artifacts/compute-domain-daemon /usr/bin/compute-domain-daemon
109135COPY --from=build /artifacts/gpu-kubelet-plugin /usr/bin/gpu-kubelet-plugin
110136COPY /hack/kubelet-plugin-prestart.sh /usr/bin/kubelet-plugin-prestart.sh
111137COPY /templates /templates
138+
139+ # Use root by default (for example, the init container as of now needs
140+ # this, otherwise `ln: /driver-root: Permission denied`).
141+ COPY --from=build /etc/passwd /etc/passwd
142+ COPY --from=build /etc/group /etc/group
143+ USER root:root
144+
145+ # Smoke-test executables (provide early build feedback).
146+ RUN ["/usr/bin/compute-domain-kubelet-plugin" , "--version" ]
147+ RUN ["/bin/bash" , "--version" ]
0 commit comments