Skip to content

Commit 5bc2f50

Browse files
authored
Merge pull request #1154 from elezar/switch-to-distroless
Switch to distroless Base image
2 parents 0dddd5c + 6070681 commit 5bc2f50

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

.github/workflows/image.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ jobs:
7979
runs-on: ubuntu-latest
8080
strategy:
8181
matrix:
82-
dist:
83-
- ubi9
82+
target:
83+
- application
8484
- packaging
8585
needs: packages
8686
steps:
@@ -117,4 +117,4 @@ jobs:
117117
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
118118
run: |
119119
echo "${VERSION}"
120-
make -f deployments/container/Makefile build-${{ matrix.dist }}
120+
make -f deployments/container/Makefile build-${{ matrix.target }}

deployments/container/Dockerfile

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ ARG VERSION="N/A"
4848
ARG GIT_COMMIT="unknown"
4949
RUN make PREFIX=/artifacts/bin cmd-nvidia-ctk-installer
5050

51-
# The packaging stage collects the deb and rpm packages built for supported
52-
# architectures.
53-
FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi9 AS packaging
51+
# The packaging stage collects the deb and rpm packages built for
52+
# supported architectures.
53+
FROM nvcr.io/nvidia/distroless/go:v3.1.9-dev AS packaging
54+
55+
USER 0:0
56+
SHELL ["/busybox/sh", "-c"]
57+
RUN ln -s /busybox/sh /bin/sh
5458

5559
ARG ARTIFACTS_ROOT
5660
COPY ${ARTIFACTS_ROOT} /artifacts/packages/
5761

58-
WORKDIR /artifacts/packages
62+
WORKDIR /artifacts
5963

6064
# build-args are added to the manifest.txt file below.
6165
ARG PACKAGE_VERSION
@@ -70,7 +74,14 @@ RUN echo "#IMAGE_EPOCH=$(date '+%s')" > /artifacts/manifest.txt && \
7074
env | sed 's/^/#/g' >> /artifacts/manifest.txt && \
7175
find /artifacts/packages -iname '*.deb' -o -iname '*.rpm' >> /artifacts/manifest.txt
7276

73-
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
77+
LABEL name="NVIDIA Container Toolkit Packages"
78+
LABEL vendor="NVIDIA"
79+
LABEL version="${VERSION}"
80+
LABEL release="N/A"
81+
LABEL summary="deb and rpm packages for the NVIDIA Container Toolkit"
82+
LABEL description="See summary"
83+
84+
COPY LICENSE /licenses/
7485

7586
# The debpackages stage is used to extract the contents of deb packages.
7687
FROM nvcr.io/nvidia/cuda:12.9.0-base-ubuntu20.04 AS debpackages
@@ -116,13 +127,19 @@ RUN set -eux; \
116127
# - The extracted deb packages
117128
# - The extracted rpm packages
118129
# - The nvidia-ctk-installer binary
119-
FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi9 AS artifacts
130+
FROM scratch AS artifacts
120131

121132
COPY --from=rpmpackages /artifacts/rpm /artifacts/rpm
122133
COPY --from=debpackages /artifacts/deb /artifacts/deb
123134
COPY --from=build /artifacts/bin /artifacts/build
124135

125-
FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi9
136+
# The application stage contains the application used as a GPU Operator
137+
# operand.
138+
FROM nvcr.io/nvidia/distroless/go:v3.1.9-dev AS application
139+
140+
USER 0:0
141+
SHELL ["/busybox/sh", "-c"]
142+
RUN ln -s /busybox/sh /bin/sh
126143

127144
ENV NVIDIA_DISABLE_REQUIRE="true"
128145
ENV NVIDIA_VISIBLE_DEVICES=void
@@ -144,6 +161,11 @@ LABEL release="N/A"
144161
LABEL summary="Automatically Configure your Container Runtime for GPU support."
145162
LABEL description="See summary"
146163

147-
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
164+
COPY LICENSE /licenses/
148165

149166
ENTRYPOINT ["/work/nvidia-ctk-installer"]
167+
168+
# The GPU Operator exec's nvidia-toolkit in its entrypoint.
169+
# We create a symlink here to ensure compatibility with older
170+
# GPU Operator versions.
171+
RUN ln -s /work/nvidia-ctk-installer /work/nvidia-toolkit

deployments/container/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)
3838
OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)
3939

4040
##### Public rules #####
41-
DEFAULT_PUSH_TARGET := ubi9
41+
DEFAULT_PUSH_TARGET := application
4242
DISTRIBUTIONS := $(DEFAULT_PUSH_TARGET)
4343

4444
META_TARGETS := packaging
@@ -102,8 +102,6 @@ build: build-$(DEFAULT_PUSH_TARGET)
102102
push: push-$(DEFAULT_PUSH_TARGET)
103103

104104
# Test targets
105-
test-%: DIST = $(*)
106-
107105
TEST_CASES ?= docker crio containerd
108106
$(TEST_TARGETS): test-%:
109107
TEST_CASES="$(TEST_CASES)" bash -x $(CURDIR)/test/container/main.sh run \

hack/pull-packages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ docker run --rm \
5353
-v $(pwd):$(pwd) \
5454
-w $(pwd) \
5555
-u $(id -u):$(id -g) \
56-
--entrypoint="bash" \
56+
--entrypoint="sh" \
5757
${IMAGE} \
58-
-c "cp --preserve=timestamps -R /artifacts/* ${DIST_DIR}"
58+
-c "cp -p -R /artifacts/* ${DIST_DIR}"

scripts/extract-packages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function copy-file() {
7070
-v "$(pwd):$(pwd)" \
7171
-w "$(pwd)" \
7272
-u "$(id -u):$(id -g)" \
73-
--entrypoint="bash" \
73+
--entrypoint="sh" \
7474
"${image}" \
75-
-c "cp ${path_in_image} ${path_on_host}"
75+
-c "cp -p ${path_in_image} ${path_on_host}"
7676
fi
7777
}
7878

scripts/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ function copy_file() {
9696
-v "$(pwd):$(pwd)" \
9797
-w "$(pwd)" \
9898
-u "$(id -u):$(id -g)" \
99-
--entrypoint="bash" \
99+
--entrypoint="sh" \
100100
"${image}" \
101-
-c "cp ${path_in_image} ${path_on_host}"
101+
-c "cp -p ${path_in_image} ${path_on_host}"
102102
fi
103103
}
104104

0 commit comments

Comments
 (0)