-
Notifications
You must be signed in to change notification settings - Fork 860
feat: add support for preserving and labeling intermediate stage images #6556
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
base: main
Are you sure you want to change the base?
feat: add support for preserving and labeling intermediate stage images #6556
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ezopezo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Ephemeral COPR build failed. @containers/packit-build please check. |
59cd9ae to
6bd3187
Compare
b7e81df to
3314051
Compare
|
/retest |
|
@ezopezo: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@nalind can you please take a look and put ok-to-test label? It seems to me that tests are failing most likely with some timeouts and thus I would like to try to re-run them (or please tell me what I just broke :) ). |
|
/ok-to-test |
|
/test |
|
@ezopezo: No presubmit jobs available for containers/buildah@main In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
This adds support for preserving and labeling intermediate stage images in multi-stage builds. In contrast to the --layers flag, --cache-stages preserves only the final image from each named stage (FROM ... AS name), not every instruction layer. This also keeps the final image's layer count unchanged compared to a regular build. New flags: - --cache-stages: preserve intermediate stage images instead of removing them - --stage-labels: add metadata labels to intermediate stage images (stage name, base image, build ID, parent stage name). Requires --cache-stages. - --build-id-file: write unique build ID (UUID) to file for easier identification and grouping of intermediate images from a single build. Requires --stage-labels. The implementation also includes: - Detection of transitive alias patterns (stage using another intermediate stage as base) - Validation that --stage-labels requires --cache-stages - Validation that --build-id-file requires --stage-labels - Test coverage (15 tests) and documentation updates This functionality is useful for debugging, exploring, and reusing intermediate stage images in multi-stage builds. Signed-off-by: Erik Mravec <[email protected]>
3314051 to
3955b20
Compare
|
@nalind @mtrmac @TomSweeneyRedHat can you please take a look on this? (or pick up some appropriate reviewers?) Thanks in advance! |
This adds support for preserving and labeling intermediate stage images in multi-stage builds. In contrast to the
--layersflag,--cache-stagespreserves only the final image from each named stage (FROM ... AS name), not every instruction layer. This also keeps the final image's layer count unchanged compared to a regular build.New flags:
--cache-stages: preserve intermediate stage images instead of removing them--stage-labels: add metadata labels to intermediate stage images (stage name, base image, build ID, parent stage name). Requires--cache-stages.--build-id-file: write unique build ID (UUID) to file for easier identification and grouping of intermediate images from a single build. Requires--stage-labels.The implementation also includes:
--stage-labelsrequires--cache-stages--build-id-filerequires--stage-labelsWhat type of PR is this?
/kind feature
What this PR does / why we need it:
General use: This functionality is useful for identification, debugging, and reusing intermediate stage images in multi-stage builds.
Specific need: Identifying the content copied from intermediate stages in multi-stage builds into the final image is a hard requirement for supporting Contextual SBOM - an SBOM that understands the origin of each component.
While intermediate images can be extracted using the
--layersoption, this approach has several issues for our use case:buildah images --all), which introduces unnecessary noise for our purposes.--layers), meaning:Related repositories:
konflux (uses mobster for SBOM generation),
mobster (implements contextual SBOM functionality requiring this change),
capo (wraps builder content identification functionality for mobster),
Contact person: emravec (RedHat) / @ezopezo (Github)
How to verify it
Run any multistage build with intermediate stage specified with implemented arguments. Resulting intermediate images should be correctly labeled. Example:
buildah build --cache-stages --stage-labels --build-id-file ./file.txt -t test:0.1 .Which issue(s) this PR fixes:
Fixes: #6257
Internal Jira: https://issues.redhat.com/browse/ISV-6122
Does this PR introduce a user-facing change?