-
Notifications
You must be signed in to change notification settings - Fork 814
build: add support for --inherit-labels
#6103
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
Conversation
/packit retest-failed |
Account Honny1 has no write access nor is author of PR! |
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 think this needs to include broader tests, as there are cases I'm not sure are being handled here.
define/build.go
Outdated
@@ -236,6 +236,9 @@ type BuildOptions struct { | |||
// ID mapping options to use if we're setting up our own user namespace | |||
// when handling RUN instructions. | |||
IDMappingOptions *IDMappingOptions | |||
// InheritLabels allows users to specify if they want | |||
// to inheritlabels from base image or not. |
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.
// to inheritlabels from base image or not. | |
// to inherit labels from base image or not. |
docs/buildah-build.1.md
Outdated
@@ -497,6 +497,10 @@ Path to an alternative .containerignore (.dockerignore) file. | |||
Write the built image's ID to the file. When `--platform` is specified more | |||
than once, attempting to use this option will trigger an error. | |||
|
|||
**--inherit-labels** *bool-value* | |||
|
|||
Allows users to specify if they want to inherit labels from base image or not. (Default is `true`). |
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.
"Allows users" is kind of implied here, in the man page. Describe what the tool will do when the flag is specified.
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.
Perhaps
Inherit the labels from the base image (default true).
I'm assuming the default is true; I haven't read the rest.
# and `hello=world` which we just added using cli flag | ||
want_output='map["hello":"world" "io.buildah.version":"'$buildah_version'"]' | ||
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' exp | ||
expect_output "$want_output" |
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 needs to test builds with multiple layers (--layers=true
) and ensure that the build cache doesn't use images that have been built with one value for this setting when the build is running with a different value, since the resulting configurations would differ.
It should probably also check running a multi-stage build where an earlier stage that's used as the base of a later stage sets a label, as I suspect that might not behave as expected in this iteration.
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.
It would also be good to add a test just using --inherit-labels" to ensure the default works and doesn't get change in the future. I'm also a bit on the OCD side, I'd also like a
--inherit-labels=true` test, but not completely necessary.
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 added tests to work with --layers
pkg/cli/common.go
Outdated
@@ -230,6 +231,7 @@ func GetBudFlags(flags *BudResults) pflag.FlagSet { | |||
fs.StringVar(&flags.CertDir, "cert-dir", "", "use certificates at the specified path to access the registry") | |||
fs.BoolVar(&flags.Compress, "compress", false, "this is a legacy option, which has no effect on the image") | |||
fs.BoolVar(&flags.CompatVolumes, "compat-volumes", false, "preserve the contents of VOLUMEs during RUN instructions") | |||
fs.BoolVar(&flags.InheritLabels, "inherit-labels", true, "inherit labels from base image") |
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.
fs.BoolVar(&flags.InheritLabels, "inherit-labels", true, "inherit labels from base image") | |
fs.BoolVar(&flags.InheritLabels, "inherit-labels", true, "inherit the labels from the base image") |
/packit retest-failed |
b10e993
to
2df09fd
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.
Tests should also check running a multi-stage build where an earlier stage that's used as the base of a later stage sets a label, as I suspect that might not behave as expected in this iteration, depending on what the expected behavior is, which is unclear.
define/build.go
Outdated
@@ -236,6 +236,9 @@ type BuildOptions struct { | |||
// ID mapping options to use if we're setting up our own user namespace | |||
// when handling RUN instructions. | |||
IDMappingOptions *IDMappingOptions | |||
// InheritLabels allows users to specify if they want |
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.
Same comment as for the man page: we're at the API level here, so just describe what the library will be doing differently based on this field, perhaps something like "InheritLabels controls whether or not built images will retain the labels which were set in their base images".
# Now build same file with --inherit-labels=true and verify if using the cache | ||
run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=true -t exp -f $BUDFILES/base-with-labels/Containerfile.layer | ||
# Should contain `Using cache` at all since | ||
expect_output --substring " Using 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.
How many times is "Using cache" expected to be printed? Would it be simpler to compare the IDs of the final images?
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 also added a check below to verify image id.
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 should also be checked for multi-stage builds, since for those we generally leave the final image for a stage around for use in caching.
97fe66a
to
e812133
Compare
With this current patch it if |
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.
With this current patch it if
--inherit-labels=false
is set it does not inherit label intotarget
stage from base stages. I think that aligns with the docs that no labels are inherited at all from base image. I added a test to verify that. WDYT ?
You could ask in the issue that prompted this PR, and given how #5762 describes handling of ARGs, which don't even get recorded in images, I'm not sure if I know what the correct behavior should be for labels when the base image for a stage is part of the same build. Either way, the detail should be mentioned in the docs.
# Now build same file with --inherit-labels=true and verify if using the cache | ||
run_buildah build $WITH_POLICY_JSON --layers --inherit-labels=true -t exp -f $BUDFILES/base-with-labels/Containerfile.layer | ||
# Should contain `Using cache` at all since | ||
expect_output --substring " Using 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.
This should also be checked for multi-stage builds, since for those we generally leave the final image for a stage around for use in caching.
1477512
to
04b2894
Compare
I updated the doc to reflect both |
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.
Mostly nits, but I'd like one more test added, and there's an always-true assertion in there by mistake.
@@ -2670,6 +2670,69 @@ _EOF | |||
expect_output "$want_output" | |||
} | |||
|
|||
@test "bud and test inherit-labels" { |
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.
Missing calls to _prefetch
in here.
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.
tests/bud/base-with-labels/Containerfile.multi-stage
uses "alpine" as its base.
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 added _prefetch alpine
too.
04b2894
to
e9b339f
Compare
Allows users to specify if they want to inherit labels from base image or not. Signed-off-by: flouthoc <[email protected]>
e9b339f
to
a235033
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.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: flouthoc, nalind The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Did we ever have a conversation on why not just do --cap-drop=all has precedence. |
@rhatdan I think you mean |
/lgtm |
Allows users to specify if they want to inherit labels from base image or not.
Closes: #6098
What type of PR is this?
What this PR does / why we need it:
How to verify it
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?