driver: docs to set buildkitd network mode and add tests#2275
driver: docs to set buildkitd network mode and add tests#2275tonistiigi merged 3 commits intodocker:masterfrom
Conversation
b273d8d to
655e137
Compare
tests/build.go
Outdated
| cases := []struct { | ||
| name string | ||
| args []string | ||
| }{ | ||
| { | ||
| name: "bridge", | ||
| // TODO: use stable buildkit image when v0.13.0 released | ||
| args: []string{"--driver", "docker-container", "--buildkitd-flags=--oci-worker-net=bridge", "--driver-opt", "image=moby/buildkit:master"}, | ||
| }, | ||
| { | ||
| name: "host", | ||
| args: []string{"--driver", "docker-container", "--buildkitd-flags=--oci-worker-net=host"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range cases { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| out, err := createCmd(sb, withArgs(tt.args...)) | ||
| require.NoError(t, err, out) | ||
| builderName := strings.TrimSpace(out) | ||
| builders = append(builders, builderName) | ||
|
|
||
| cmd := buildxCmd(sb, withArgs("build", fmt.Sprintf("--output=type=local,dest=%s", dir), dir)) | ||
| cmd.Env = append(cmd.Env, "BUILDX_BUILDER="+builderName) | ||
| outb, err := cmd.CombinedOutput() | ||
| require.NoError(t, err, string(outb)) | ||
|
|
||
| dt, err := os.ReadFile(filepath.Join(dir, "ip.txt")) | ||
| require.NoError(t, err) | ||
|
|
||
| ip := net.ParseIP(strings.TrimSpace(string(dt))) | ||
| require.NotNil(t, ip) | ||
|
|
||
| if tt.name == "bridge" { | ||
| _, subnet, err := net.ParseCIDR("10.10.0.0/16") // default subnet for bridge network in buildkit: https://github.com/moby/buildkit/blob/489f5fc6a331530daa8a31fb6ed7ba223df8ecb9/cmd/buildkitd/main.go#L474 | ||
| require.NoError(t, err) | ||
| require.True(t, subnet.Contains(ip)) | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
@tonistiigi I use this kind of test cases to check the behavior to avoid this issue encountered in #2270 (comment)
There was a problem hiding this comment.
I guess this should be fine but the case I thought is to compare the values of host and bridge, to make sure bridge was applied and we don't get the default host even when the request did not set --network.
So instead of two buildkitd's with different network config, only one buildkitd with bridge mode and then test that in this buildkitd with --network host and without it provides a different ip/interfaces.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Updated test and vendored buildkit as well to grab moby/buildkit#4676
9364a74 to
6733f35
Compare
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
full diff: moby/buildkit@8e3fe35...d6e1426 Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
6733f35 to
aa518f9
Compare
fixes #2256
follow-up #2270 (comment) and closes #2270
needs #2268
This is an alternative to #2270 to document how to set BuildKit daemon network mode using
--buildkitd-flagsinstead of introducing a new flag.