Skip to content

build(images): slim the Postgres image and build each platform natively - #248

Merged
vishr merged 4 commits into
mainfrom
build/optimize-images
Nov 29, 2026
Merged

vishr merged 4 commits into
mainfrom
build/optimize-images

Conversation

@vishr

@vishr vishr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

What this changes

Postgres image (build/package/postgres.Dockerfile)

  • Fixes a broken build. apt.postgresql.org no longer serves the pinned postgis, pg_cron, pg_repack and hypopg versions, so main cannot rebuild the image today. Every extension moves to its current pgdg package:
    • postgis 3.6.4 → 3.7.0
    • pg_cron 1.6.7 → 1.6.8
    • pgaudit 18.0 → 18.1
    • pg_partman 5.5.0 → 5.5.1
    • hypopg 1.4.3 → 1.4.5
    • PostgreSQL 18.6 → 18.7, from the new base image
  • Pins postgres:18-trixie and debian:trixie-slim by digest.
  • Compiles pgvector in its own stage and does all downloads in a fetch stage. The final image no longer contains binutils, dpkg-dev, cpp, libcrypt-dev, curl or unzip, which saves about 19 MB on disk. Upstream GDAL 3.9 grew by about the same amount, so the net size change is close to zero (amd64 adds 276 MB over the base instead of 278 MB).
  • Bind-mounts the pgvectorscale .deb instead of copying it, so no layer contains it.
  • Installs ca-certificates explicitly. The old image had it only because the build step happened to install it, and WAL-G needs it for TLS to object storage.

Postgres workflow

  • Builds each platform on a native runner (ubuntu-24.04 and ubuntu-24.04-arm) instead of compiling arm64 under QEMU.
  • Caches build layers per platform.
  • Each runner pushes a per-platform candidate tag and verifies that exact image. The 18 tag moves only after both platforms pass. The image is now built once instead of twice (verify and publish).
  • New checks fail the build if build tools leak into the final image or the CA bundle is missing.

Discovery image

  • Removes QEMU from discovery-image.yml and release.yml. The Go stage cross-compiles on the build platform and the scratch stage runs no commands, so nothing needs emulation.
  • Adds a build cache on main. Releases reuse that cache.
  • Adds a Go build cache mount, which speeds up local rebuilds.

Weekly pin bump (postgres-image-bump.yml)

  • With the pins, minor releases and Debian security fixes no longer arrive on their own. Every Monday, build/package/postgres-bump.sh moves both base images to their tag's current digest and each pgdg package to its newest build.
  • The workflow builds both platforms on native runners and runs the same smoke test as the publish workflow, now shared as build/package/postgres-verify.sh. Then it opens or updates a pull request from bot/postgres-image-bump.
  • WAL-G, pgvector and pgvectorscale are still bumped by hand, because they are pinned by checksum or commit.
  • PRs opened with GITHUB_TOKEN start no workflows, so the required checks wouldn't run. Add a POSTGRES_BUMP_TOKEN secret (a fine-grained token with contents and pull-requests write) to fix that. Without it, the PR body says to close and reopen the PR.
  • The CLA allowlist gains github-actions[bot], which authors the bump commits.

Why this is correct

  • Both platforms build locally. The workflow's extension check passes on arm64 natively and on amd64 under emulation. It creates every extension, builds a diskann index and a GiST index, runs pg_cron and hypopg, and runs wal-g --version.
  • Upgrade in place: I started a cluster with the published onebox-postgres:18, created all extensions, and added data with spatial and vector indexes. Then I started the new image on the same volume. Queries returned correct results before any ALTER EXTENSION. postgis_extensions_upgrade() and ALTER EXTENSION … UPDATE for pgaudit, pg_partman and hypopg all succeeded.
  • I compared package lists against the pinned base image to confirm which packages were removed.
  • just check passes. actionlint passes; shellcheck ran separately on the verify script, the bump script, and every workflow run block.
  • Bump script: no changes against current pins; with a stale digest and an old postgis pin, it restored both to the current values.
  • The bump workflow can first run only after merge (workflow_dispatch needs the file on main).

The native arm64 runner and the merge step run only on main, so their first real run happens after merge.

Effect on the safety envelope

After merge, the workflow republishes ghcr.io/labstack/onebox-postgres:18. Each host picks up the new image on its next pull, which restarts Postgres: brief database downtime for each app. Existing databases keep their current extension versions until someone runs ALTER EXTENSION … UPDATE; Onebox never runs it. Merge at a quiet time, then check on goal and monk that Postgres starts and WAL archiving works (pg_stat_archiver). No change to ob behaviour or to the capabilities reference.

Checklist

  • just check passes locally.
  • Tests cover the new behaviour, including the failure paths. (No Go changes. The verify step in the workflow is the test.)
  • Generated documentation is current (just check verifies this).
  • I have accepted the CLA, or will when the bot asks on my first pull request.

🤖 Generated with Claude Code

vishr and others added 4 commits November 29, 2026 05:52
The Postgres image no longer builds from main: apt.postgresql.org has
dropped the pinned postgis, pg_cron, pg_repack, and hypopg versions.
Move every extension to its current pgdg package and pin both base
images by digest, so later rebuilds are reproducible.

pgvector now compiles in its own stage and downloads happen in a
separate fetch stage. The final image no longer carries binutils,
dpkg-dev, cpp, libcrypt-dev, curl, or unzip (about 19 MB). The
pgvectorscale package is bind-mounted rather than copied.
ca-certificates is installed explicitly: the old image had it only
as a side effect of the build step, and WAL-G needs it for TLS.

The Postgres workflow builds each platform on a native runner instead
of compiling arm64 under QEMU, caches layers per platform, verifies
each pushed platform candidate, and moves the 18 tag only after both
pass. It also fails if build tools or the CA bundle regress.

The discovery image drops QEMU, which it never needed, and reuses the
gha layer cache from main in releases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Probe readiness over TCP. The entrypoint's init server listens only on
  the Unix socket, so a socket probe could pass before the real server
  started and psql then failed (2 of 3 local runs).
- Before promoting :18, assert the merged index holds exactly amd64 and
  arm64, each at the digest its own runner verified.
- Extend the build-tool guard to clang, llvm-config, and unzip.
- Declare PGVECTORSCALE_VERSION once, as a global ARG.
- Run the fetch stage on the build platform; it only downloads.
- Correct the comments: the digest pins do not make apt pins
  reproducible, pgvector's headers do ship, and PG_MAJOR must match the
  base image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pinning the base images by digest stopped PostgreSQL minor releases and
Debian security fixes from reaching hosts on their own, and pgdg drops
old extension builds, so the apt pins go stale too.

postgres-bump.sh moves POSTGRES_IMAGE and DEBIAN_IMAGE to their tag's
current digest and each pgdg package to the newest build the new base
offers. A weekly workflow runs it, pushes bot/postgres-image-bump,
builds and smoke-tests both platforms on native runners, and then opens
or updates the pull request. Merging it republishes onebox-postgres:18.

The smoke test moves to postgres-verify.sh so the publish and bump
workflows run the same checks. A pull request opened with GITHUB_TOKEN
starts no workflows, so the bump uses POSTGRES_BUMP_TOKEN when that
secret exists; otherwise the body says to close and reopen. The CLA
allowlist gains github-actions[bot], which authors the bump commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Push the bump to a per-run candidate branch and move the pull request
  branch only after both platforms pass, so an open pull request never
  carries unverified pins. A cleanup job deletes failed candidates.
- Move a package pin only to a build both amd64 and arm64 offer; pgdg
  can publish one architecture first.
- Fail loudly when apt-get update fails instead of reporting every
  package as missing.
- Refuse to run when PG_MAJOR does not match the POSTGRES_IMAGE tag.
- Always bump main, whatever ref dispatched the run.
- Read main's layer cache but never write it from an unmerged bump.
- Drop the unneeded buildx setup and extra fetch depth, note the repo
  setting the GITHUB_TOKEN fallback needs, and fix the Dockerfile
  comment on what republishes the image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishr
vishr merged commit 7acc9a7 into main Nov 29, 2026
6 checks passed
@vishr
vishr deleted the build/optimize-images branch November 29, 2026 14:29
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