mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
[no-relnote] Use NVIDIA_CTK_CONFIG_FILE_PATH in toolkit install
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
f672d38aa5
commit
849691d290
@ -11,10 +11,6 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
driverPath = "/run/nvidia/driver"
|
|
||||||
)
|
|
||||||
|
|
||||||
// hookConfig wraps the toolkit config.
|
// hookConfig wraps the toolkit config.
|
||||||
// This allows for functions to be defined on the local type.
|
// This allows for functions to be defined on the local type.
|
||||||
type hookConfig struct {
|
type hookConfig struct {
|
||||||
|
@ -28,7 +28,7 @@ type createDirectory struct {
|
|||||||
logger logger.Interface
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolkitInstaller) createDirectory() Installer {
|
func (t *ToolkitInstaller) createDirectory() Installer {
|
||||||
return &createDirectory{
|
return &createDirectory{
|
||||||
logger: t.logger,
|
logger: t.logger,
|
||||||
}
|
}
|
||||||
|
@ -28,20 +28,18 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/operator"
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/operator"
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type executable struct {
|
type executable struct {
|
||||||
requiresKernelModule bool
|
requiresKernelModule bool
|
||||||
path string
|
path string
|
||||||
symlink string
|
symlink string
|
||||||
args []string
|
|
||||||
env map[string]string
|
env map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, error) {
|
func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, error) {
|
||||||
configHome := filepath.Join(destDir, ".config")
|
configFilePath := t.ConfigFilePath(destDir)
|
||||||
configDir := filepath.Join(configHome, "nvidia-container-runtime")
|
|
||||||
configPath := filepath.Join(configDir, "config.toml")
|
|
||||||
|
|
||||||
executables := []executable{
|
executables := []executable{
|
||||||
{
|
{
|
||||||
@ -56,7 +54,7 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
path: runtime.Path,
|
path: runtime.Path,
|
||||||
requiresKernelModule: true,
|
requiresKernelModule: true,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"XDG_CONFIG_HOME": configHome,
|
config.FilePathOverrideEnvVar: configFilePath,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
executables = append(executables, e)
|
executables = append(executables, e)
|
||||||
@ -72,7 +70,9 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
executable{
|
executable{
|
||||||
path: "nvidia-container-runtime-hook",
|
path: "nvidia-container-runtime-hook",
|
||||||
symlink: "nvidia-container-toolkit",
|
symlink: "nvidia-container-toolkit",
|
||||||
args: []string{fmt.Sprintf("-config %s", configPath)},
|
env: map[string]string{
|
||||||
|
config.FilePathOverrideEnvVar: configFilePath,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -94,7 +94,6 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
Source: executablePath,
|
Source: executablePath,
|
||||||
WrappedExecutable: dotRealFilename,
|
WrappedExecutable: dotRealFilename,
|
||||||
CheckModules: executable.requiresKernelModule,
|
CheckModules: executable.requiresKernelModule,
|
||||||
Args: executable.args,
|
|
||||||
Envvars: map[string]string{
|
Envvars: map[string]string{
|
||||||
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
|
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
|
||||||
},
|
},
|
||||||
@ -124,7 +123,6 @@ type wrapper struct {
|
|||||||
Envvars map[string]string
|
Envvars map[string]string
|
||||||
WrappedExecutable string
|
WrappedExecutable string
|
||||||
CheckModules bool
|
CheckModules bool
|
||||||
Args []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type render struct {
|
type render struct {
|
||||||
@ -165,9 +163,6 @@ fi
|
|||||||
{{$key}}={{$value}} \
|
{{$key}}={{$value}} \
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ .DestDir }}/{{ .WrappedExecutable }} \
|
{{ .DestDir }}/{{ .WrappedExecutable }} \
|
||||||
{{- range $arg := .Args }}
|
|
||||||
{{$arg}} \
|
|
||||||
{{- end }}
|
|
||||||
"$@"
|
"$@"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -68,19 +68,6 @@ fi
|
|||||||
PATH=/foo/bar/baz \
|
PATH=/foo/bar/baz \
|
||||||
/dest-dir/some-runtime \
|
/dest-dir/some-runtime \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: "args are added",
|
|
||||||
w: &wrapper{
|
|
||||||
WrappedExecutable: "some-runtime",
|
|
||||||
Args: []string{"--config foo", "bar"},
|
|
||||||
},
|
|
||||||
expected: `#! /bin/sh
|
|
||||||
/dest-dir/some-runtime \
|
|
||||||
--config foo \
|
|
||||||
bar \
|
|
||||||
"$@"
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ type Installer interface {
|
|||||||
Install(string) error
|
Install(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type toolkitInstaller struct {
|
type ToolkitInstaller struct {
|
||||||
logger logger.Interface
|
logger logger.Interface
|
||||||
ignoreErrors bool
|
ignoreErrors bool
|
||||||
sourceRoot string
|
sourceRoot string
|
||||||
@ -43,11 +43,11 @@ type toolkitInstaller struct {
|
|||||||
ensureTargetDirectory Installer
|
ensureTargetDirectory Installer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Installer = (*toolkitInstaller)(nil)
|
var _ Installer = (*ToolkitInstaller)(nil)
|
||||||
|
|
||||||
// New creates a toolkit installer with the specified options.
|
// New creates a toolkit installer with the specified options.
|
||||||
func New(opts ...Option) (Installer, error) {
|
func New(opts ...Option) (*ToolkitInstaller, error) {
|
||||||
t := &toolkitInstaller{
|
t := &ToolkitInstaller{
|
||||||
sourceRoot: "/",
|
sourceRoot: "/",
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -73,7 +73,7 @@ func New(opts ...Option) (Installer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install ensures that the required toolkit files are installed in the specified directory.
|
// Install ensures that the required toolkit files are installed in the specified directory.
|
||||||
func (t *toolkitInstaller) Install(destDir string) error {
|
func (t *ToolkitInstaller) Install(destDir string) error {
|
||||||
var installers []Installer
|
var installers []Installer
|
||||||
|
|
||||||
installers = append(installers, t.ensureTargetDirectory)
|
installers = append(installers, t.ensureTargetDirectory)
|
||||||
@ -98,6 +98,11 @@ func (t *toolkitInstaller) Install(destDir string) error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ToolkitInstaller) ConfigFilePath(destDir string) string {
|
||||||
|
toolkitConfigDir := filepath.Join(destDir, ".config", "nvidia-container-runtime")
|
||||||
|
return filepath.Join(toolkitConfigDir, "config.toml")
|
||||||
|
}
|
||||||
|
|
||||||
type symlink struct {
|
type symlink struct {
|
||||||
linkname string
|
linkname string
|
||||||
target string
|
target string
|
||||||
|
@ -112,7 +112,7 @@ func TestToolkitInstaller(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
i := toolkitInstaller{
|
i := ToolkitInstaller{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
artifactRoot: r,
|
artifactRoot: r,
|
||||||
ensureTargetDirectory: createDirectory,
|
ensureTargetDirectory: createDirectory,
|
||||||
@ -172,8 +172,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.real \
|
/foo/bar/baz/nvidia-container-runtime.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -187,8 +187,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.cdi.real \
|
/foo/bar/baz/nvidia-container-runtime.cdi.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -202,8 +202,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.legacy.real \
|
/foo/bar/baz/nvidia-container-runtime.legacy.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -240,9 +240,9 @@ PATH=/foo/bar/baz:$PATH \
|
|||||||
path: "/foo/bar/baz/nvidia-container-runtime-hook",
|
path: "/foo/bar/baz/nvidia-container-runtime-hook",
|
||||||
mode: 0777,
|
mode: 0777,
|
||||||
wrapper: `#! /bin/sh
|
wrapper: `#! /bin/sh
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
/foo/bar/baz/nvidia-container-runtime-hook.real \
|
/foo/bar/baz/nvidia-container-runtime-hook.real \
|
||||||
-config /foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
// A predefined set of library candidates are considered, with the first one
|
// A predefined set of library candidates are considered, with the first one
|
||||||
// resulting in success being installed to the toolkit folder. The install process
|
// resulting in success being installed to the toolkit folder. The install process
|
||||||
// resolves the symlink for the library and copies the versioned library itself.
|
// resolves the symlink for the library and copies the versioned library itself.
|
||||||
func (t *toolkitInstaller) collectLibraries() ([]Installer, error) {
|
func (t *ToolkitInstaller) collectLibraries() ([]Installer, error) {
|
||||||
requiredLibraries := []string{
|
requiredLibraries := []string{
|
||||||
"libnvidia-container.so.1",
|
"libnvidia-container.so.1",
|
||||||
"libnvidia-container-go.so.1",
|
"libnvidia-container-go.so.1",
|
||||||
|
@ -19,29 +19,29 @@ package installer
|
|||||||
|
|
||||||
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
|
|
||||||
type Option func(*toolkitInstaller)
|
type Option func(*ToolkitInstaller)
|
||||||
|
|
||||||
func WithLogger(logger logger.Interface) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.logger = logger
|
ti.logger = logger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithArtifactRoot(artifactRoot *artifactRoot) Option {
|
func WithArtifactRoot(artifactRoot *artifactRoot) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.artifactRoot = artifactRoot
|
ti.artifactRoot = artifactRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithIgnoreErrors(ignoreErrors bool) Option {
|
func WithIgnoreErrors(ignoreErrors bool) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.ignoreErrors = ignoreErrors
|
ti.ignoreErrors = ignoreErrors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSourceRoot sets the root directory for locating artifacts to be installed.
|
// WithSourceRoot sets the root directory for locating artifacts to be installed.
|
||||||
func WithSourceRoot(sourceRoot string) Option {
|
func WithSourceRoot(sourceRoot string) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.sourceRoot = sourceRoot
|
ti.sourceRoot = sourceRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
// DefaultNvidiaDriverRoot specifies the default NVIDIA driver run directory
|
// DefaultNvidiaDriverRoot specifies the default NVIDIA driver run directory
|
||||||
DefaultNvidiaDriverRoot = "/run/nvidia/driver"
|
DefaultNvidiaDriverRoot = "/run/nvidia/driver"
|
||||||
|
|
||||||
configFilename = "config.toml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cdiOptions struct {
|
type cdiOptions struct {
|
||||||
@ -316,7 +314,7 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
|
|||||||
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not install toolkit components: %w", err))
|
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not install toolkit components: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = t.installToolkitConfig(cli, opts)
|
err = t.installToolkitConfig(cli, opts, toolkit.ConfigFilePath(t.toolkitRoot))
|
||||||
if err != nil && !opts.ignoreErrors {
|
if err != nil && !opts.ignoreErrors {
|
||||||
return fmt.Errorf("error installing NVIDIA container toolkit config: %v", err)
|
return fmt.Errorf("error installing NVIDIA container toolkit config: %v", err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -343,13 +341,11 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
|
|||||||
|
|
||||||
// installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
|
// installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
|
||||||
// that the settings are updated to match the desired install and nvidia driver directories.
|
// that the settings are updated to match the desired install and nvidia driver directories.
|
||||||
func (t *Installer) installToolkitConfig(c *cli.Context, opts *Options) error {
|
func (t *Installer) installToolkitConfig(c *cli.Context, opts *Options, toolkitConfigPath string) error {
|
||||||
toolkitConfigDir := filepath.Join(t.toolkitRoot, ".config", "nvidia-container-runtime")
|
|
||||||
toolkitConfigPath := filepath.Join(toolkitConfigDir, configFilename)
|
|
||||||
|
|
||||||
t.logger.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigPath)
|
t.logger.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigPath)
|
||||||
|
|
||||||
err := t.createDirectories(toolkitConfigDir)
|
err := t.createDirectories(filepath.Dir(toolkitConfigPath))
|
||||||
if err != nil && !opts.ignoreErrors {
|
if err != nil && !opts.ignoreErrors {
|
||||||
return fmt.Errorf("could not create required directories: %v", err)
|
return fmt.Errorf("could not create required directories: %v", err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user