mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-02 12:00:18 +00:00
Extract deb and rpm packages to single image
Some checks failed
Some checks failed
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 <elezar@nvidia.com>
This commit is contained in:
parent
23bd41163c
commit
ba65c1114b
@ -40,6 +40,7 @@ type options struct {
|
||||
root string
|
||||
pidFile string
|
||||
sourceRoot string
|
||||
packageType string
|
||||
|
||||
toolkitOptions toolkit.Options
|
||||
runtimeOptions runtime.Options
|
||||
@ -141,11 +142,18 @@ func (a app) build() *cli.App {
|
||||
EnvVars: []string{"ROOT"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "source-root",
|
||||
Name: "toolkit-source-root",
|
||||
Value: "/",
|
||||
Usage: "The folder where the required toolkit artifacts can be found",
|
||||
Destination: &options.sourceRoot,
|
||||
EnvVars: []string{"SOURCE_ROOT"},
|
||||
EnvVars: []string{"TOOLKIT_SOURCE_ROOT"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "toolkit-package-type",
|
||||
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.",
|
||||
Value: "auto",
|
||||
Destination: &options.packageType,
|
||||
EnvVars: []string{"TOOLKIT_PACKAGE_TYPE"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pid-file",
|
||||
@ -163,6 +171,15 @@ func (a app) build() *cli.App {
|
||||
}
|
||||
|
||||
func (a *app) Before(c *cli.Context, o *options) error {
|
||||
if o.sourceRoot == "" {
|
||||
sourceRoot, err := resolveSourceRoot(o.runtimeOptions.HostRootMount, o.packageType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve source root: %v", err)
|
||||
}
|
||||
a.logger.Infof("Resolved source root to %v", sourceRoot)
|
||||
o.sourceRoot = sourceRoot
|
||||
}
|
||||
|
||||
a.toolkit = toolkit.NewInstaller(
|
||||
toolkit.WithLogger(a.logger),
|
||||
toolkit.WithSourceRoot(o.sourceRoot),
|
||||
@ -323,3 +340,33 @@ func (a *app) shutdown(pidFile string) {
|
||||
a.logger.Warningf("Unable to remove pidfile: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func resolveSourceRoot(hostRoot string, packageType string) (string, error) {
|
||||
resolvedPackageType, err := resolvePackageType(hostRoot, packageType)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
switch resolvedPackageType {
|
||||
case "deb":
|
||||
return "/artifacts/deb", nil
|
||||
case "rpm":
|
||||
return "/artifacts/rpm", nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid package type: %v", resolvedPackageType)
|
||||
}
|
||||
}
|
||||
|
||||
func resolvePackageType(hostRoot string, packageType string) (rPackageTypes string, rerr error) {
|
||||
if packageType != "" && packageType != "auto" {
|
||||
return packageType, nil
|
||||
}
|
||||
|
||||
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/rpm")); err != nil && !info.IsDir() {
|
||||
return "rpm", nil
|
||||
}
|
||||
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/dpkg")); err != nil && !info.IsDir() {
|
||||
return "deb", nil
|
||||
}
|
||||
|
||||
return "deb", nil
|
||||
}
|
||||
|
@ -47,7 +47,9 @@ var _ Installer = (*toolkitInstaller)(nil)
|
||||
|
||||
// New creates a toolkit installer with the specified options.
|
||||
func New(opts ...Option) (Installer, error) {
|
||||
t := &toolkitInstaller{}
|
||||
t := &toolkitInstaller{
|
||||
sourceRoot: "/",
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(t)
|
||||
}
|
||||
@ -55,9 +57,6 @@ func New(opts ...Option) (Installer, error) {
|
||||
if t.logger == nil {
|
||||
t.logger = logger.New()
|
||||
}
|
||||
if t.sourceRoot == "" {
|
||||
t.sourceRoot = "/"
|
||||
}
|
||||
if t.artifactRoot == nil {
|
||||
artifactRoot, err := newArtifactRoot(t.logger, t.sourceRoot)
|
||||
if err != nil {
|
||||
|
19
cmd/nvidia-ctk-installer/toolkit/installer/package-type.go
Normal file
19
cmd/nvidia-ctk-installer/toolkit/installer/package-type.go
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
*
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
*
|
||||
*/
|
||||
package installer
|
@ -211,7 +211,8 @@ func Flags(opts *Options) []cli.Flag {
|
||||
|
||||
// An Installer is used to install the NVIDIA Container Toolkit from the toolkit container.
|
||||
type Installer struct {
|
||||
logger logger.Interface
|
||||
logger logger.Interface
|
||||
|
||||
sourceRoot string
|
||||
// toolkitRoot specifies the destination path at which the toolkit is installed.
|
||||
toolkitRoot string
|
||||
|
@ -47,33 +47,85 @@ ARG VERSION="N/A"
|
||||
ARG GIT_COMMIT="unknown"
|
||||
RUN make PREFIX=/artifacts cmd-nvidia-ctk-installer
|
||||
|
||||
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8
|
||||
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS packaging
|
||||
|
||||
ARG ARTIFACTS_ROOT
|
||||
COPY ${ARTIFACTS_ROOT} /artifacts/packages/
|
||||
|
||||
WORKDIR /artifacts/packages
|
||||
|
||||
# build-args are added to the manifest.txt file below.
|
||||
ARG PACKAGE_DIST
|
||||
ARG PACKAGE_VERSION
|
||||
ARG GIT_BRANCH
|
||||
ARG GIT_COMMIT
|
||||
ARG GIT_COMMIT_SHORT
|
||||
ARG SOURCE_DATE_EPOCH
|
||||
ARG VERSION
|
||||
|
||||
# Create a manifest.txt file with the absolute paths of all deb and rpm packages in the container
|
||||
RUN echo "#IMAGE_EPOCH=$(date '+%s')" > /artifacts/manifest.txt && \
|
||||
env | sed 's/^/#/g' >> /artifacts/manifest.txt && \
|
||||
find /artifacts/packages -iname '*.deb' -o -iname '*.rpm' >> /artifacts/manifest.txt
|
||||
|
||||
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
|
||||
|
||||
# The rpmpackages stage is used to extract the contents of the rpm packages.
|
||||
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS rpmpackages
|
||||
RUN dnf install -y cpio
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG PACKAGE_DIST_RPM=centos7
|
||||
|
||||
COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_RPM} /rpm-packages
|
||||
|
||||
RUN mkdir -p /artifacts/rpm
|
||||
RUN set -eux; \
|
||||
\
|
||||
case "${TARGETARCH}" in \
|
||||
x86_64 | amd64) ARCH='x86_64' ;; \
|
||||
ppc64el | ppc64le) ARCH='ppc64le' ;; \
|
||||
aarch64 | arm64) ARCH='aarch64' ;; \
|
||||
*) echo "unsupported architecture" ; exit 1 ;; \
|
||||
esac; \
|
||||
for p in $(ls /rpm-packages/${ARCH}/*.rpm); do rpm2cpio $p | cpio -idmv -D /artifacts/rpm; done
|
||||
|
||||
# The debpackages stage is used to extract the contents of deb packages.
|
||||
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu20.04 AS debpackages
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG PACKAGE_DIST_DEB=ubuntu18.04
|
||||
|
||||
COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_DEB} /deb-packages
|
||||
|
||||
RUN mkdir -p /artifacts/deb
|
||||
RUN set -eux; \
|
||||
\
|
||||
case "${TARGETARCH}" in \
|
||||
x86_64 | amd64) ARCH='amd64' ;; \
|
||||
ppc64el | ppc64le) ARCH='ppc64le' ;; \
|
||||
aarch64 | arm64) ARCH='arm64' ;; \
|
||||
*) echo "unsupported architecture" ; exit 1 ;; \
|
||||
esac; \
|
||||
for p in $(ls /deb-packages/${ARCH}/*.deb); do dpkg-deb -xv $p /artifacts/deb/; done
|
||||
|
||||
FROM nvcr.io/nvidia/cuda:12.8.1-base-ubi8 AS artifacts
|
||||
|
||||
COPY --from=rpmpackages /artifacts/rpm /artifacts/rpm
|
||||
COPY --from=debpackages /artifacts/deb /artifacts/deb
|
||||
COPY --from=build /artifacts/bin /artifacts/build
|
||||
|
||||
FROM nvcr.io/nvidia/cuda:12.6.2-base-ubi8
|
||||
|
||||
ENV NVIDIA_DISABLE_REQUIRE="true"
|
||||
ENV NVIDIA_VISIBLE_DEVICES=void
|
||||
ENV NVIDIA_DRIVER_CAPABILITIES=utility
|
||||
|
||||
ARG ARTIFACTS_ROOT
|
||||
ARG PACKAGE_DIST
|
||||
COPY ${ARTIFACTS_ROOT}/${PACKAGE_DIST} /artifacts/packages/${PACKAGE_DIST}
|
||||
|
||||
WORKDIR /artifacts/packages
|
||||
|
||||
ARG PACKAGE_VERSION
|
||||
ARG TARGETARCH
|
||||
ENV PACKAGE_ARCH=${TARGETARCH}
|
||||
|
||||
RUN PACKAGE_ARCH=${PACKAGE_ARCH/amd64/x86_64} && PACKAGE_ARCH=${PACKAGE_ARCH/arm64/aarch64} && \
|
||||
yum localinstall -y \
|
||||
${PACKAGE_DIST}/${PACKAGE_ARCH}/libnvidia-container1-1.*.rpm \
|
||||
${PACKAGE_DIST}/${PACKAGE_ARCH}/libnvidia-container-tools-1.*.rpm \
|
||||
${PACKAGE_DIST}/${PACKAGE_ARCH}/nvidia-container-toolkit*-${PACKAGE_VERSION}*.rpm
|
||||
COPY --from=artifacts /artifacts/rpm /artifacts/rpm
|
||||
COPY --from=artifacts /artifacts/deb /artifacts/deb
|
||||
COPY --from=artifacts /artifacts/build /work
|
||||
|
||||
WORKDIR /work
|
||||
|
||||
COPY --from=build /artifacts/nvidia-ctk-installer /work/nvidia-ctk-installer
|
||||
RUN ln -s nvidia-ctk-installer nvidia-toolkit
|
||||
|
||||
ENV PATH=/work:$PATH
|
||||
|
||||
ARG VERSION
|
||||
|
@ -90,10 +90,13 @@ $(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
|
||||
--provenance=false --sbom=false \
|
||||
$(DOCKER_BUILD_OPTIONS) \
|
||||
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
|
||||
$(INTERMEDIATE_TARGET) \
|
||||
--tag $(IMAGE) \
|
||||
--build-arg ARTIFACTS_ROOT="$(ARTIFACTS_ROOT)" \
|
||||
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
|
||||
--build-arg PACKAGE_DIST="$(PACKAGE_DIST)" \
|
||||
--build-arg PACKAGE_DIST_DEB="$(PACKAGE_DIST_DEB)" \
|
||||
--build-arg PACKAGE_DIST_RPM="$(PACKAGE_DIST_RPM)" \
|
||||
--build-arg PACKAGE_VERSION="$(PACKAGE_VERSION)" \
|
||||
--build-arg VERSION="$(VERSION)" \
|
||||
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
|
||||
@ -103,14 +106,19 @@ $(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
|
||||
-f $(DOCKERFILE) \
|
||||
$(CURDIR)
|
||||
|
||||
|
||||
PACKAGE_DIST_DEB = ubuntu18.04
|
||||
# TODO: This needs to be set to centos8 for ppc64le builds
|
||||
PACKAGE_DIST_RPM = centos7
|
||||
|
||||
build-ubuntu%: DOCKERFILE_SUFFIX := ubuntu
|
||||
build-ubuntu%: PACKAGE_DIST = ubuntu18.04
|
||||
|
||||
build-ubi8: DOCKERFILE_SUFFIX := ubi8
|
||||
build-ubi8: PACKAGE_DIST = centos7
|
||||
|
||||
build-packaging: DOCKERFILE_SUFFIX := packaging
|
||||
build-packaging: PACKAGE_ARCH := amd64
|
||||
build-packaging: DOCKERFILE_SUFFIX := ubi8
|
||||
build-packaging: INTERMEDIATE_TARGET := --target=packaging
|
||||
build-packaging: PACKAGE_DIST = all
|
||||
|
||||
# Test targets
|
||||
|
Loading…
Reference in New Issue
Block a user