diff --git a/src/app/process.go b/src/app/process.go index e939c310..a3594401 100644 --- a/src/app/process.go +++ b/src/app/process.go @@ -222,6 +222,16 @@ func (p *Process) getCommander() command.Commander { p.procConf.Executable, p.mergeExtraArgs(), ) + } else if p.procConf.IsContainer && strings.ToLower(p.procConf.ContainerRuntime) == "apptainer" { + return command.BuildApptainerCommand( + p.procConf.ContainerRuntime, + p.procConf.ContainerExec, + p.procConf.ContainerVolumes, + p.procConf.ContainerArgs, + p.procConf.ContainerImage, + p.procConf.Executable, + p.mergeExtraArgs(), + ) } else { return command.BuildCommand( p.procConf.Executable, diff --git a/src/command/command.go b/src/command/command.go index c6e7f386..a29c1daf 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "runtime" + "strings" ) func BuildCommand(cmd string, args []string) *CmdWrapper { @@ -32,6 +33,18 @@ func BuildCommandShellArgContext(ctx context.Context, shell ShellConfig, cmd str } } +func BuildApptainerCommand(containerRuntime string, containerExecution string, containerVolumes []string, containerArgs []string, containerImage string, containerCmd string, cmdArgs []string) *CmdWrapper { + volumes := "-B " + strings.Join(containerVolumes, ",") + container_args := strings.Join(containerArgs, " ") + args_string := strings.Join(cmdArgs, " ") + + args := []string{containerExecution, volumes, container_args, containerImage, containerCmd, args_string} + + return &CmdWrapper{ + cmd: exec.Command(containerRuntime, args...), + } +} + func getRunnerShell() string { shell, ok := os.LookupEnv("COMPOSE_SHELL") if !ok { diff --git a/src/types/process.go b/src/types/process.go index b8b2de44..5c970d21 100644 --- a/src/types/process.go +++ b/src/types/process.go @@ -38,6 +38,12 @@ type ProcessConfig struct { IsForeground bool `yaml:"is_foreground"` IsTty bool `yaml:"is_tty"` IsElevated bool `yaml:"is_elevated"` + IsContainer bool `yaml:"is_container"` + ContainerRuntime string `yaml:"container_runtime"` + ContainerExec string `yaml:"container_execution"` + ContainerVolumes []string `yaml:"container_volumes"` + ContainerImage string `yaml:"container_image"` + ContainerArgs []string `yaml:"container_args"` ReplicaNum int ReplicaName string Executable string