1
0

Add a flag to set the container runtime binary

This commit is contained in:
2023-04-07 18:57:18 +00:00
parent e35e030c54
commit 9e55ebd44e
3 changed files with 28 additions and 5 deletions

19
main.go
View File

@ -9,6 +9,7 @@ import (
"io"
"math/rand"
"os"
"os/exec"
"os/user"
"runtime/debug"
"strconv"
@ -44,6 +45,8 @@ type CLI struct {
Version VersionFlag `name:"version" help:"print version information and quit"`
LogLevel LogLevelFlag `enum:"trace,debug,info,warn,error" default:"info"`
ContainerRuntime string `enum:"podman,docker" default:"podman"`
}
type LogLevelFlag string
@ -153,6 +156,22 @@ func main() {
log.Debug().Msgf("%v", buildInfo.Settings)
}
_, err = exec.LookPath(cli.ContainerRuntime)
if err != nil {
if cli.ContainerRuntime == "podman" { // default value
log.Debug().Msgf("podman is not found in $PATH, " +
"fall back to docker")
cli.ContainerRuntime = "docker"
}
_, err = exec.LookPath(cli.ContainerRuntime)
if err != nil {
log.Fatal().Msgf("%v is not found in $PATH",
cli.ContainerRuntime)
}
}
containerRuntime = cli.ContainerRuntime
err = ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}