Skip to content

Commit 3428b6b

Browse files
authored
Merge pull request moby#3482 from crazy-max/integration-dockerd-mirror
integration: set mirrors and entitlements with dockerd worker
2 parents 234dfca + 489c823 commit 3428b6b

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

.github/workflows/dockerd.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ jobs:
6161
if: steps.build.outputs.result == 'true'
6262
run: |
6363
if [ -L "/tmp/moby/binary-daemon/dockerd" ]; then
64-
mv -f $(readlink /tmp/moby/binary-daemon/dockerd) /tmp/moby/binary-daemon/dockerd
64+
mv -f $(readlink /tmp/moby/binary-daemon/dockerd) /tmp/moby/dockerd
6565
fi
6666
-
6767
name: Download
6868
if: steps.build.outputs.result != 'true'
6969
run: |
70-
mkdir -p /tmp/moby/binary-daemon
71-
cd /tmp/moby/binary-daemon
70+
mkdir -p /tmp/moby
71+
cd /tmp/moby
7272
wget -qO- "https://download.docker.com/linux/static/stable/x86_64/docker-${{ env.DOCKER_VERSION }}.tgz" | tar xvz --strip 1
7373
-
7474
name: Upload dockerd
7575
uses: actions/upload-artifact@v3
7676
with:
7777
name: dockerd
78-
path: /tmp/moby/binary-daemon/dockerd
78+
path: /tmp/moby/dockerd
7979
if-no-files-found: error
8080

8181
test:

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)