Skip to content

Add support for gzip-compressed CPIO output#2253

Open
lavishpal wants to merge 1 commit into
chainguard-dev:mainfrom
lavishpal:build-cpio-gzip-support
Open

Add support for gzip-compressed CPIO output#2253
lavishpal wants to merge 1 commit into
chainguard-dev:mainfrom
lavishpal:build-cpio-gzip-support

Conversation

@lavishpal
Copy link
Copy Markdown

This PR implement support for gzip-compressed CPIO archives when the output filename ends with .gz
Detect .gz output filenames and wrap the destination writer with a gzip writer
Ran the relevant go tests

@lavishpal lavishpal force-pushed the build-cpio-gzip-support branch from f692bf1 to 282b5a3 Compare June 1, 2026 23:28
@lavishpal
Copy link
Copy Markdown
Author

cc: @imjasonh

Signed-off-by: Lavish Pal <lvishpal408@gmail.com>
@lavishpal lavishpal force-pushed the build-cpio-gzip-support branch from 282b5a3 to 15aa0c7 Compare June 4, 2026 14:09
Copy link
Copy Markdown
Contributor

@codysoyland codysoyland left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Is this needed if you can just run the output to gzip?

Can you include tests?

return cpio.FromLayer(layer, f)
if strings.HasSuffix(dest, ".gz") {
gzw := gzip.NewWriter(f)
defer gzw.Close()
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.

nit: should probably check the error returned by the gzip writer (gzq.Close() writes a footer)

@lavishpal
Copy link
Copy Markdown
Author

implemented based on an existing TODO comment in the codebase "// TODO(mattmoor): Consider wrapping in a gzip writer if the filename ends in .gz"

Happy to add tests and fix the gzw.Close() error handling.

@lavishpal
Copy link
Copy Markdown
Author

also to add some context on the running two separate commands means the full uncompressed output hits disk before being compressed even piping avoids that but still requires gzip to present as a binary which may be not guaranteed on windows or in minimal/distroless build env

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants