-
Notifications
You must be signed in to change notification settings - Fork 639
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
feat: add network flag to nerdctl build #2383
Conversation
cmd/nerdctl/builder_build_test.go
Outdated
@@ -449,3 +449,38 @@ CMD ["cat", "/source-date-epoch"] | |||
base.Cmd("build", "-t", imageName, "--build-arg", "SOURCE_DATE_EPOCH="+sourceDateEpochArgStr, buildCtx).AssertOK() | |||
base.Cmd("run", "--rm", imageName).AssertOutExactly(sourceDateEpochArgStr + "\n") | |||
} | |||
|
|||
func TestBuildNetworkFlat(t *testing.T) { |
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.
What is "flat" ?
cmd/nerdctl/builder_build.go
Outdated
@@ -56,6 +56,7 @@ If Dockerfile is not present and -f is not specified, it will look for Container | |||
buildCommand.Flags().StringArray("cache-from", nil, "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)") | |||
buildCommand.Flags().StringArray("cache-to", nil, "Cache export destinations (eg. user/app:cache, type=local,dest=path/to/dir)") | |||
buildCommand.Flags().Bool("rm", true, "Remove intermediate containers after a successful build") | |||
buildCommand.Flags().String("network", "default", "Set type of network for build (default, none, host)") |
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.
Can we have shell completion too?
ee4db5e
to
3d61a92
Compare
@AkihiroSuda Thanks for the review. I addressed all the comments. |
cmd/nerdctl/completion.go
Outdated
@@ -160,3 +160,12 @@ func shellCompletePlatforms(cmd *cobra.Command, args []string, toComplete string | |||
} | |||
return candidates, cobra.ShellCompDirectiveNoFileComp | |||
} | |||
|
|||
func shellCompleteBuildNetworks(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
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.
This can be just in builder_build.go
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.
Thanks, I made the suggested change and added a test.
cmd/nerdctl/builder_build_test.go
Outdated
@@ -449,3 +449,38 @@ CMD ["cat", "/source-date-epoch"] | |||
base.Cmd("build", "-t", imageName, "--build-arg", "SOURCE_DATE_EPOCH="+sourceDateEpochArgStr, buildCtx).AssertOK() | |||
base.Cmd("run", "--rm", imageName).AssertOutExactly(sourceDateEpochArgStr + "\n") | |||
} | |||
|
|||
func TestBuildNetworkFlag(t *testing.T) { |
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.
func TestBuildNetworkFlag(t *testing.T) { | |
func TestBuildNetwork(t *testing.T) { |
3d61a92
to
1a4ecc4
Compare
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.
Thanks
https://github.com/containerd/nerdctl/actions/runs/5613705111/job/15211524315?pr=2383 |
1a4ecc4
to
63cd139
Compare
This is a bit strange to what I observe when I test locally.
Also tested this test on
|
cmd/nerdctl/builder_build_test.go
Outdated
for _, tc := range validCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
base.Cmd("build", buildCtx, "--network", tc.network).AssertExitCode(tc.exitCode) |
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.
Please try adding --no-cache
to fix the CI failure with docker
.
Or, test --network=none
before running other tests
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.
And it is weird that the test is passing for nerdctl
without --no-cache
. 🤔
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.
Please try adding --no-cache to fix the CI failure with docker.
Or, test --network=none before running other tests
This did the trick although not sure why it works with nerdctl
without this option. Also works with docker on lima instance on my local. I'll add a comment about it.
2d79c7d
to
0d2413f
Compare
https://github.com/containerd/nerdctl/actions/runs/5618569480/job/15225123013?pr=2383 |
a30e72a
to
4206529
Compare
9ca560f
to
946036e
Compare
I could not find the race root cause for this. However a workaround could be container prune in container_list test. It should have no impact to the functionality being tested in those tests or to the build network test. PTAL. |
This may help you |
Not a race. |
Thanks for the insight. I will rebase off of main once this PR is merged rather than using Update: After the rebase with main the tests run fine. |
d461fcb
to
ca4d601
Compare
Signed-off-by: Vishwas Siravara <[email protected]>
ca4d601
to
ccce195
Compare
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.
Thanks
What does this PR do?
Add's support for
--network
flag tonerdctl build
. Fixes: #2233Details
host|none|default
. Compatible withbuildctl build
--network=host
. Additionally pass--allow=network.host
and--allow=security.insecure
to buildctlArgsTesting
builder_build_test.go
for--network=default|""|none
. Tested--network=host
manually since it requires modifyingbuildkitd.toml
file.