Repository navigation
bazel/tarball: Add compressed_tar, bsdtar into a parallel compressor - #5607
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Slashless mtree directory entries change the current directory, causing later files and directories to be nested incorrectly, breaking the archive layout and both tarball tests.
1 open issue
What changed in this PR
Adds a Bazel compressed_tar rule to speed up large release archives and container layers by streaming hermetic bsdtar output into a parallel compressor.
Changes:
- Supports gzip via pigz and zstd, with validated compression levels and selective compressor dependencies.
- Renders
pkg_filesmappings into mtree entries with deterministic metadata. - Adds rendering, archive-content, and duplicate-path tests.
| File | Description |
|---|---|
bazel/tarball/test/tool.sh |
Executable-content fixture. |
bazel/tarball/test/plain.txt |
Fixture for default file attributes. |
bazel/tarball/test/hello.txt |
Fixture for mapped file contents. |
bazel/tarball/test/compressed_tar_test.bzl |
Tests mtree rendering and duplicate-path rejection. |
bazel/tarball/test/BUILD |
Defines fixtures and gzip/zstd test targets. |
bazel/tarball/test/assert_compressed_tar.sh |
Checks compression, layout, metadata, and extracted contents. |
bazel/tarball/compressed_tar.bzl |
Implements mtree rendering and compressed archive generation. |
bazel/tarball/BUILD |
Exports the new rule file. |
Review effort: Balanced
phlax
force-pushed
the
compressed-tar
branch
from
November 14, 2026 18:19
22c9e01 to
e68e6a1
Compare
phlax
force-pushed
the
compressed-tar
branch
from
November 14, 2026 18:30
e68e6a1 to
68b3c7e
Compare
`pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Signed-off-by: Ryan Northey <[email protected]>
phlax
force-pushed
the
compressed-tar
branch
from
November 14, 2026 18:40
68b3c7e to
bc7c7b0
Compare
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): gzip only, and its tests Linux only: this branch has no `@zstd`, and the prebuilt pigz is for Linux. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): gzip only, and its tests Linux only: this branch has no `@zstd`, and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): gzip only, and its tests Linux only: this branch has no `@zstd`, and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): gzip only, and its tests Linux only: this branch has no `@zstd`, and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): as on `main`, but tested for gzip only, on Linux only: zstd uses the consumer's `@zstd` (this branch's toolshed has none), and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
envoyproxy#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): as on `main`, but tested for gzip only, on Linux only: zstd uses the consumer's `@zstd` (this branch's toolshed has none), and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
to phlax/toolshed
that referenced
this pull request
Nov 17, 2026
…allow the libcxx LLVM version to be set Port `//oci` (`oci_base_edit`), `//pigz` and `//tarball:compressed_tar.bzl` from `main` at bazel-v0.5.22, so Envoy's WORKSPACE release branches (`release/v1.39` and earlier) can build their release container images with rules_oci and gzip the packages with all the cores, as `main` and `release/v1.40` do. Backported, with what differs from `main`: - envoyproxy#5597 `oci_base_edit`: as on `main`. - envoyproxy#5601 hermetic pigz: the toolchain and the prebuilt repositories only. `setup_pigz()` and `load_pigz_toolchains()` (`//pigz:repositories.bzl`) replace the module extension, as `//pgp` does for `sq`, and this repo's `WORKSPACE` calls both. The source build and its packaging stay on `main`, which publishes the prebuilts. The README describes them as `main` now builds them (against zlib-ng, envoyproxy#5606, which has nothing else to backport here). `repository_ctx.repo_metadata` is only called where Bazel has it: Envoy's `release/v1.38` and earlier use Bazel 7. - envoyproxy#5605 a pigz on the host, by path: `setup_pigz(host_path = ...)`. The prebuilts are not configurable here, so a prebuilt for the host always takes precedence. - envoyproxy#5607 `compressed_tar`: as on `main`. zstd uses the consumer's `@zstd` (Envoy has one; this branch's toolshed does not), so only gzip is tested here, on Linux only. Also, not a backport: `setup_libcxx_libs(llvm_version = ...)`. The libc++ bundles for cross-compiling are fetched for toolshed's LLVM (22.1.8), but Envoy's `release/v1.39` and earlier compile with LLVM 18.1.8, so a cross-compile there (arm64 from x64, as the one-job release build does) gets LLVM 18's headers with LLVM 22's `__config_site` and fails. The option selects the bundles of the consumer's LLVM, from the bins release that published them (0.1.59 for 18.1.8). The prebuilt hashes (`VERSIONS["pigz_sha256"]`) are empty, as in envoyproxy#5601, for the release preparation to set: the `_release.yml` step that does that comes with envoyproxy#5601 too. This branch has no source toolchain to fall back to, so `//pigz` is `manual` (there is no pigz without a prebuilt for the platform), and the tests that run it are `manual` until the hashes are set. (cherry picked from commit 0dbd94a) (cherry picked from commit fc8e06e) (cherry picked from commit 77185d7) (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
phlax
added a commit
that referenced
this pull request
Nov 17, 2026
#5607) `pkg_tar` writes tarballs in Python (~20MB/s), which dominates builds of large tarballs (eg envoy's release binaries and container image layers, several GB with the debug info). `compressed_tar` takes the same `pkg_files` (their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain) into a hermetic compressor using all the cores: pigz (`//pigz`, `-n`) for gzip, or zstd (`-T0`), with an optional level. The tarball is reproducible: entries are sorted, owned by root unless the `pkg_files` set an owner, with `pkg_tar`'s "portable" mtime; parent directories are added (0755), and files without a mode are 0555, as `pkg_tar` does. Tests check the mtree rendering, the gzip and zstd tarballs (format, layout, modes, owners, mtime and contents), and that a path given twice fails. Backport note (workspace): as on `main`, but tested for gzip only, on Linux only: zstd uses the consumer's `@zstd` (this branch's toolshed has none), and the prebuilt pigz is for Linux. The tests that gzip are `manual` until there is a prebuilt. (cherry picked from commit 49947f3) Signed-off-by: Ryan Northey <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

pkg_tarwrites tarballs in Python (~20MB/s), which dominates builds of large tarballs: in envoy's release build (envoyproxy/envoy#49259) it was most of the time spent writing the release tarball and the container image layers (several GB with the debug info).compressed_tar(@envoy_toolshed//tarball:compressed_tar.bzl) takes the samepkg_files(their paths and attributes), writes an mtree of them, and streams bsdtar (the hermetic tar toolchain,@aspect_bazel_lib//lib:tar_toolchain_type) into a hermetic compressor using all the cores:compression = "gzip": pigz (//pigz, with-n: no name or time in the header);compression = "zstd": zstd (-T0);level(gzip 1-9, zstd 1-19), checked.The macro picks the compressor, so only the one used is analysed (zstd users never resolve pigz).
The tarball is reproducible: entries are sorted, owned by root (uid/gid 0, named root) unless the
pkg_filesset an owner, withpkg_tar's "portable" mtime (2000-01-01); parent directories are added (0755), and files without a mode are 0555, aspkg_tardoes.In envoy-ci-staging, swapping the release tarball and binary layers to this (from
pkg_tar+ the same compressors) cut the release packaging (link done -> build done) from 325s to 269s (arm64) and 342s to 303s (x64).Tests: the mtree rendering, the gzip and zstd tarballs (compression format, layout, modes, owners, mtime, contents), and that a path given twice fails analysis.