mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +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:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/toolkit"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,10 +37,11 @@ var signalReceived = make(chan bool, 1)
|
||||
type options struct {
|
||||
toolkitInstallDir string
|
||||
|
||||
noDaemon bool
|
||||
runtime string
|
||||
pidFile string
|
||||
sourceRoot string
|
||||
noDaemon bool
|
||||
runtime string
|
||||
pidFile string
|
||||
sourceRoot string
|
||||
packageType string
|
||||
|
||||
toolkitOptions toolkit.Options
|
||||
runtimeOptions runtime.Options
|
||||
@@ -123,11 +125,17 @@ func (a app) build() *cli.App {
|
||||
EnvVars: []string{"TOOLKIT_INSTALL_DIR", "ROOT"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "source-root",
|
||||
Value: "/",
|
||||
Usage: "The folder where the required toolkit artifacts can be found",
|
||||
Name: "toolkit-source-root",
|
||||
Usage: "The folder where the required toolkit artifacts can be found. If this is not specified, the path /artifacts/{{ .ToolkitPackageType }} is used where ToolkitPackageType is the resolved package type",
|
||||
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",
|
||||
@@ -145,6 +153,15 @@ func (a app) build() *cli.App {
|
||||
}
|
||||
|
||||
func (a *app) Before(c *cli.Context, o *options) error {
|
||||
if o.sourceRoot == "" {
|
||||
sourceRoot, err := a.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),
|
||||
@@ -277,3 +294,35 @@ func (a *app) shutdown(pidFile string) {
|
||||
a.logger.Warningf("Unable to remove pidfile: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) resolveSourceRoot(hostRoot string, packageType string) (string, error) {
|
||||
resolvedPackageType, err := a.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 (a *app) resolvePackageType(hostRoot string, packageType string) (rPackageTypes string, rerr error) {
|
||||
if packageType != "" && packageType != "auto" {
|
||||
return packageType, nil
|
||||
}
|
||||
|
||||
locator := lookup.NewExecutableLocator(a.logger, hostRoot)
|
||||
if candidates, err := locator.Locate("/usr/bin/rpm"); err == nil && len(candidates) > 0 {
|
||||
return "rpm", nil
|
||||
}
|
||||
|
||||
if candidates, err := locator.Locate("/usr/bin/dpkg"); err == nil && len(candidates) > 0 {
|
||||
return "deb", nil
|
||||
}
|
||||
|
||||
return "deb", nil
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ swarm-resource = ""
|
||||
"--driver-root-ctr-path=" + hostRoot,
|
||||
"--pid-file=" + filepath.Join(testRoot, "toolkit.pid"),
|
||||
"--restart-mode=none",
|
||||
"--source-root=" + filepath.Join(artifactRoot, "deb"),
|
||||
"--toolkit-source-root=" + filepath.Join(artifactRoot, "deb"),
|
||||
}
|
||||
|
||||
err := app.Run(append(testArgs, tc.args...))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -215,7 +215,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
|
||||
|
||||
Reference in New Issue
Block a user