Skip to content

Commit e830e09

Browse files
authored
Fix S2I build with podman. (#1014)
Workaround a bug in podman: containers/podman#13770 Signed-off-by: Matej Vasek <[email protected]>
1 parent 867d4c2 commit e830e09

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

s2i/builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
6161
}
6262
defer client.Close()
6363

64+
if isPodman(ctx, client) {
65+
client = podmanDockerClient{client}
66+
}
67+
6468
// Build Config
6569
cfg := &api.Config{}
6670
cfg.Quiet = !b.verbose

s2i/docker_client_wrapper.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package s2i
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"strings"
8+
9+
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/client"
11+
)
12+
13+
// Wrapper to workaround https://github.com/containers/podman/issues/13770
14+
type podmanDockerClient struct {
15+
client.CommonAPIClient
16+
}
17+
18+
func (p podmanDockerClient) ContainerCommit(ctx context.Context, nameOrID string, opts types.ContainerCommitOptions) (types.IDResponse, error) {
19+
if len(opts.Config.Cmd) > 0 {
20+
bs, err := json.Marshal(opts.Config.Cmd)
21+
if err != nil {
22+
return types.IDResponse{}, err
23+
}
24+
opts.Changes = append(opts.Changes, "CMD "+string(bs))
25+
}
26+
27+
if len(opts.Config.Entrypoint) > 0 {
28+
bs, err := json.Marshal(opts.Config.Entrypoint)
29+
if err != nil {
30+
return types.IDResponse{}, err
31+
}
32+
opts.Changes = append(opts.Changes, "ENTRYPOINT "+string(bs))
33+
}
34+
35+
if opts.Config.User != "" {
36+
opts.Changes = append(opts.Changes, "USER "+opts.Config.User)
37+
}
38+
39+
for _, e := range opts.Config.Env {
40+
parts := strings.SplitN(e, "=", 2)
41+
opts.Changes = append(opts.Changes, fmt.Sprintf("ENV %s=%q", parts[0], parts[1]))
42+
}
43+
44+
for k, v := range opts.Config.Labels {
45+
opts.Changes = append(opts.Changes, fmt.Sprintf("LABEL %q=%q", k, v))
46+
}
47+
48+
return p.CommonAPIClient.ContainerCommit(ctx, nameOrID, opts)
49+
}
50+
51+
func isPodman(ctx context.Context, cli client.CommonAPIClient) bool {
52+
v, err := cli.ServerVersion(ctx)
53+
if err != nil {
54+
return false
55+
}
56+
for _, comp := range v.Components {
57+
if comp.Name == "Podman Engine" {
58+
return true
59+
}
60+
}
61+
return false
62+
}

0 commit comments

Comments
 (0)