Skip to content

Commit afe8d89

Browse files
[wanda] add podman backend
adds podman backend via podman_cmd. Requires having podman already installed + available via PATH I still need to battletest this, but this is the general shape! Topic: add-podman-backend Relative: refactor-for-podman Signed-off-by: andrew <andrew@anyscale.com>
1 parent cbee168 commit afe8d89

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

wanda/container_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ func (c *baseContainerCmd) inspectImage(tag string) (*imageInfo, error) {
8282
cmd.Stdout = buf
8383
if err := cmd.Run(); err != nil {
8484
if exitErr, ok := err.(*exec.ExitError); ok {
85-
// Docker returns 1
85+
// Docker returns 1, podman returns 125 for "image not found".
8686
code := exitErr.ExitCode()
87-
if code == 1 {
87+
if code == 1 || code == 125 {
8888
return nil, nil
8989
}
9090
}

wanda/container_cmd_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func dockerAvailable() bool {
3333
}
3434

3535
func podmanAvailable() bool {
36-
return false
36+
_, err := exec.LookPath("podman")
37+
return err == nil
3738
}
3839

3940
var containerRuntimes = []containerRuntimeTest{

wanda/forge_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ type ForgeConfig struct {
4040

4141
// newContainerCmd creates a ContainerCmd based on the config settings.
4242
func (c *ForgeConfig) newContainerCmd() ContainerCmd {
43+
if c.ContainerRuntime == RuntimePodman {
44+
return NewPodmanCmd(&PodmanCmdConfig{
45+
Bin: c.ContainerBin,
46+
})
47+
}
4348
return NewDockerCmd(&DockerCmdConfig{
4449
Bin: c.ContainerBin,
4550
UseLegacyEngine: runtime.GOOS == "windows",

wanda/podman_cmd.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package wanda
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func podmanCmdEnvs() []string {
9+
var envs []string
10+
for _, k := range []string{
11+
"HOME",
12+
"USER",
13+
"PATH",
14+
"XDG_RUNTIME_DIR",
15+
"CONTAINERS_CONF",
16+
"REGISTRY_AUTH_FILE",
17+
} {
18+
if v, ok := os.LookupEnv(k); ok {
19+
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
20+
}
21+
}
22+
return envs
23+
}
24+
25+
// podmanCmd wraps the podman CLI for building container images.
26+
type podmanCmd struct {
27+
baseContainerCmd
28+
}
29+
30+
// PodmanCmdConfig configures the podman command.
31+
type PodmanCmdConfig struct {
32+
Bin string
33+
}
34+
35+
// NewPodmanCmd creates a new podman container command.
36+
func NewPodmanCmd(config *PodmanCmdConfig) ContainerCmd {
37+
bin := config.Bin
38+
if bin == "" {
39+
bin = "podman"
40+
}
41+
envs := podmanCmdEnvs()
42+
43+
return &podmanCmd{
44+
baseContainerCmd: baseContainerCmd{
45+
bin: bin,
46+
envs: envs,
47+
},
48+
}
49+
}

wanda/podman_cmd_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package wanda
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestNewPodmanCmd(t *testing.T) {
8+
c := NewPodmanCmd(&PodmanCmdConfig{})
9+
cmd := c.(*podmanCmd)
10+
11+
if cmd.bin != "podman" {
12+
t.Errorf("bin: got %q, want %q", cmd.bin, "podman")
13+
}
14+
}
15+
16+
func TestNewPodmanCmd_customBin(t *testing.T) {
17+
c := NewPodmanCmd(&PodmanCmdConfig{Bin: "/usr/local/bin/podman"})
18+
cmd := c.(*podmanCmd)
19+
20+
if cmd.bin != "/usr/local/bin/podman" {
21+
t.Errorf("bin: got %q, want %q", cmd.bin, "/usr/local/bin/podman")
22+
}
23+
}

wanda/wanda/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Flags:
2727
func main() {
2828
workDir := flag.String("work_dir", ".", "root directory for the build")
2929
dockerBin := flag.String("docker", "", "path to the docker/podman binary")
30+
podman := flag.Bool("podman", false, "use podman instead of docker")
3031
rayCI := flag.Bool(
3132
"rayci", false,
3233
"takes RAYCI_ env vars for input and run in remote mode",
@@ -73,6 +74,9 @@ func main() {
7374

7475
// Determine the container runtime.
7576
runtime := wanda.RuntimeDocker
77+
if *podman {
78+
runtime = wanda.RuntimePodman
79+
}
7680

7781
config := &wanda.ForgeConfig{
7882
WorkDir: *workDir,

0 commit comments

Comments
 (0)