Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/cmd/initContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"syscall"
"time"

"github.com/containers/toolbox/pkg/config"
"github.com/containers/toolbox/pkg/nvidia"
"github.com/containers/toolbox/pkg/shell"
"github.com/containers/toolbox/pkg/utils"
"github.com/fsnotify/fsnotify"
Expand Down Expand Up @@ -283,6 +285,15 @@ func initContainer(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to look up user ID %s: %w", uidString, err)
}

cfg, err := config.GetRunningContainerConfig(
filepath.Join(initContainerFlags.home, ".config"),
initContainerFlags.uid,
initContainerFlags.gid,
)
if err != nil {
logrus.Debugf("Failed to load container configuration: %s", err)
}

cdiFileForNvidia, err := getCDIFileForNvidia(targetUser)
if err != nil {
return err
Expand All @@ -302,6 +313,10 @@ func initContainer(cmd *cobra.Command, args []string) error {
}

if cdiSpecForNvidia != nil {
if err := nvidia.PatchConfigForMultilib(cfg); err != nil {
return err
}

if err := applyCDISpecForNvidia(cdiSpecForNvidia); err != nil {
return err
}
Expand Down Expand Up @@ -437,9 +452,8 @@ func applyCDISpecForNvidia(spec *specs.Spec) error {
continue
}

flags := strings.Join(mount.Options, ",")
hostPath := filepath.Join(string(filepath.Separator), "run", "host", mount.HostPath)
if err := mountBind(mount.ContainerPath, hostPath, flags); err != nil {
if err := mountExt(mount.ContainerPath, hostPath, "", mount.Options...); err != nil {
logrus.Debugf("Applying Container Device Interface for NVIDIA: %s", err)
return errors.New("failed to apply mount from Container Device Interface for NVIDIA")
}
Expand Down Expand Up @@ -1001,7 +1015,7 @@ func loadCDISpecFrom(path string) (*specs.Spec, error) {
return spec, nil
}

func mountBind(containerPath, source, flags string) error {
func mountExt(containerPath, source string, flag string, opts ...string) error {
fi, err := os.Stat(source)
if err != nil {
if os.IsNotExist(err) {
Expand Down Expand Up @@ -1036,12 +1050,14 @@ func mountBind(containerPath, source, flags string) error {

logrus.Debugf("Binding %s to %s", containerPath, source)

args := []string{
"--rbind",
args := make([]string, 0, 2)

if flag != "" {
args = append(args, flag)
}

if flags != "" {
args = append(args, []string{"-o", flags}...)
if len(opts) > 0 {
args = append(args, []string{"-o", strings.Join(opts, ",")}...)
}

args = append(args, []string{source, containerPath}...)
Expand All @@ -1053,6 +1069,10 @@ func mountBind(containerPath, source, flags string) error {
return nil
}

func mountBind(containerPath, source, flags string) error {
return mountExt(containerPath, source, "--rbind", strings.Split(flags, ",")...)
}

// redirectPath serves for creating symbolic links for crucial system
// configuration files to their counterparts on the host's file system.
//
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"strings"

"github.com/containers/toolbox/pkg/config"
"github.com/containers/toolbox/pkg/podman"
"github.com/containers/toolbox/pkg/utils"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -83,6 +84,10 @@ func rm(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
continue
}

if cfg, _ := config.GetContainerConfig(container.Name()); cfg != nil {
cfg.Delete()
}
}
} else {
if len(args) == 0 {
Expand Down Expand Up @@ -110,6 +115,10 @@ func rm(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
continue
}

if cfg, _ := config.GetContainerConfig(containerObj.Name()); cfg != nil {
cfg.Delete()
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"syscall"
"time"

"github.com/containers/toolbox/pkg/config"
"github.com/containers/toolbox/pkg/nvidia"
"github.com/containers/toolbox/pkg/podman"
"github.com/containers/toolbox/pkg/shell"
Expand Down Expand Up @@ -345,8 +346,13 @@ func runCommand(container string,
}

logrus.Debugf("Container %s is initialized", container)

environ := append(cdiEnviron, p11KitServerEnviron...)

cfg, err := config.GetContainerConfig(container)
if cfg != nil {
environ = append(environ, cfg.ListEnv()...)
}

if err := runCommandWithFallbacks(container,
preserveFDs,
command,
Expand Down
47 changes: 25 additions & 22 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
module github.com/containers/toolbox

go 1.22.0
go 1.25.6

require (
github.com/HarryMichal/go-version v1.0.1
github.com/NVIDIA/go-nvlib v0.7.2
github.com/NVIDIA/go-nvml v0.12.4-1
github.com/NVIDIA/nvidia-container-toolkit v1.17.8
github.com/NVIDIA/go-nvlib v0.9.1-0.20251202135446-d0f42ba016dd
github.com/NVIDIA/go-nvml v0.13.0-1.0.20260212130905-92cf8c963449
github.com/NVIDIA/nvidia-container-toolkit v1.19.1
github.com/acobaugh/osrelease v0.1.0
github.com/briandowns/spinner v1.23.2
github.com/docker/go-units v0.5.0
github.com/fsnotify/fsnotify v1.8.0
github.com/fsnotify/fsnotify v1.10.1
github.com/go-logfmt/logfmt v0.5.0
github.com/godbus/dbus/v5 v5.0.6
github.com/godbus/dbus/v5 v5.2.2
github.com/google/renameio/v2 v2.0.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1
github.com/sirupsen/logrus v1.9.4
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.29.0
tags.cncf.io/container-device-interface v0.8.1
tags.cncf.io/container-device-interface/specs-go v0.8.0
github.com/stretchr/testify v1.11.1
go.podman.io/podman/v6 v6.0.2
golang.org/x/sys v0.46.0
tags.cncf.io/container-device-interface v1.1.0
tags.cncf.io/container-device-interface/specs-go v1.1.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/opencontainers/runtime-spec v1.2.1 // indirect
github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 // indirect
github.com/moby/sys/capability v0.4.0 // indirect
github.com/opencontainers/cgroups v0.0.6 // indirect
github.com/opencontainers/runc v1.4.2 // indirect
github.com/opencontainers/runtime-spec v1.3.0 // indirect
github.com/opencontainers/runtime-tools v0.9.1-0.20260316125833-8a4db579f5c8 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/term v0.44.0 // indirect
golang.org/x/text v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
Loading