-
Notifications
You must be signed in to change notification settings - Fork 877
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
Open
ezopezo
wants to merge
1
commit into
containers:main
Choose a base branch
from
ezopezo:emravec/preserve-intermediate-images
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,13 @@ The value of `[name]` is matched with the following priority order: | |
| * Stage defined with AS [name] inside Containerfile | ||
| * Image [name], either local or in a remote registry | ||
|
|
||
| **--build-id-file** *BuildIDfile* | ||
|
|
||
| Write a unique build ID (UUID) to the file. This build ID is generated once per | ||
| build and is added to intermediate stage images as a label (`io.buildah.build.id`) | ||
| when `--stage-labels` is enabled. This allows grouping all intermediate images | ||
| from a single build together. This option requires `--stage-labels` to be enabled. | ||
|
|
||
| **--cache-from** | ||
|
|
||
| Repository to utilize as a potential list of cache sources. When specified, Buildah will try to look for | ||
|
|
@@ -136,6 +143,21 @@ the intermediate image is stored in the image itself. Buildah's approach is simi | |
| does not inflate the size of the original image with intermediate images. Also, intermediate images can truly be | ||
| kept distributed across one or more remote registries using Buildah's caching mechanism. | ||
|
|
||
| **--cache-stages** *bool-value* | ||
|
|
||
| Preserve intermediate stage images instead of removing them after the build completes | ||
| (Default is `false`). By default, Buildah removes intermediate stage images to save space. | ||
| This option keeps those images, which can be useful for debugging multi-stage builds or | ||
| for reusing intermediate stages in subsequent builds. | ||
|
|
||
| When `--cache-stages` is used, cache lookup is disabled to ensure a fresh build every time. | ||
| This means the build will not reuse cached intermediate images from previous builds. On the | ||
| other hand when `--cache-stages` is used with `--layers` in a first build, subsequent builds without | ||
| `--cache-stages` but with `--layers` can still use the preserved intermediate layers as cache. | ||
|
|
||
| When combined with `--stage-labels`, intermediate images will include metadata labels | ||
| for easier identification and management. | ||
|
|
||
| **--cache-to** | ||
|
|
||
| Set this flag to specify list of remote repositories that will be used to store cache images. Buildah will attempt to | ||
|
|
@@ -1136,6 +1158,21 @@ To later use the ssh agent, use the --mount flag in a `RUN` instruction within a | |
|
|
||
| `RUN --mount=type=secret,id=id mycmd` | ||
|
|
||
|
|
||
| **--stage-labels** *bool-value* | ||
|
|
||
| Add metadata labels to intermediate stage images (Default is `false`). This option | ||
| requires `--cache-stages` to be enabled. | ||
|
|
||
| When enabled, intermediate stage images will be labeled with: | ||
| - `io.buildah.stage.name`: The stage name (from `FROM ... AS name`) | ||
| - `io.buildah.stage.base`: The base image used by this stage | ||
| - `io.buildah.stage.parent_name`: The parent stage name (if this stage uses another stage as base) | ||
| - `io.buildah.build.id`: A unique build ID shared across all stages in a single build | ||
|
|
||
| These labels make it easier to identify, query, and manage intermediate images from | ||
| multi-stage builds. | ||
|
|
||
| **--stdin** | ||
|
|
||
| Pass stdin into the RUN containers. Sometimes commands being RUN within a Containerfile | ||
|
|
@@ -1468,6 +1505,10 @@ buildah build -v /var/lib/dnf:/var/lib/dnf:O -t imageName . | |
|
|
||
| buildah build --layers -t imageName . | ||
|
|
||
| buildah build --cache-stages --stage-labels -t imageName . | ||
|
|
||
| buildah build --cache-stages --stage-labels --build-id-file /tmp/build-id.txt -t imageName . | ||
|
|
||
| buildah build --no-cache -t imageName . | ||
|
|
||
| buildah build -f Containerfile --layers --force-rm -t imageName . | ||
|
|
@@ -1530,6 +1571,21 @@ buildah build --output type=tar,dest=out.tar . | |
|
|
||
| buildah build -o - . > out.tar | ||
|
|
||
| ### Preserving and querying intermediate stage images | ||
|
|
||
| Build a multi-stage image while preserving intermediate stages with metadata labels: | ||
|
|
||
| buildah build --cache-stages --stage-labels --build-id-file /tmp/build-id.txt -t myapp . | ||
|
|
||
| Query intermediate images from a specific build using the build ID: | ||
|
|
||
| BUILD_ID=$(cat /tmp/build-id.txt) | ||
| buildah images --filter "label=io.buildah.build.id=${BUILD_ID}" | ||
|
|
||
| Find an intermediate image for a specific stage name: | ||
|
|
||
| buildah images --filter "label=io.buildah.stage.name=builder" | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! TY! |
||
| ### Building an image using a URL | ||
|
|
||
| This will clone the specified GitHub repository from the URL and use it as context. The Containerfile or Dockerfile at the root of the repository is used as the context of the build. This only works if the GitHub repository is a dedicated repository. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 to show the bool values in play, perhaps
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 skipped that since this is a relatively uncommon use case for boolean flags, because the false behavior is implicit whenever the flag is absent. Other flags such as
--no-cacheor--layersfollow the same pattern (present when true, absent when not, without presence of the--layers false) so I wanted to stay consistent with your docs. If you feel strongly about it, I certainly can add the examples :)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.
There's a long-standing bit of confusion in the man pages where, even though the boolean argument values are optional, we don't suggest that they always have to be supplied in the --flag=value form, with an equal sign, to prevent them from being treated as unrelated arguments.
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.
@nalind Does it make a sense to you to add args with equal sign and boolean or leave it as it is? What do you think?
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.
If we want an example where the flag is set to
false, the equal sign is going to be necessary.