Skip to content

build: commit an empty layer instead of a layer with nothing in it#6873

Open
nalind wants to merge 2 commits into
podman-container-tools:mainfrom
nalind:suppress-empty-layer-diffs
Open

build: commit an empty layer instead of a layer with nothing in it#6873
nalind wants to merge 2 commits into
podman-container-tools:mainfrom
nalind:suppress-empty-layer-diffs

Conversation

@nalind

@nalind nalind commented May 26, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

When buildah building an image in single-layer mode, if the generated diff has nothing in it, omit the blob and set the EmptyLayer field in the final history entry, which would otherwise correspond to it.

How to verify it

New integration test!

Which issue(s) this PR fixes:

Fixes #6860

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Images built by `buildah build` without `--layers=true` will no longer add an empty layer to the output image if there were no changes to the working container's root filesystem during the build.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 26, 2026
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

1 similar comment
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

nalind added 2 commits May 27, 2026 10:42
Add a flag to CommitOptions which will drop the layer blob for the
working container's layer, and mark it as an empty layer in the history,
if the generated diff is just a block of zero bytes.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
When `buildah build`ing an image in single-layer mode, if the generated
diff has nothing in it, omit the blob and set the EmptyLayer field in
the final history entry, which would otherwise correspond to it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
@nalind nalind force-pushed the suppress-empty-layer-diffs branch from 2cd9c85 to a23b7ba Compare May 27, 2026 14:42
@TomSweeneyRedHat

Copy link
Copy Markdown
Contributor

LGTM

Comment thread image.go
// don't bother, because it's highly unlikely), suppress it.
if i.emptyLayerIfEmptyDiff && layerID == i.layerID {
switch size {
case 0, 512, 1024, 2048:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this numbers mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are multiples of the record size used by tar(5) - an archive with no entries in it still includes the end-of-archive marker, which is usually 1024 bytes, i.e., two records full of zero bytes. The rest of the possible lengths are just guesses, which should be harmless since still we only discard layers of that length if the diff is all zero bytes.

Comment thread tests/bud.bats
Comment on lines +942 to +945
# sha512sum([0]{})
assert lastdiffid != sha512:cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
# sha512sum([1024]{})
assert lastdiffid != sha512:8efb4f73c5655351c444eb109230c556d39e2c7624e9c11abc9e3fb4b9b9254218cc5085b454a9698d085cfa92198491f07a723be4574adc70617b73eb0b6461

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Should we use some flag or config to force buildah to use sha512?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently don't have a flag to do that. This is an attempt at predicting the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RootFS.layers entry added for operations that do not impact the filesystem

3 participants