-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
driver: docs to set buildkitd network mode and add tests #2275
driver: docs to set buildkitd network mode and add tests #2275
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-flags
instead of introducing a new flag.