forked from LINBIT/containerapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodman.go
41 lines (33 loc) · 826 Bytes
/
podman.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
package containerapi
import (
"context"
"fmt"
"os"
"github.com/docker/docker/client"
)
type PodmanProvider struct {
DockerProvider
}
func (p PodmanProvider) Command() string {
return "podman"
}
func NewPodmanProvider(ctx context.Context) (ContainerProvider, error) {
socketDir, ok := os.LookupEnv("XDG_RUNTIME_DIR")
if !ok {
socketDir = "/run"
}
socket := socketDir + "/podman/podman.sock"
apiclient, err := client.NewClientWithOpts(client.WithHost("unix://"+socket), client.WithAPIVersionNegotiation())
if err != nil {
return nil, fmt.Errorf("could not connect to Podman: %w", err)
}
_, err = apiclient.ServerVersion(ctx)
if err != nil {
return nil, fmt.Errorf("connection check failed: %w", err)
}
return &PodmanProvider{
DockerProvider: DockerProvider{
client: apiclient,
},
}, nil
}