Skip to content

Commit 11d7e76

Browse files
committed
integration: set mirrors and entitlements with dockerd worker
Signed-off-by: CrazyMax <[email protected]>
1 parent eb31c0c commit 11d7e76

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

util/testutil/dockerd/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dockerd
2+
3+
type Config struct {
4+
Features map[string]bool `json:"features,omitempty"`
5+
Mirrors []string `json:"registry-mirrors,omitempty"`
6+
Builder BuilderConfig `json:"builder,omitempty"`
7+
}
8+
9+
type BuilderEntitlements struct {
10+
NetworkHost bool `json:"network-host,omitempty"`
11+
SecurityInsecure bool `json:"security-insecure,omitempty"`
12+
}
13+
14+
type BuilderConfig struct {
15+
Entitlements BuilderEntitlements `json:",omitempty"`
16+
}

util/testutil/integration/dockerd.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package integration
33
import (
44
"bytes"
55
"context"
6-
"fmt"
6+
"encoding/json"
77
"io"
88
"net"
99
"os"
1010
"path/filepath"
1111
"time"
1212

1313
"github.com/docker/docker/client"
14+
"github.com/moby/buildkit/cmd/buildkitd/config"
1415
"github.com/moby/buildkit/util/testutil/dockerd"
1516
"github.com/pkg/errors"
1617
"golang.org/x/sync/errgroup"
@@ -63,6 +64,37 @@ func (c moby) New(ctx context.Context, cfg *BackendConfig) (b Backend, cl func()
6364
return nil, nil, err
6465
}
6566

67+
bkcfg, err := config.LoadFile(cfg.ConfigFile)
68+
if err != nil {
69+
return nil, nil, errors.Wrapf(err, "failed to load buildkit config file %s", cfg.ConfigFile)
70+
}
71+
72+
dcfg := dockerd.Config{
73+
Features: map[string]bool{
74+
"containerd-snapshotter": c.name == "dockerd-containerd",
75+
},
76+
}
77+
if reg, ok := bkcfg.Registries["docker.io"]; ok && len(reg.Mirrors) > 0 {
78+
for _, m := range reg.Mirrors {
79+
dcfg.Mirrors = append(dcfg.Mirrors, "http://"+m)
80+
}
81+
}
82+
if bkcfg.Entitlements != nil {
83+
for _, e := range bkcfg.Entitlements {
84+
switch e {
85+
case "network.host":
86+
dcfg.Builder.Entitlements.NetworkHost = true
87+
case "security.insecure":
88+
dcfg.Builder.Entitlements.SecurityInsecure = true
89+
}
90+
}
91+
}
92+
93+
dcfgdt, err := json.Marshal(dcfg)
94+
if err != nil {
95+
return nil, nil, errors.Wrapf(err, "failed to marshal dockerd config")
96+
}
97+
6698
deferF := &multiCloser{}
6799
cl = deferF.F()
68100

@@ -86,14 +118,8 @@ func (c moby) New(ctx context.Context, cfg *BackendConfig) (b Backend, cl func()
86118
return nil, nil, errors.Errorf("new daemon error: %q, %s", err, formatLogs(cfg.Logs))
87119
}
88120

89-
dockerdConfig := fmt.Sprintf(`{
90-
"features": {
91-
"containerd-snapshotter": %v
92-
}
93-
}`, c.name == "dockerd-containerd")
94-
95121
dockerdConfigFile := filepath.Join(workDir, "daemon.json")
96-
if err := os.WriteFile(dockerdConfigFile, []byte(dockerdConfig), 0644); err != nil {
122+
if err := os.WriteFile(dockerdConfigFile, dcfgdt, 0644); err != nil {
97123
return nil, nil, err
98124
}
99125

0 commit comments

Comments
 (0)