/
runc_run_builder.go
46 lines (39 loc) · 1.17 KB
/
runc_run_builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dadoo
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
func BuildRuncCommand(runtimePath, runMode, runcRoot, processPath, containerHandle, ttyConsoleSocket, logfilePath string) *exec.Cmd {
runtimeArgs := []string{}
if runcRoot != "" {
runtimeArgs = append(runtimeArgs, "--root", runcRoot)
}
runtimeArgs = append(runtimeArgs,
"--debug", "--log", logfilePath, "--log-format", "json",
runMode,
"--detach",
"--pid-file", filepath.Join(processPath, "pidfile"),
)
runtimeArgs = append(runtimeArgs, runmodeArgs(runMode, processPath)...)
runtimeArgs = append(runtimeArgs, ttyArgs(runMode, ttyConsoleSocket)...)
runtimeArgs = append(runtimeArgs, containerHandle)
return exec.Command(runtimePath, runtimeArgs...)
}
func runmodeArgs(runMode, bundlePath string) []string {
if runMode == "run" {
return []string{"--no-new-keyring", "--bundle", bundlePath}
}
return []string{"-p", fmt.Sprintf("/proc/%d/fd/0", os.Getpid())}
}
func ttyArgs(runMode, ttyConsoleSocket string) []string {
args := []string{}
if ttyConsoleSocket == "" {
return args
}
if runMode == "exec" {
args = append(args, "--tty")
}
return append(args, "--console-socket", ttyConsoleSocket)
}