Skip to content
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

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Feb 22, 2024

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.

@crazy-max crazy-max force-pushed the buildkitd-flags-network-mode branch 2 times, most recently from b273d8d to 655e137 Compare February 22, 2024 09:33
tests/build.go Outdated
Comment on lines 458 to 498
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:/moby/buildkit/blob/489f5fc6a331530daa8a31fb6ed7ba223df8ecb9/cmd/buildkitd/main.go#L474
require.NoError(t, err)
require.True(t, subnet.Contains(ip))
}
})
}
Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member Author

@crazy-max crazy-max Feb 22, 2024

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

tests/build.go Outdated Show resolved Hide resolved
@crazy-max crazy-max force-pushed the buildkitd-flags-network-mode branch 5 times, most recently from 9364a74 to 6733f35 Compare February 22, 2024 20:51
@crazy-max crazy-max marked this pull request as ready for review February 22, 2024 22:08
@tonistiigi tonistiigi merged commit fd11d93 into docker:master Feb 23, 2024
65 checks passed
@crazy-max crazy-max deleted the buildkitd-flags-network-mode branch February 23, 2024 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v0.13] allow driver-opt to that sets bridge network as default
2 participants