Skip to content

Commit 3b47605

Browse files
authored
Merge pull request #470 from jgehrcke/jp/distroless
Use 'distroless' prod image
2 parents fe736f1 + e278808 commit 3b47605

4 files changed

Lines changed: 48 additions & 9 deletions

File tree

deployments/container/Dockerfile

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
ARG 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).
2626
ARG 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
3435
ARG BUILDARCH
3536
ARG TARGETARCH
3637

38+
# Install dependencies for Go build. Do not clear apt cache (does not
39+
# leak into prod stage).
3740
RUN 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

4668
RUN 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).
78100
FROM ${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

83110
ENV NVIDIA_DISABLE_REQUIRE="true"
84111
ENV NVIDIA_VISIBLE_DEVICES=all
@@ -97,15 +124,24 @@ LABEL description="NVIDIA DRA Driver for GPUs"
97124
LABEL org.opencontainers.image.description="NVIDIA DRA Driver for GPUs"
98125
LABEL 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

105130
COPY --from=toolkit /artifacts/rpm/usr/bin/nvidia-cdi-hook /usr/bin/nvidia-cdi-hook
131+
COPY --from=build /bashbuild/bash /bin/bash
106132
COPY --from=build /artifacts/compute-domain-controller /usr/bin/compute-domain-controller
107133
COPY --from=build /artifacts/compute-domain-kubelet-plugin /usr/bin/compute-domain-kubelet-plugin
108134
COPY --from=build /artifacts/compute-domain-daemon /usr/bin/compute-domain-daemon
109135
COPY --from=build /artifacts/gpu-kubelet-plugin /usr/bin/gpu-kubelet-plugin
110136
COPY /hack/kubelet-plugin-prestart.sh /usr/bin/kubelet-plugin-prestart.sh
111137
COPY /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"]

deployments/container/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ $(IMAGE_TARGETS): image-%:
8484
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
8585
--tag $(IMAGE) \
8686
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
87+
--build-arg BASH_STATIC_GIT_REF="$(BASH_STATIC_GIT_REF)" \
8788
--build-arg TOOLKIT_CONTAINER_IMAGE="$(TOOLKIT_CONTAINER_IMAGE)" \
8889
--build-arg VERSION="$(VERSION)" \
8990
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \

deployments/devel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ DOCKERFILE_CONTEXT = deployments/devel
4343
$(DOCKER) build \
4444
--progress=plain \
4545
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
46+
--build-arg BASH_STATIC_GIT_REF="$(BASH_STATIC_GIT_REF)" \
4647
--build-arg TOOLKIT_CONTAINER_IMAGE="$(TOOLKIT_CONTAINER_IMAGE)" \
4748
--tag $(BUILDIMAGE) \
4849
-f $(DOCKERFILE_DEVEL) \

versions.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ vVERSION := v$(VERSION:v%=%)
2929

3030
GOLANG_VERSION := $(shell ./hack/golang-version.sh)
3131
TOOLKIT_CONTAINER_IMAGE := $(shell ./hack/toolkit-container-image.sh)
32+
BASH_STATIC_GIT_REF := 021f5f29f665c92ca16a369d9f27e288c3aed0c6
3233

3334
# These variables are only needed when building a local image
3435
BUILDIMAGE_TAG ?= devel-go$(GOLANG_VERSION)

0 commit comments

Comments
 (0)