-
Notifications
You must be signed in to change notification settings - Fork 609
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
Add --pull option to build command #3074
Conversation
348bfb7
to
0613eac
Compare
Does buildkit output to stderr? Integration tests were failing with |
cmd/nerdctl/builder_build_test.go
Outdated
func TestBuildWithPull(t *testing.T) { | ||
testutil.RequiresBuild(t) | ||
|
||
oldImage := "ubuntu:18.04" |
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.
Any reason to use this very old version of Ubuntu?
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.
Just for testing purposes. The idea is to pull an old version of ubuntu, tag it as latest, and see if --pull=false
uses local image while --pull=true
uses the remote image (latest vesion).
As we aren't actually running this built image, this doesn't pose any security risk should any vulnerabilities be found.
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 just use the mirror registry, with updating the tag with another image before checking --pull behaviror?
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.
Makes sense, I switched to using much slimmer images as well so this test will now run a little bit faster
4d44b73
to
e3e33bb
Compare
Last force-push revamped the integration test, so it should work properly. IMO it's a little bit ugly, since we're using |
c5f5be4
to
98de079
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.
See comments
cmd/nerdctl/builder_build.go
Outdated
@@ -51,6 +51,7 @@ If Dockerfile is not present and -f is not specified, it will look for Container | |||
buildCommand.Flags().StringP("output", "o", "", "Output destination (format: type=local,dest=path)") | |||
buildCommand.Flags().String("progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output") | |||
buildCommand.Flags().String("provenance", "", "Shorthand for \"--attest=type=provenance\"") | |||
buildCommand.Flags().String("pull", "", "On true, always attempt to pull latest image version from remote. Default uses buildkit's default.") |
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 make it a bool flag and just check if it's set when parsing?
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.
Is this possible? From my understanding, the bool flag can only be true or false, and if none are provided then it will just set a default value.
Once parsed from a string, though, I can store it into a *bool instead of a string.
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.
Have you tried Changed
? https://pkg.go.dev/github.com/spf13/pflag#FlagSet.Changed
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 is perfect, thanks. Just pushed a new set of changes.
cmd/nerdctl/builder_build_test.go
Outdated
func TestBuildWithPull(t *testing.T) { | ||
testutil.RequiresBuild(t) | ||
|
||
oldImage := "ubuntu:18.04" |
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 just use the mirror registry, with updating the tag with another image before checking --pull behaviror?
pkg/api/types/builder_types.go
Outdated
// Pull determines if we should attempt to pull the latest image from remote. | ||
// "true" will pull from remote while "false" will always use locally cached image | ||
Pull string |
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 just make it *bool if we only take true/false/default ?
4741cec
to
5744262
Compare
Had to move the test to |
cmd/nerdctl/builder_build.go
Outdated
@@ -51,6 +51,7 @@ If Dockerfile is not present and -f is not specified, it will look for Container | |||
buildCommand.Flags().StringP("output", "o", "", "Output destination (format: type=local,dest=path)") | |||
buildCommand.Flags().String("progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output") | |||
buildCommand.Flags().String("provenance", "", "Shorthand for \"--attest=type=provenance\"") | |||
buildCommand.Flags().Bool("pull", true, "On true, always attempt to pull latest image version from remote. Default uses buildkit's default.") |
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.
Default value should be false.
name string | ||
pull bool | ||
}{ | ||
{ |
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 you add a test case for the default behaviour? (i.e. not specifying --pull)
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.
Done
5744262
to
819f183
Compare
Signed-off-by: David Son <[email protected]>
819f183
to
b63f4d6
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
Fixes #3073
docker build
initially had a--pull
command that forced remote image lookup when building an image. This has been changed when docker switched to buildkit to be default behavior, with an option to not check for updates if the image is already cached.Forcing
nerdctl build
to use local images may be desirable for a few edge cases, so I've implemented a solution via a--pull
flag innerdctl build
that can be set tofalse
to enable this behavior, andtrue
to always pull from remote. Without it, it will use the buildkit default.There's a caveat here, which is that buildkit must be set up to use the same namespace as the locally cached image, which the user must set up in their buildkit config file.
Tested in a similar workflow as the integration test:
FROM ubuntu:latest
ubuntu:18.04
) into your buildkit namespace (default should bebuildkit
)nerdctl build --pull false .
nerdctl build --pull true .