From f9b712bebe7c46e62524c4676dd3e43c2d3ed5de Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Mon, 15 Jan 2024 00:25:54 +0100 Subject: [PATCH] feat[close #263]: Support custom home directories for stacks/subsystems --- VERSION | 2 +- cmd/subsyStems.go | 11 ++++++++++- core/dbox.go | 6 +++++- core/subSystem.go | 5 ++++- locales/en.yml | 2 ++ main.go | 2 +- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index e3a4f193..cc6612c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 \ No newline at end of file +2.3.0 \ No newline at end of file diff --git a/cmd/subsyStems.go b/cmd/subsyStems.go index 28efa85c..d67f5cfb 100644 --- a/cmd/subsyStems.go +++ b/cmd/subsyStems.go @@ -70,6 +70,14 @@ func NewSubSystemsCommand() *cmdr.Command { "", ), ) + newCmd.WithStringFlag( + cmdr.NewStringFlag( + "home", + "H", + apx.Trans("subsystems.new.options.home.description"), + "", + ), + ) newCmd.WithBoolFlag( cmdr.NewBoolFlag( "init", @@ -181,6 +189,7 @@ func listSubSystems(cmd *cobra.Command, args []string) error { } func newSubSystem(cmd *cobra.Command, args []string) error { + home, _ := cmd.Flags().GetString("home") stackName, _ := cmd.Flags().GetString("stack") subSystemName, _ := cmd.Flags().GetString("name") isInit, _ := cmd.Flags().GetBool("init") @@ -233,7 +242,7 @@ func newSubSystem(cmd *cobra.Command, args []string) error { return err } - subSystem, err := core.NewSubSystem(subSystemName, stack, isInit, false, false, false, true) + subSystem, err := core.NewSubSystem(subSystemName, stack, home, isInit, false, false, false, true) if err != nil { return err } diff --git a/core/dbox.go b/core/dbox.go index 99fe993a..06d8a439 100644 --- a/core/dbox.go +++ b/core/dbox.go @@ -221,7 +221,7 @@ func (d *dbox) ContainerDelete(name string, rootFull bool) error { return err } -func (d *dbox) CreateContainer(name string, image string, additionalPackages []string, labels map[string]string, withInit bool, rootFull bool, unshared bool, withNvidiaIntegration bool) error { +func (d *dbox) CreateContainer(name string, image string, additionalPackages []string, home string, labels map[string]string, withInit bool, rootFull bool, unshared bool, withNvidiaIntegration bool) error { args := []string{ "--image", image, "--name", name, @@ -230,6 +230,10 @@ func (d *dbox) CreateContainer(name string, image string, additionalPackages []s "--pull", } + if home != "" { + args = append(args, "--home", home) + } + if hasNvidiaGPU() && withNvidiaIntegration { args = append(args, "--nvidia") } diff --git a/core/subSystem.go b/core/subSystem.go index 99b47413..e3532be3 100644 --- a/core/subSystem.go +++ b/core/subSystem.go @@ -24,6 +24,7 @@ type SubSystem struct { InternalName string Name string Stack *Stack + Home string Status string ExportedPrograms map[string]map[string]string HasInit bool @@ -33,12 +34,13 @@ type SubSystem struct { HasNvidiaIntegration bool } -func NewSubSystem(name string, stack *Stack, hasInit bool, isManaged bool, isRootfull bool, isUnshared bool, hasNvidiaIntegration bool) (*SubSystem, error) { +func NewSubSystem(name string, stack *Stack, home string, hasInit bool, isManaged bool, isRootfull bool, isUnshared bool, hasNvidiaIntegration bool) (*SubSystem, error) { internalName := genInternalName(name) return &SubSystem{ InternalName: internalName, Name: name, Stack: stack, + Home: home, HasInit: hasInit, IsManaged: isManaged, IsRootfull: isRootfull, @@ -142,6 +144,7 @@ func (s *SubSystem) Create() error { s.InternalName, s.Stack.Base, s.Stack.Packages, + s.Home, labels, s.HasInit, s.IsRootfull, diff --git a/locales/en.yml b/locales/en.yml index 0e591d8b..2e4b18ac 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -343,6 +343,8 @@ subsystems: description: "The name of the subsystem." stack: description: "The stack to use." + home: + description: "The custom home directory of the subsystem." info: description: "Use systemd inside the subsystem." rm: diff --git a/main.go b/main.go index 15ced1a5..c71e61f8 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( ) var ( - Version = "2.2.0" + Version = "2.3.0" ) //go:embed locales/*.yml