Skip to content

imagebuildah: avoid empty layer in single-layer build path#6699

Open
jlebon wants to merge 1 commit intocontainers:mainfrom
jlebon:pr/empty-final-layer
Open

imagebuildah: avoid empty layer in single-layer build path#6699
jlebon wants to merge 1 commit intocontainers:mainfrom
jlebon:pr/empty-final-layer

Conversation

@jlebon
Copy link
Contributor

@jlebon jlebon commented Feb 27, 2026

In the single-layer build path (i.e. with --layers=false), the final commit always created a layer even when only metadata instructions were executed after FROM.

Fix this by tracking if any instruction actually created data so we can avoid creating a layer in that case.

Noticed this when looking at images passed through chunkah, where one can specify the number of layers N to output; the resulting image would have a total of N+1 layers because it's often the case that you want to add metadata after the FROM oci-archive:....

Assisted-by: Claude Opus 4.6

/kind bug

Stop creating an empty layer when using `--layers=false` and adding metadata only (e.g. `LABEL`).

In the single-layer build path (i.e. with `--layers=false`), the final
commit always created a layer even when only metadata instructions were
executed after `FROM`.

Fix this by tracking if any instruction actually created data so we can
avoid creating a layer in that case.

Noticed this when looking at images passed through chunkah, where one
can specify the number of layers N to output; the resulting image would
have a total of N+1 layers because it's often the case that you want to
add metadata after the `FROM oci-archive:...`.

Signed-off-by: Jonathan Lebon <jonathan@jlebon.com>
Assisted-by: Claude Opus 4.6
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 27, 2026
@packit-as-a-service
Copy link

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

Copy link
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

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

I vaguely recall OpenShift having a build test that checked how many layers a test build added to its output image compared to the base image; it's why we added the stepRequiresLayer() helper function and started using it where we do in multi-layer builds. I don't think that it was a Layers==false (imageOptimizationPolicy==SkipLayers) case, though, so it's probably not going to be tripped up by this change.
Anyway, LGTM. Thanks!

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants