Skip to content

bazel/tarball: Add compressed_tar, bsdtar into a parallel compressor - #5607

Merged
phlax merged 1 commit into
envoyproxy:mainfrom
phlax:compressed-tar
Nov 14, 2026
Merged

phlax merged 1 commit into
envoyproxy:mainfrom
phlax:compressed-tar

Conversation

@phlax

@phlax phlax commented Nov 14, 2026

Copy link
Copy Markdown
Member

pkg_tar writes 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 same pkg_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);
  • optional 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_files set an owner, with pkg_tar's "portable" mtime (2000-01-01); parent directories are added (0755), and files without a mode are 0555, as pkg_tar does.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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_files mappings 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

Comment thread bazel/tarball/compressed_tar.bzl Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the new compressed_tar packaging option.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

`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
phlax merged commit 49947f3 into envoyproxy:main Nov 14, 2026
56 checks passed
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]>
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