# The build image

> What the build image and the Alpine run image hold, how they are built, verified and published, every step of a bump in order — the Android one included, where the image and the framework point at each other — and what moves in the framework afterwards.

Source: https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html

One image carries the whole toolchain of every Linux, web and Android job, so that a job downloads nothing and a green run means the same toolchain built it as last time. It lives in its own repository, [raylib-build-image](https://github.com/omardev29/raylib-build-image), and the framework names it by digest. This page is how to keep it: what is in it, how a new one is made and published, and the order of every step that pins it.

## Two images

| Image | Built from | Runs | Pinned in the framework by |
|---|---|---|---|
| `ghcr.io/omardev29/raylib-build` | `Dockerfile`, with `python/`, `smoke/` and `verify/`; workflow `docker-image.yaml` | every Linux, web and Android job, the framework's own jobs, this site's CI; amd64 and arm64 | `build_image_digest` |
| `ghcr.io/omardev29/raylib-run-alpine` | `alpine/`; workflow `alpine-image.yaml` | the musl build, started on Alpine; amd64 only | `run_alpine_digest` |

The two workflows never rebuild each other: a change under `alpine/` publishes only the Alpine image, a change to the rest only the build image.

## What frozen means here

| Layer | Pinned by |
|---|---|
| The base | `ubuntu:24.04` by digest, the `UBUNTU_DIGEST` argument |
| Every apt package | every source rewritten to `snapshot.ubuntu.com` at `APT_SNAPSHOT`, so an install resolves to the same bytes on any day |
| Every download | a `sha256` beside its version: CMake, Ninja, zig, UPX, butler, actionlint, Mull, the Android command-line tools |
| Emscripten | emsdk fetched by commit, `EMSDK_COMMIT`, never by tag |
| The Python test tools | the hash lock ([Python](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html#lock)) |
| The Gradle home | warmed by building the framework at `GRADLE_WARM_COMMIT`, and proven offline before the image is published |

Every version is an `ARG` at the top of the `Dockerfile`: one place to bump. Rebuilding the same `Dockerfile` gives the same contents, but not the same digest — the image records when it was built — which does not matter, because the framework pins the digest of the one that was published and verified.

## The manifest

The image writes `/etc/raylib-build-image.json`: every pinned version, and the architecture. The versions of what came from apt or pip — LLVM, cppcheck, Mull, the Python test tools — are read from the installed tool, not copied from an argument, so the manifest says what is in the image. Every container job prints it first, so a red log says which toolchain produced it, and `tools/versions_check.sh`, run inside the image, compares it with the framework's `versions` block: a framework that asks for an SDK the image does not have fails there, not twenty minutes into Gradle.

## Checked before it is published

Two checks, and each has to do the job of the tool, not print its version:

- **The smoke check**, a step of the `Dockerfile` itself, invokes every tool a CI job invokes. From `smoke/` it builds, runs, merges and reports a profiled binary; makes cppcheck refuse an out-of-bounds write and accept clean C++20; has ASan, UBSan and LSan each stop the mistake it exists for; runs libFuzzer for a hundred runs; makes Mull report the one mutant `smoke/mull.c` leaves alive; and makes mutmut kill the one mutant only a Hypothesis property can kill. A broken image fails to build.
- **The verify script**, `verify/image.sh`, runs in the image that was just built, on a runner of its own architecture, and checks the manifest's architecture is the one asked for.

The architectures are not the same image: arm64 has no Android SDK, no riscv64 libraries, an empty Gradle home, and no actionlint or butler, because the NDK's host tools are x86-64 only and those jobs run on amd64. The manifest leaves those keys out on arm64 rather than fake them.

## How it is published

| Event in the image repository | What happens |
|---|---|
| A pull request | both architectures built and verified, nothing pushed |
| A manual run on a branch other than `main` | the same: built, verified, nothing pushed — not even `:latest`, which the canary floats to |
| A push to `main` that changes the `Dockerfile`, `python/`, `smoke/`, `verify/` or the workflow | each architecture built on a runner of its own (`ubuntu-24.04`, `ubuntu-24.04-arm`), pushed by digest, pulled back and verified at that digest; then one job makes the multi-architecture list of the two, checks it holds exactly those two, tags it with the commit, only then moves `:latest`, and writes the list's digest to the run's summary |

The layer cache goes to a registry tag, `:buildcache`, not to the Actions cache: the image is around ten gigabytes, past what a repository's Actions cache holds. Both packages must stay public: the framework's jobs, and the jobs of every game made from it, pull them with their own token.

## A bump, step by step

Any change to the image — a newer tool, a new package, a newer snapshot — goes the same way.

1. **In the image repository**, change the `ARG` (and its `sha256`), on a branch. For a new apt package, add it to the install list; for a new snapshot, change `APT_SNAPSHOT`, and check the two Python pins apt owns ([the lock](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html#lock)).
2. **Build it on the branch** with a manual run: both architectures built and verified, nothing published. Or build it locally:
   ```shell
   docker build -t raylib-build .
   docker run --rm -e EXPECT_ARCH=amd64 -v "$PWD/verify:/verify:ro" raylib-build bash -l /verify/image.sh
   ```
3. **Try the framework in it before publishing**: in a checkout of the framework, the whole ladder in the local image ([a checkout of its own](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#a-checkout-for-the-image)), with `tools/versions_check.sh` told nothing yet — it will report the drift you are about to fix, which proves it is reading the new manifest.
4. **Merge to the image repository's `main`**. The workflow publishes, and the summary of that run gives the list's digest. Never pin `:latest`; never pin the digest of one architecture's image.
5. **In the framework**, on a branch, replace the digest everywhere it is written and change every key that moved:
   ```shell
   OLD=$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
   NEW=sha256:...    # from the image run's summary
   grep -rl "$OLD" .github/workflows thirdparty/FROZEN_VERSIONS.md | xargs sed -i "s/$OLD/$NEW/g"
   bash tools/versions_check.sh
   ```
   The digest is in `ci.yml` (`PINNED_IMAGE`), in `web-backends.yml`, three times in `deep.yml` — a job's `container:` cannot read a variable — and in `thirdparty/FROZEN_VERSIONS.md`; `tools/versions_check.sh` fails while any two disagree. This site follows by itself: its CI reads the image from the framework's `ci.yml` at `FRAMEWORK_REF`.
6. **Run what the image is exact about**, in the new image: `rmp test`, `rmp test examples`, `rmp test coverage`, and the size lines from a release build. [What moves](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#after) says what to expect.
7. **The pull request** says what moved in the image, what moved in the framework because of it, and what was re-recorded. Once the image repository's verify workflow is green on both architectures, the pull request that pins an image a card of the plan builds merges on a review by an agent that did not write it (`CLAUDE.md`, "What does not wait for him").

### The Android bump: two repositories, in order

The image's Gradle home is warmed by building the framework's Android project at `GRADLE_WARM_COMMIT`, and the Android job builds offline from it. So a change to Gradle, AGP, the SDK levels or AdMob's version needs a framework commit that the image is built from, and an image the framework then pins:

1. In the framework, on a branch: the new set in `raymob/app/build.gradle`, `raymob/build.gradle` and `raymob/gradle/wrapper/gradle-wrapper.properties` (with the wrapper's `sha256`), and the same values in the `versions` block. Push it. The Android job of that branch fails offline, because the image does not have the new dependencies yet; that is expected.
2. In the image repository: `GRADLE_WARM_COMMIT` set to that commit, and the SDK, NDK and build tools arguments set to the same values. The build warms the home from it, with AdMob on and off, and proves both builds offline from a clean tree before it can publish.
3. Publish, take the digest, and pin it on the same framework branch. Its Android job is green now, and `tools/versions_check.sh` holds the framework's Gradle files, its `versions` block and the image's manifest to one set.

The warm commit has to stay fetchable for as long as anyone may rebuild the image: the build fetches it from the framework's repository by its full hash. A commit a pull request carries stays reachable on GitHub through the pull request's own ref, even after its branch is deleted; a commit of a branch pushed without one, and then deleted or rewritten, does not. Open the pull request before the image is built, or point the next image's warm commit at the merged commit on `main`.

### The LLVM bump

LLVM is held where it is by Mull, which is built for one LLVM release and refused by the image for any other (`MULL_LLVM_VERSION`). Moving LLVM means a Mull for it, and the `-18` in the names of the tools the `Dockerfile`, the manifest step and the framework's coverage and mutation scripts call — `llvm-config-18`, `mull-runner-18`, the clang plugin's path. If no Mull exists for the LLVM wanted, the choice is between keeping LLVM and dropping mutation of the C++ from the image; that is Omar's.

### A new Ubuntu

The largest bump: the base digest, the snapshot, the package names that changed between releases, the two Python pins apt owns, the system compilers, and the `ubuntu` key — which the manifest step writes as a literal, not from an argument. The image's Python moves with it, so the lock is regenerated. Do it alone, in its own pull request, with a full matrix after.

## What moves in the framework after a bump

| Changed in the image | What can go red | What to do |
|---|---|---|
| GCC or Clang | new warnings (the framework builds its checks with warnings as errors); the e2e shots and the render hash, if the code generation changed a float | fix the warning in the code; a moved shot is re-recorded in the image with `rmp test e2e-update`, every picture looked at, and a moved golden needs `behaviour-approved` |
| zig, UPX, any compiler | the size budget, past 1.5 % a warning and past 10 % a failure | the new lines from the release run, `tools/size_check.py --update`, with the reason in the pull request |
| GCC's headers | the cost of each public header, `tools/header_budget.txt` | the new numbers from `tools/header_cost.py`, run in the image |
| LLVM | the coverage floors (another release counts lines differently) and the mutation floors | raise with `tools/coverage_check.sh --update`; a floor that has to come down is a hand edit a reviewer reads, never a script's |
| clang-format, clang-tidy | files that were formatted, warnings nobody owed | [their own bump](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#clang-tools) |
| Emscripten | the web build, its size line, the web boot test | a full web run, and the web size line |
| The Android set | the Android build, offline | [the Android bump](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump) |
| The apt snapshot | any of the above at once | a snapshot bump is every package's bump: do it alone |

## The Alpine run image

The musl build is started on Alpine, twice: the headless build, which renders the golden frame, and the archive a player downloads, under `xvfb-run` on Mesa's llvmpipe. The image is Alpine by digest with exactly those packages and nothing else — no compiler, no Python — and a small GLX program, built against the same Alpine, that opens every library GLFW opens, makes a context, insists the renderer is llvmpipe and reads two drawn pixels back. The build runs it, and `alpine/verify/image.sh` runs it again on the built image, with `--init` and no network as the framework runs it, before anything is published.

Its packages are not pinned to versions, because Alpine keeps one version per package per release branch and deletes the one it replaces; there is no snapshot service to point at. What CI runs is frozen by the digest. A rebuild installs whatever its branch has that day, and the image's `/etc/raylib-run-alpine.json` lists every installed package with its version, so two builds can be compared line by line.

It is pinned in two places, `RUN_IMAGE` in `_linux.yml`'s `musl-x64-run` job and `run_alpine_digest` in `thirdparty/FROZEN_VERSIONS.md`, and `tools/versions_check.sh` fails while they disagree. A bump is a push to `alpine/` on the image repository's `main`, which builds it, verifies it at its digest and only then tags it. Locally:

```shell
docker build -t raylib-run-alpine alpine/
docker run --rm --init --network none -e EXPECT_ARCH=amd64 \
    -v "$PWD/alpine/verify:/verify:ro" raylib-run-alpine sh /verify/image.sh
```

When the Alpine release it is built on stops getting fixes, move the base to a newer release by digest, and run the musl jobs; nothing else depends on which Alpine it is.

## Keep a copy

The published image is the toolchain. Rebuilding it depends on a dozen outside addresses still serving the same bytes — the Ubuntu snapshot above all — and some of them will not, one day. Keep every digest the framework has pinned in a place of your own: [Ten years and more](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html#archive) has the commands.
