Skip to content

build: the images install the extension flake's build, through docker-bake.hcl - #24

Merged
sagikazarmark merged 9 commits into
mainfrom
experiment/nix-docker-bake
Nov 27, 2026
Merged

sagikazarmark merged 9 commits into
mainfrom
experiment/nix-docker-bake

Conversation

@sagikazarmark

Copy link
Copy Markdown
Contributor

Why

The Docker images of the integration, load, soak, upstream and quickstart suites compiled the extension themselves, with rustup and Cargo cache mounts, while the PIE archives and Nix users' builds came from the extension flake. That's two builds of the same module to maintain, and CI's image jobs compiled it from scratch on every run.

Since #23, restate-php.cachix.org has the flake's builds for both CPUs, the debug and diagnostics builds the suites use included. With this PR the images install the flake's build instead of compiling their own, and CI downloads it.

Development keeps just extension build (plain Cargo, incremental). An image build after a Rust change compiles the extension in about 30 s.

docs/decisions/0044-extension-modules-in-the-images.md has the decision and the measurements.

What

  • The images install the extension, they don't build it. One Dockerfile per server, next to its configuration: docker/frankenphp/, docker/fpm/, docker/quickstart/. Each target COPY --froms restate.so out of a restate-extension context into its PHP's extension_dir and checks that it loads. docker/Dockerfile, its Rust stages and docker/extension/build.sh are gone.
  • docker-bake.hcl builds them. Targets are <target>-<minor>-<variant>, e.g. frankenphp-extension-84-debug. Each image's context is the extension build of the same PHP minor, thread safety and variant, so the two can't disagree. PHP 8.6's official images are ZTS only, so their images get the ZTS build.
  • Where the extension is built:
    • extension/Dockerfile (the default): Nix in a container, cross-compiling. Its first layer fetches everything the builds need except the source (~1 GiB, kept until a lock file or the toolchain changes). It needs only extension/, so it goes with the split to ext-restate.
    • RESTATE_PHP_IMAGE_EXTENSION=host: the host's Nix, handed to bake as EXTENSION_DIR. Every image-building workflow sets this, so runners download the build from Cachix and never build that layer.
  • bin/build-image.sh [--php <minor>] [--variant <variant>] <target> <tag> is how the recipes, scripts and workflows build an image.
  • Base images: one stage per PHP minor in each Dockerfile (frankenphp-8.5, …), which Dependabot updates; bake picks them by name. RESTATE_PHP_TEST_PHP_VERSION replaces RESTATE_PHP_TEST_FRANKENPHP_BASE_IMAGE and RESTATE_PHP_TEST_FPM_BASE_IMAGE. ci.yaml's hand-bumped FrankenPHP tags are gone.
  • The flake moves to ext-php-rs.nix 0.4.0:
    • legacyPackages.extensions.<php>.<nts|zts>.<target>.<variant> (buildRustPhpExtensions) and extension-inputs (mkExtensionInputs); packages.pie is the release variant.
    • The per-system outputs are in one scope (an inline eachSystem), and phps is a list of packages. I checked every derivation (328 of them, overlay included) against the previous structure: unchanged.
  • Callers: tests/justfile, tests/load/ (the compose file no longer builds the endpoint), bin/conformance-upstream-local.sh (which asks bake whether a target exists), upstream.yaml (plain Nix and Cachix on the runner), the other workflows, dependabot.yaml (/docker/*, /extension).
  • Docs: decision 0044 (amends 0037 and 0042), docker/README.md, TESTING.md, extension/README.md.

Tested locally

  • All six targets (plus PHP 8.6's FPM image) build and load the right build: ZTS for FrankenPHP and 8.6, NTS otherwise.
  • just test integration frankenphp and nginx-fpm (--filter 'BasicServiceTest|ServingTest') pass.
  • Without bake, the build fails at the COPY (/restate.so: no such file or directory). An NTS image given a ZTS build fails its load check with PHP's undefined symbol warning.
  • With extension-inputs in place, the extension stage builds only the extension and fetches nothing.
  • just lint and nix flake check --all-systems --no-build.

Not verified

  • The workflows themselves: this PR's run is their first. ext-php-rs.nix 0.3.0 and 0.4.0 changed every build recipe, so nothing is in Cachix yet. This PR's extension workflow builds and pushes everything; until it has, the image jobs build the extension themselves (about 30 s each).
  • The load workflow (self-hosted runner) and the nightly ones.
  • Podman: it has no docker buildx bake, so bin/build-image.sh doesn't work with it (documented in 0044 and TESTING.md).

Upstream issues filed along the way: sagikazarmark/ext-php-rs.nix#7 (compiled dependencies in their own derivation, not on our path), #9, #11 and #12 (fixed in 0.3.0 and 0.4.0).

… docker-bake.hcl

docker/Dockerfile no longer compiles the extension: every target installs restate.so for its PHP from the restate-extension context (docker/extension/install.sh). docker-bake.hcl builds each target per PHP minor and variant, and gives it the flake's module of the same PHP minor, thread safety and variant: built by extension/Dockerfile (Nix in a container), or with RESTATE_PHP_IMAGE_EXTENSION=host by the host's Nix, which CI uses to download it from restate-php.cachix.org. bin/build-image.sh is the one entry point for the recipes and workflows.

Each PHP minor has base stages of its own (php-cli-8.5, frankenphp-8.5, php-fpm-8.5), which Dependabot updates and bake picks by name. RESTATE_PHP_TEST_PHP_VERSION chooses the suites' PHP minor, replacing the base image overrides.

docs/decisions/0044-extension-modules-in-the-images.md has the decision and the measurements.
…ker inputs layer

0.3.0 passes the PHP headers and libclang through a setup hook instead of env, so a module's inputDerivation includes them (sagikazarmark/ext-php-rs.nix#9). moduleInputs is now the modules' inputDerivations instead of their drvAttrs. nixpkgs is unchanged; every module derivation changes once.
…ns and mkExtensionInputs

The flake's matrix is buildRustPhpExtensions (sagikazarmark/ext-php-rs.nix#12), packages.pie the release variant through collectExtensions, and the Docker inputs layer mkExtensionInputs, which leaves the source out. The outputs are renamed to match: legacyPackages.extensions.<php>.<nts|zts>.<target>.<variant> and extension-inputs. extension/Dockerfile's inputs layer copies only what the flake evaluates them from, so .cargo/ and core/Cargo.toml no longer invalidate it.
An eachSystem helper builds packages, legacyPackages, checks and formatter from one function of the system, merged with the overlay (the one output that isn't per system, and the one that needs rustPhpPlatform as a function of the package set). The platform, the extension matrix, the PHP with the extension and FrankenPHP are evaluated once per system instead of once per output, and checks no longer read them back through self.packages. Every derivation is unchanged.
phps is the per-system list of PHP packages instead of attribute names every caller looked up in pkgs. The .phpt checks are keyed php84, … from each PHP's version, as buildRustPhpExtensions keys the extensions. Every derivation is unchanged.
extension/Dockerfile copies with COPY --parents and builds to nix build's default result link. The flake drops its description and the rust-overlay comment, and notes a TODO on following nixpkgs unstable.
…er/quickstart

One file shared the stages that compiled the extension; with none left, each server's images go in its own directory, next to its configuration, with only its own base stages and one BASE_IMAGE argument. docker-bake.hcl's targets, tags and contexts are unchanged. bin/conformance-upstream-local.sh asks bake whether a target exists instead of grepping docker/Dockerfile, and Dependabot watches docker/*.
…tall script

Each target copies restate.so from the restate-extension context and moves it into its PHP's extension_dir, which depends on the PHP version and thread safety, then enables it with docker-php-ext-enable (php-fpm: docker/fpm/php.ini) and checks that it loads. A missing context fails the COPY; a module for another PHP fails the load check. docker/extension/install.sh and its bind mounts are gone.
@github-actions

Copy link
Copy Markdown

Test Results

  8 files  ±0    8 suites  ±0   2m 4s ⏱️ -7s
 71 tests ±0   71 ✅ ±0  0 💤 ±0  0 ❌ ±0 
322 runs  ±0  322 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit f70e131. ± Comparison against base commit 2327557.

@sagikazarmark
sagikazarmark merged commit f25f23b into main Nov 27, 2026
44 checks passed
@sagikazarmark
sagikazarmark deleted the experiment/nix-docker-bake branch November 27, 2026 03:52
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.

1 participant