Skip to content

Respect compression_format from containers.conf in push, build --cache-to, and commit#6757

Merged
TomSweeneyRedHat merged 5 commits into
containers:mainfrom
Honny1:teach-Zstd
May 20, 2026
Merged

Respect compression_format from containers.conf in push, build --cache-to, and commit#6757
TomSweeneyRedHat merged 5 commits into
containers:mainfrom
Honny1:teach-Zstd

Conversation

@Honny1
Copy link
Copy Markdown
Member

@Honny1 Honny1 commented Apr 1, 2026

  • buildah push now falls back to compression_format and compression_level from containers.conf when --compression-format is not set
  • buildah build --cache-to passes CompressionFormat/ForceCompressionFormat to cache push, so cached layers use the configured compression instead of defaulting to gzip
  • buildah build gains --cache-compression-format, --cache-compression-level, and --cache-force-compression flags for controlling cache layer compression independently
  • buildah commit gains --compression-format, --compression-level, and --force-compression flags with containers.conf fallback
  • Fix commit.go switch to set DirForceCompress for all compression algorithms, not just gzip
  • Fix push.go blobcache to treat any non-uncompressed format as requiring compression
  • Add conflicting flag validation for --disable-compression with --compression-format/--force-compression

Fixes: #6660
Fixes: #6072

Depends on: containers/container-libs#731

What type of PR is this?

/kind api-change

/kind bug

/kind cleanup

/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

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?

`push`, build`, `commit`: respect `compression_format` from `containers.conf`

`buildah push`, `buildah build --cache-to`, and `buildah commit` now honor the `compression_format` and `compression_level` settings from `containers.conf`. Previously, `--cache-to` ignored these settings and always used `gzip`, causing cache layers to lose the configured compression. `buildah build` also gains new `--cache-compression-format`, `--cache-compression-level`, and `--cache-force-compression` flags for controlling cache layer compression independently of the final image. `buildah commit` also gains new `--compression-format`, `--compression-level`, and `--force-compression` flags.

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 1, 2026

While fixing the build cache, I decided to also check the pull and commit where compression is used.

@Honny1 Honny1 closed this Apr 1, 2026
@Honny1 Honny1 reopened this Apr 1, 2026
@Honny1 Honny1 force-pushed the teach-Zstd branch 7 times, most recently from 4ce00cc to b66921a Compare April 17, 2026 09:14
@packit-as-a-service
Copy link
Copy Markdown

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

@Honny1 Honny1 marked this pull request as ready for review April 17, 2026 10:11
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 17, 2026
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 17, 2026

/packit rebuild-failed

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 17, 2026

PTAL @containers/buildah-maintainers

Comment thread pkg/cli/build.go Outdated
Comment on lines +254 to +256
if defaultContainerConfig.Engine.CompressionLevel != nil {
compressionLevel = defaultContainerConfig.Engine.CompressionLevel
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if defaultContainerConfig.Engine.CompressionLevel != nil {
compressionLevel = defaultContainerConfig.Engine.CompressionLevel
}
compressionLevel = defaultContainerConfig.Engine.CompressionLevel

Definitely non-blocking, it just caught my eye, but the if is redundant, right? compressionLevel would be nil on declaration, so assigning nil to it again would not be a problem.

@simonbrauner
Copy link
Copy Markdown

LGTM

Copy link
Copy Markdown
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.

What's the intent behind not adding to "build" the flags that are being added to "push" and "commit"?

Comment thread cmd/buildah/commit.go
if err != nil {
return err
}
options.CompressionFormat = &algo
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was the bit that checks for c.Flag("compression-format").Changed above intended to be merged into this block, to parallel the similar logic in the next block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, that is much cleaner. I will fix that.

Comment thread cmd/buildah/push.go
if err != nil {
return err
}
options.CompressionFormat = &algo
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was the bit that checks for c.Flag("compression-format").Changed above intended to be merged into this block, to parallel the similar logic in the next block?

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 24, 2026

What's the intent behind not adding to "build" the flags that are being added to "push" and "commit"?

I forgot to do that. Good catch.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 24, 2026
@Honny1 Honny1 requested a review from nalind April 24, 2026 12:57
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 24, 2026

@nalind I addressed your comments.

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 27, 2026

PTAL @containers/buildah-maintainers

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 27, 2026

PTAL @containers/podman-maintainers

Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread tests/commit.bats Outdated
$cid \
dir:$destdir

run cat $destdir/manifest.json
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should check "$status", just in case the "dir:" format changes, however unlikely that is.

Comment thread tests/commit.bats
Comment thread pkg/cli/common.go Outdated
fs.StringVarP(&flags.CWOptions, "cw", "", "", "confidential workload `options`")
fs.StringVar(&flags.CacheCompressionFormat, "cache-compression-format", "", "compression format to use for cache layers")
fs.IntVar(&flags.CacheCompressionLevel, "cache-compression-level", 0, "compression level to use for cache layers")
fs.BoolVar(&flags.CacheForceCompressionFormat, "cache-force-compression", false, "use the specified compression algorithm for cache layers if the destination contains a differently-compressed variant already")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

build can write the final image to non-local destinations, as commit does. Could these flags also affect those cases?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These flags are intentionally cache-only (--cache-to). The final image commit already respects the compression_format in containers.conf, and buildah push has its own --compression-format flag for the actual push. Should I clarify this in the docs, or implement flags that affect the entire build?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding CLI flags to "commit" for overriding the defaults from the configuration file when committing the image, and having flags for "build" that do the same thing for cache images, but no equivalent for "build" for the final image just looks like an oversight. Most options for "commit" should also be available for "build".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have added support for --compression-format, --compression-level, and --force-compression to apply to the final image during buildah build, not just cache layers. These take effect when the output is a non-local destination (registry, dir:, oci-archive:, etc.).

@Honny1 Honny1 requested a review from nalind April 28, 2026 11:18
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented Apr 29, 2026

PTAL @nalind

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 4, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers @mheon

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 13, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers @nalind

Copy link
Copy Markdown
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.

Some questions about the tests that verify compression on --cache-to targets.

Comment thread imagebuildah/stage_executor.go
Comment thread tests/bud.bats
Comment thread tests/bud.bats Outdated
Comment thread tests/bud.bats Outdated
@Honny1 Honny1 force-pushed the teach-Zstd branch 3 times, most recently from 39d0f40 to 94fb09a Compare May 15, 2026 09:46
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 15, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers @nalind

Copy link
Copy Markdown
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.

Some questions about the tests.

Comment thread tests/bud.bats
Comment thread tests/bud.bats
Comment thread tests/bud.bats Outdated
Comment thread tests/bud.bats Outdated
Comment thread tests/bud.bats Outdated
Comment thread tests/bud.bats Outdated
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 19, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers @nalind

Copy link
Copy Markdown
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.

Some nits in the tests, but LGTM.

Comment thread tests/commit.bats Outdated
Comment thread tests/push.bats
Comment thread tests/push.bats
Comment thread tests/bud.bats
Comment thread tests/bud.bats
Honny1 added 5 commits May 20, 2026 14:07
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Fixes: containers#6660
Fixes: containers#6072

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 20, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers @nalind

Copy link
Copy Markdown
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.

LGTM, thanks!

@Honny1
Copy link
Copy Markdown
Member Author

Honny1 commented May 20, 2026

PTAL @containers/buildah-maintainers @containers/podman-maintainers for final review and merge.

func NewBlobCache(ref types.ImageReference, directory string, compress types.LayerCompression) (BlobCache, error) {
return imageBlobCache.NewBlobCache(ref, directory, compress)
// The optional Option values can further refine behavior.
func NewBlobCache(ref types.ImageReference, directory string, compress types.LayerCompression, opts ...Option) (BlobCache, error) {
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.

(An absolutely non-blocking drive-by, by no means a review:) Maybe the Buildah callers could call the c/image package directly, without extending the API here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These were left here to avoid breaking callers when the package's guts were moved.

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.

Yes, I just meant that that doesn’t require adding more compatibility wrappers. The existing pkg/blobcache could remain as is for compatibility, and callers within Buildah could call the c/image one with the new options.

Anyway this already merged.

Comment thread pkg/cli/common.go
RewriteTimestamp bool
CreatedAnnotation bool
SourcePolicyFile string
TransientRunMounts []string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not to fix now, but I will note that I hate seeing long structs like this that aren't in alpha order. It makes debugging later down the line harder IMHO>

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

LGTM

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

/lgtm

@TomSweeneyRedHat TomSweeneyRedHat merged commit 622a55a into containers:main May 20, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--cache-to causes compression_format from containers.conf to be ignored cache compression algorithm

6 participants