Repository navigation
bazel: Backport oci, pigz and compressed_tar to WORKSPACE, and allow the libcxx LLVM version to be set - #5616
Conversation
abcd307 to
2a8e51f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The pigz integration breaks Bazel 7.7.1 and macOS builds and can point toolchains at missing artifacts; path validation also rejects valid edits and package mappings.
7 open issues
Fail preparation when an enabled pigz artifact is missing · New Keep the pigz convenience target manual on macOS · New Remove unsupported repo_metadata calls from the Bazel 7.7 backport · New Restrict pigz-dependent fixtures to Linux · New Validate only files required by the requested edits · New Check home symlinks only when creating the home directory · New Normalize absolute package prefixes before path validation · New
What changed in this PR
Backports OCI base-image editing and parallel gzip packaging to support Envoy release branches that use Bazel WORKSPACE.
Changes:
- Adds
oci_base_editto extend base-image accounts and package metadata. - Adds prebuilt and host pigz toolchains, WORKSPACE registration, and release hash updates.
- Adds gzip-only
compressed_tar, with fixtures and tests.
| File | Description |
|---|---|
bazel/WORKSPACE |
Creates and registers pigz toolchains. |
bazel/versions.bzl |
Adds the pigz version and prebuilt hash placeholders. |
bazel/tarball/test/tool.sh |
Provides an executable-content fixture. |
bazel/tarball/test/plain.txt |
Provides a default-attributes fixture. |
bazel/tarball/test/hello.txt |
Provides an archive-content fixture. |
bazel/tarball/test/compressed_tar_test.bzl |
Tests mtree rendering and duplicate paths. |
bazel/tarball/test/BUILD |
Defines archive fixtures and tests. |
bazel/tarball/test/assert_compressed_tar.sh |
Checks compression, metadata, layout, and contents. |
bazel/tarball/compressed_tar.bzl |
Implements bsdtar-to-pigz archive creation. |
bazel/tarball/BUILD |
Exports the compressed tar rule. |
bazel/pigz/toolchain.bzl |
Implements pigz providers, resolution, and fallback. |
bazel/pigz/test/pigz_test.bzl |
Tests toolchain rendering and platform handling. |
bazel/pigz/test/BUILD |
Defines pigz unit and round-trip tests. |
bazel/pigz/test/assert_pigz_roundtrip.sh |
Checks reproducible compression and decompression. |
bazel/pigz/repositories.bzl |
Provides WORKSPACE setup and registration helpers. |
bazel/pigz/README.md |
Documents pigz setup and consumption. |
bazel/pigz/private/pigz_prebuilt.bzl |
Defines prebuilt repositories and host-toolchain generation. |
bazel/pigz/private/BUILD |
Exports repository-rule definitions. |
bazel/pigz/defs.bzl |
Exposes the public pigz toolchain API. |
bazel/pigz/BUILD |
Defines the public executable and fallback toolchain. |
bazel/oci/tests/layout/oci-layout |
Identifies the OCI layout fixture. |
bazel/oci/tests/layout/index.json |
References the fixture image manifest. |
bazel/oci/tests/layout/blobs/sha256/f6b0fb35ba53df14ac9e15793dd3408774c6d1520f80cd3d06d8b80ea397bf25 |
Describes the fixture image layers. |
bazel/oci/tests/layout/blobs/sha256/0dabb676417a2f768d6464c2195ec31cc19e70ced763aa377056341a8a8d26e8 |
Provides fixture image configuration. |
bazel/oci/tests/BUILD |
Defines the base-edit fixture and test. |
bazel/oci/tests/base_edit_test.py |
Checks generated accounts, homes, and package status. |
bazel/oci/README.md |
Documents base-image editing and limitations. |
bazel/oci/private/BUILD |
Exports the editing implementation files. |
bazel/oci/private/base_edit.sh |
Reads image layers and writes the edited layer. |
bazel/oci/private/base_edit.bzl |
Connects editing actions to jq and tar toolchains. |
bazel/oci/defs.bzl |
Exposes the oci_base_edit macro. |
bazel/oci/BUILD |
Exports the public OCI definitions. |
.github/workflows/_release.yml |
Adds pigz hash updates during release preparation. |
Review effort: Balanced
…and set up pigz envoyproxy/toolshed#5616 with the pigz prebuilt hashes set, to test it before the release: the bins release is 0.2.34 there, and `//pigz` is set up with `setup_pigz()` and `load_pigz_toolchains()`. Signed-off-by: Ryan Northey <[email protected]>
2a8e51f to
d3ddeff
Compare
As the release preparation would, to test envoyproxy#5616 from Envoy before the release. Signed-off-by: Ryan Northey <[email protected]>
…and set up pigz envoyproxy/toolshed#5616 with the pigz prebuilt hashes set, to test it before the release: the bins release is 0.2.34 there, and `//pigz` is set up with `setup_pigz()` and `load_pigz_toolchains()`. Signed-off-by: Ryan Northey <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Populating the Linux prebuilt hashes would expose pigz targets and gzip tests to macOS builds without a supported toolchain, breaking CI; overly broad symlink checks also reject valid image edits.
8 open issues
Restrict pigz-dependent fixtures to Linux Remove unsupported repo_metadata calls from the Bazel 7.7 backport Keep the pigz convenience target manual on macOS Fail preparation when an enabled pigz artifact is missing Add an end-to-end compression test without prebuilts · New Normalize absolute package prefixes before path validation Check home symlinks only when creating the home directory Validate only files required by the requested edits
Review effort: Balanced
As the release preparation would, to test envoyproxy#5616 from Envoy before the release. Signed-off-by: Ryan Northey <[email protected]>
…and set up pigz envoyproxy/toolshed#5616 with the pigz prebuilt hashes set, to test it before the release: the bins release is 0.2.34 there, and `//pigz` is set up with `setup_pigz()` and `load_pigz_toolchains()`. Signed-off-by: Ryan Northey <[email protected]>
oci, pigz and compressed_tar to WORKSPACEoci, pigz and compressed_tar to WORKSPACE, and allow the libcxx LLVM version to be set
…nvoyproxy#5597) rules_oci can not run anything in an image, so the `RUN` steps of a Dockerfile that add users or install packages on a base image have to be replaced. rules_distroless `passwd`, `group` and `dpkg_status` write the whole of those files, which replaces those of the base. `oci_base_edit` reads the passwd, group, shadow, gshadow and dpkg status files from the layers of the base image, and creates a layer with users and groups added as `adduser` adds them, their home directories, and packages added to the dpkg status. Backport note (workspace): as on `main`. (cherry picked from commit 0dbd94a) Signed-off-by: Ryan Northey <[email protected]>
`//pigz` is pigz (parallel gzip) resolved for the platform it runs on,
for use as a tool, eg as the `compressor` of a `pkg_tar`, to gzip with
all the cores. It resolves `//pigz:toolchain_type`, in order:
- the prebuilt toolchains (`pigz_prebuilt_extension`), from the bins
release's `pigz-<version>-linux-{x86_64,aarch64}.tar.zst`;
- a source toolchain, if the consumer registers one (the README shows
how);
- otherwise a fallback toolchain, with which `//pigz` fails with a
message, rather than building pigz.
toolshed builds the `pigz` module only as a dev dependency (for the
packages, and as the source toolchain of its own tests), so consumers
never fetch and compile pigz unless they ask to.
The toolchains match on `target_compatible_with`: as a tool, in the
exec configuration, the target platform is the one pigz runs on.
The bins release builds the packages (`//pigz/source:pigz_packages`):
the binary built against the glibc 2.31 sysroot and stripped, with the
pigz, zlib and zopfli licenses; the release preparation sets
`VERSIONS["pigz_sha256"]` from it. Tests check the packages (layout,
modes, stripping, arch, runtime deps, glibc floor), a compress /
decompress roundtrip with the resolved and source binaries (also on
macOS), the hub rendering, and the failure without a pigz for the
platform.
Backport note (workspace): the toolchain and the prebuilt repositories only, set up with
`setup_pigz()` and `load_pigz_toolchains()` (`//pigz:repositories.bzl`) in place of the
module extension. The source build and its packaging stay on `main`, which publishes the
prebuilts. Their hashes are empty, as here on `main`, for the release preparation to set:
`//pigz` is `manual`, as this branch has no source toolchain (so no pigz without a prebuilt
for the platform), and its test until then. `repository_ctx.repo_metadata` is only called
where Bazel has it: Envoy's `release/v1.38` and earlier use Bazel 7. The
README describes the prebuilts as `main` now publishes them (against zlib-ng, envoyproxy#5606).
(cherry picked from commit fc8e06e)
Signed-off-by: Ryan Northey <[email protected]>
`pigz_prebuilt_extension.setup(host_path = "/abs/path/pigz")` adds a toolchain over that pigz for the host's OS and CPU, after the prebuilts: so it is used where there is no prebuilt (eg macOS), or where the prebuilt is disabled, rather than building pigz or failing. The path must be absolute and exist (it is watched, so a change re-evaluates the toolchains), and the host must be Linux or macOS on x86_64 or aarch64; otherwise the hub fails, with the reason. The hub is not reproducible with a host pigz. The fallback's failure now points at the option too. Backport note (workspace): the path is set with `setup_pigz(host_path = ...)`. The prebuilts are not configurable here, so a prebuilt for the host always takes precedence. (cherry picked from commit 77185d7) Signed-off-by: Ryan Northey <[email protected]>
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]>
`libcxx_libs` fetches the bundles for toolshed's LLVM version (22.1.8). A consumer on another version (Envoy's `release/v1.39` and earlier are on LLVM 18.1.8) then cross-compiles its LLVM's libc++ headers against the `__config_site` of another, which fails: __config:483:6: error: "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" `setup_libcxx_libs(llvm_version = ...)` selects the bundles of that version, from the bins release that published them (`*_version`, eg 0.1.59 for 18.1.8) and with their hashes (`*_sha256`). Signed-off-by: Ryan Northey <[email protected]>
3220b92 to
61f545d
Compare
…and set up pigz envoyproxy/toolshed#5616 with the pigz prebuilt hashes set, to test it before the release: the bins release is 0.2.34 there, and `//pigz` is set up with `setup_pigz()` and `load_pigz_toolchains()`. Signed-off-by: Ryan Northey <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Automatic execution groups can cause tools to run on incompatible architectures, and the LLVM version override lacks focused test coverage.
3 open issues
8 resolved since last review
Restrict pigz-dependent fixtures to Linux Remove unsupported repo_metadata calls from the Bazel 7.7 backport Keep the pigz convenience target manual on macOS Fail preparation when an enabled pigz artifact is missing Add an end-to-end compression test without prebuilts Normalize absolute package prefixes before path validation Check home symlinks only when creating the home directory Validate only files required by the requested edits
Review effort: Balanced
61f545d to
ffc586f
Compare
ffc586f to
61f545d
Compare
As the release preparation would, to test envoyproxy#5616 from Envoy before the release. Signed-off-by: Ryan Northey <[email protected]>
…and set up pigz envoyproxy/toolshed#5616 with the pigz prebuilt hashes set, to test it before the release: the bins release is 0.2.34 there, and `//pigz` is set up with `setup_pigz()` and `load_pigz_toolchains()`. Signed-off-by: Ryan Northey <[email protected]>
| local parent | ||
| parent="$(dirname "$1")" | ||
| while [[ "$parent" != "/" ]]; do | ||
| if ! in_image "$parent"; then |
| args.add(ctx.executable.compressor) | ||
| args.add(ctx.outputs.out) | ||
| args.add_all(ctx.attr.compressor_args) | ||
| ctx.actions.run_shell( |
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>
0.4.13.post4 has, backported to the WORKSPACE line (envoyproxy/toolshed#5616): - `oci_base_edit`, `compressed_tar` and a hermetic pigz, to build the release container images with rules_oci, and to gzip with all the cores; - `setup_libcxx_libs(llvm_version = ...)`, to cross-compile with the libc++ of this branch's LLVM. It is also on toolshed's bins v0.2.34. Signed-off-by: Ryan Northey <[email protected]>


Port
//oci(oci_base_edit),//pigzand//tarball:compressed_tar.bzlfrommainat bazel-v0.5.22, so Envoy's WORKSPACE release branches (release/v1.39and earlier) can build their release container images with rules_oci and gzip the packages with all the cores, asmainandrelease/v1.40do.One commit per original PR, each with a backport note:
oci_base_editto add users and packages to a base image #5597oci_base_edit: as onmain.setup_pigz()andload_pigz_toolchains()(//pigz:repositories.bzl) replace the module extension, as//pgpdoes forsq, and this repo'sWORKSPACEcalls both. The source build and its packaging stay onmain, which publishes the prebuilts. The README describes them asmainnow builds them (against zlib-ng, bazel/pigz: Build pigz against zlib-ng #5606, which has nothing else to backport here).setup_pigz(host_path = ...).compressed_tar, bsdtar into a parallel compressor #5607compressed_tar: as onmain. zstd uses the consumer's@zstd(Envoy has one; this branch's toolshed does not), so only gzip is tested here.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'srelease/v1.39and 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_siteand 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 #5601, for the release preparation to set: the_release.ymlstep that does that comes with #5601 too. This branch has no source toolchain to fall back to, so until the hashes are set//pigzand the tests that run it aremanual.Not built locally: this PR's CI is the first test.