Skip to content

Commit ba65c11

Browse files
committed
Extract deb and rpm packages to single image
This change swithces to using a single image for the NVIDIA Container Toolkit contianer. Here the contents of the architecture-specific deb and rpm packages are extracted to a known root. These contents can then be installed using the updated installation mechanism which has been updated to detect the source root based on the packaging type. Signed-off-by: Evan Lezar <[email protected]>
1 parent 23bd411 commit ba65c11

File tree

6 files changed

+151
-25
lines changed

6 files changed

+151
-25
lines changed

Diff for: cmd/nvidia-ctk-installer/main.go

+49-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type options struct {
4040
root string
4141
pidFile string
4242
sourceRoot string
43+
packageType string
4344

4445
toolkitOptions toolkit.Options
4546
runtimeOptions runtime.Options
@@ -141,11 +142,18 @@ func (a app) build() *cli.App {
141142
EnvVars: []string{"ROOT"},
142143
},
143144
&cli.StringFlag{
144-
Name: "source-root",
145+
Name: "toolkit-source-root",
145146
Value: "/",
146147
Usage: "The folder where the required toolkit artifacts can be found",
147148
Destination: &options.sourceRoot,
148-
EnvVars: []string{"SOURCE_ROOT"},
149+
EnvVars: []string{"TOOLKIT_SOURCE_ROOT"},
150+
},
151+
&cli.StringFlag{
152+
Name: "toolkit-package-type",
153+
Usage: "specify the package type to use for the toolkit. One of ['deb', 'rpm', 'auto', '']. If 'auto' or '' are used, the type is inferred automatically.",
154+
Value: "auto",
155+
Destination: &options.packageType,
156+
EnvVars: []string{"TOOLKIT_PACKAGE_TYPE"},
149157
},
150158
&cli.StringFlag{
151159
Name: "pid-file",
@@ -163,6 +171,15 @@ func (a app) build() *cli.App {
163171
}
164172

165173
func (a *app) Before(c *cli.Context, o *options) error {
174+
if o.sourceRoot == "" {
175+
sourceRoot, err := resolveSourceRoot(o.runtimeOptions.HostRootMount, o.packageType)
176+
if err != nil {
177+
return fmt.Errorf("failed to resolve source root: %v", err)
178+
}
179+
a.logger.Infof("Resolved source root to %v", sourceRoot)
180+
o.sourceRoot = sourceRoot
181+
}
182+
166183
a.toolkit = toolkit.NewInstaller(
167184
toolkit.WithLogger(a.logger),
168185
toolkit.WithSourceRoot(o.sourceRoot),
@@ -323,3 +340,33 @@ func (a *app) shutdown(pidFile string) {
323340
a.logger.Warningf("Unable to remove pidfile: %v", err)
324341
}
325342
}
343+
344+
func resolveSourceRoot(hostRoot string, packageType string) (string, error) {
345+
resolvedPackageType, err := resolvePackageType(hostRoot, packageType)
346+
if err != nil {
347+
return "", err
348+
}
349+
switch resolvedPackageType {
350+
case "deb":
351+
return "/artifacts/deb", nil
352+
case "rpm":
353+
return "/artifacts/rpm", nil
354+
default:
355+
return "", fmt.Errorf("invalid package type: %v", resolvedPackageType)
356+
}
357+
}
358+
359+
func resolvePackageType(hostRoot string, packageType string) (rPackageTypes string, rerr error) {
360+
if packageType != "" && packageType != "auto" {
361+
return packageType, nil
362+
}
363+
364+
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/rpm")); err != nil && !info.IsDir() {
365+
return "rpm", nil
366+
}
367+
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/dpkg")); err != nil && !info.IsDir() {
368+
return "deb", nil
369+
}
370+
371+
return "deb", nil
372+
}

Diff for: cmd/nvidia-ctk-installer/toolkit/installer/installer.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,16 @@ var _ Installer = (*toolkitInstaller)(nil)
4747

4848
// New creates a toolkit installer with the specified options.
4949
func New(opts ...Option) (Installer, error) {
50-
t := &toolkitInstaller{}
50+
t := &toolkitInstaller{
51+
sourceRoot: "/",
52+
}
5153
for _, opt := range opts {
5254
opt(t)
5355
}
5456

5557
if t.logger == nil {
5658
t.logger = logger.New()
5759
}
58-
if t.sourceRoot == "" {
59-
t.sourceRoot = "/"
60-
}
6160
if t.artifactRoot == nil {
6261
artifactRoot, err := newArtifactRoot(t.logger, t.sourceRoot)
6362
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
*
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
*
18+
*/
19+
package installer

Diff for: cmd/nvidia-ctk-installer/toolkit/toolkit.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ func Flags(opts *Options) []cli.Flag {
211211

212212
// An Installer is used to install the NVIDIA Container Toolkit from the toolkit container.
213213
type Installer struct {
214-
logger logger.Interface
214+
logger logger.Interface
215+
215216
sourceRoot string
216217
// toolkitRoot specifies the destination path at which the toolkit is installed.
217218
toolkitRoot string

Diff for: deployments/container/Dockerfile.ubi8

+68-16
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,85 @@ ARG VERSION="N/A"
4747
ARG GIT_COMMIT="unknown"
4848
RUN make PREFIX=/artifacts cmd-nvidia-ctk-installer
4949

50-
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8
51-
52-
ENV NVIDIA_DISABLE_REQUIRE="true"
53-
ENV NVIDIA_VISIBLE_DEVICES=void
54-
ENV NVIDIA_DRIVER_CAPABILITIES=utility
50+
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS packaging
5551

5652
ARG ARTIFACTS_ROOT
57-
ARG PACKAGE_DIST
58-
COPY ${ARTIFACTS_ROOT}/${PACKAGE_DIST} /artifacts/packages/${PACKAGE_DIST}
53+
COPY ${ARTIFACTS_ROOT} /artifacts/packages/
5954

6055
WORKDIR /artifacts/packages
6156

57+
# build-args are added to the manifest.txt file below.
58+
ARG PACKAGE_DIST
6259
ARG PACKAGE_VERSION
60+
ARG GIT_BRANCH
61+
ARG GIT_COMMIT
62+
ARG GIT_COMMIT_SHORT
63+
ARG SOURCE_DATE_EPOCH
64+
ARG VERSION
65+
66+
# Create a manifest.txt file with the absolute paths of all deb and rpm packages in the container
67+
RUN echo "#IMAGE_EPOCH=$(date '+%s')" > /artifacts/manifest.txt && \
68+
env | sed 's/^/#/g' >> /artifacts/manifest.txt && \
69+
find /artifacts/packages -iname '*.deb' -o -iname '*.rpm' >> /artifacts/manifest.txt
70+
71+
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
72+
73+
# The rpmpackages stage is used to extract the contents of the rpm packages.
74+
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS rpmpackages
75+
RUN dnf install -y cpio
76+
6377
ARG TARGETARCH
64-
ENV PACKAGE_ARCH=${TARGETARCH}
78+
ARG PACKAGE_DIST_RPM=centos7
6579

66-
RUN PACKAGE_ARCH=${PACKAGE_ARCH/amd64/x86_64} && PACKAGE_ARCH=${PACKAGE_ARCH/arm64/aarch64} && \
67-
yum localinstall -y \
68-
${PACKAGE_DIST}/${PACKAGE_ARCH}/libnvidia-container1-1.*.rpm \
69-
${PACKAGE_DIST}/${PACKAGE_ARCH}/libnvidia-container-tools-1.*.rpm \
70-
${PACKAGE_DIST}/${PACKAGE_ARCH}/nvidia-container-toolkit*-${PACKAGE_VERSION}*.rpm
80+
COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_RPM} /rpm-packages
7181

72-
WORKDIR /work
82+
RUN mkdir -p /artifacts/rpm
83+
RUN set -eux; \
84+
\
85+
case "${TARGETARCH}" in \
86+
x86_64 | amd64) ARCH='x86_64' ;; \
87+
ppc64el | ppc64le) ARCH='ppc64le' ;; \
88+
aarch64 | arm64) ARCH='aarch64' ;; \
89+
*) echo "unsupported architecture" ; exit 1 ;; \
90+
esac; \
91+
for p in $(ls /rpm-packages/${ARCH}/*.rpm); do rpm2cpio $p | cpio -idmv -D /artifacts/rpm; done
92+
93+
# The debpackages stage is used to extract the contents of deb packages.
94+
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu20.04 AS debpackages
7395

74-
COPY --from=build /artifacts/nvidia-ctk-installer /work/nvidia-ctk-installer
75-
RUN ln -s nvidia-ctk-installer nvidia-toolkit
96+
ARG TARGETARCH
97+
ARG PACKAGE_DIST_DEB=ubuntu18.04
98+
99+
COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_DEB} /deb-packages
100+
101+
RUN mkdir -p /artifacts/deb
102+
RUN set -eux; \
103+
\
104+
case "${TARGETARCH}" in \
105+
x86_64 | amd64) ARCH='amd64' ;; \
106+
ppc64el | ppc64le) ARCH='ppc64le' ;; \
107+
aarch64 | arm64) ARCH='arm64' ;; \
108+
*) echo "unsupported architecture" ; exit 1 ;; \
109+
esac; \
110+
for p in $(ls /deb-packages/${ARCH}/*.deb); do dpkg-deb -xv $p /artifacts/deb/; done
76111

112+
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS artifacts
113+
114+
COPY --from=rpmpackages /artifacts/rpm /artifacts/rpm
115+
COPY --from=debpackages /artifacts/deb /artifacts/deb
116+
COPY --from=build /artifacts/bin /artifacts/build
117+
118+
FROM nvcr.io/nvidia/cuda:12.6.2-base-ubi8
119+
120+
ENV NVIDIA_DISABLE_REQUIRE="true"
121+
ENV NVIDIA_VISIBLE_DEVICES=void
122+
ENV NVIDIA_DRIVER_CAPABILITIES=utility
123+
124+
COPY --from=artifacts /artifacts/rpm /artifacts/rpm
125+
COPY --from=artifacts /artifacts/deb /artifacts/deb
126+
COPY --from=artifacts /artifacts/build /work
127+
128+
WORKDIR /work
77129
ENV PATH=/work:$PATH
78130

79131
ARG VERSION

Diff for: deployments/container/Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ $(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
9090
--provenance=false --sbom=false \
9191
$(DOCKER_BUILD_OPTIONS) \
9292
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
93+
$(INTERMEDIATE_TARGET) \
9394
--tag $(IMAGE) \
9495
--build-arg ARTIFACTS_ROOT="$(ARTIFACTS_ROOT)" \
9596
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
9697
--build-arg PACKAGE_DIST="$(PACKAGE_DIST)" \
98+
--build-arg PACKAGE_DIST_DEB="$(PACKAGE_DIST_DEB)" \
99+
--build-arg PACKAGE_DIST_RPM="$(PACKAGE_DIST_RPM)" \
97100
--build-arg PACKAGE_VERSION="$(PACKAGE_VERSION)" \
98101
--build-arg VERSION="$(VERSION)" \
99102
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
@@ -103,14 +106,19 @@ $(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
103106
-f $(DOCKERFILE) \
104107
$(CURDIR)
105108

109+
110+
PACKAGE_DIST_DEB = ubuntu18.04
111+
# TODO: This needs to be set to centos8 for ppc64le builds
112+
PACKAGE_DIST_RPM = centos7
113+
106114
build-ubuntu%: DOCKERFILE_SUFFIX := ubuntu
107115
build-ubuntu%: PACKAGE_DIST = ubuntu18.04
108116

109117
build-ubi8: DOCKERFILE_SUFFIX := ubi8
110118
build-ubi8: PACKAGE_DIST = centos7
111119

112-
build-packaging: DOCKERFILE_SUFFIX := packaging
113-
build-packaging: PACKAGE_ARCH := amd64
120+
build-packaging: DOCKERFILE_SUFFIX := ubi8
121+
build-packaging: INTERMEDIATE_TARGET := --target=packaging
114122
build-packaging: PACKAGE_DIST = all
115123

116124
# Test targets

0 commit comments

Comments
 (0)