From 084ecb53d18c69761778d42515b2119ab215e9cc Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 07:05:05 -0800 Subject: [PATCH 1/2] build(postgres): rebuild weekly instead of bumping pins Exact apt pins go stale because apt.postgresql.org drops old builds, and keeping them current needed a bump script, a bot pull request, a token workaround, and a CLA exception. That is more machinery than a two-host alpha needs. Follow postgres:18-trixie and the current pgdg packages instead, and rebuild every Monday. Scheduled and manual runs skip the layer cache so package updates actually land, verify both platforms as before, and publish :18 only when the SBOM package list differs from the published image, so an unchanged rebuild never restarts Postgres on a host. The summary shows the package diff that replaces the bump pull request. Each run tags its images with the run ID, so a rebuild of the same commit never overwrites an earlier image and every publish stays a rollback target. Publishes now queue instead of cancelling each other. WAL-G, pgvector, and pgvectorscale stay pinned by checksum or commit. Remove postgres-bump.sh, postgres-image-bump.yml, and the github-actions[bot] CLA allowlist entry. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/cla.yml | 2 +- .github/workflows/postgres-image-bump.yml | 192 ---------------------- .github/workflows/postgres-image.yml | 67 +++++++- build/package/postgres-bump.sh | 119 -------------- build/package/postgres.Dockerfile | 41 ++--- 5 files changed, 77 insertions(+), 344 deletions(-) delete mode 100644 .github/workflows/postgres-image-bump.yml delete mode 100755 build/package/postgres-bump.sh diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index ce782cec..24eb4f46 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -36,4 +36,4 @@ jobs: # a bot commit into the release history and trigger a CI run every # time somebody signs. branch: cla-signatures - allowlist: vishr,dependabot[bot],github-actions[bot] + allowlist: vishr,dependabot[bot] diff --git a/.github/workflows/postgres-image-bump.yml b/.github/workflows/postgres-image-bump.yml deleted file mode 100644 index fad2035d..00000000 --- a/.github/workflows/postgres-image-bump.yml +++ /dev/null @@ -1,192 +0,0 @@ -name: PostgreSQL image pin bump - -# The Dockerfile pins its base images by digest and its pgdg extension -# packages by exact build, so security fixes and PostgreSQL minor releases -# arrive only through a pin bump. This opens that bump as a pull request each -# week, after both platforms build and pass the same smoke test the publish -# workflow runs. Merging it republishes onebox-postgres:18. -# -# Without POSTGRES_BUMP_TOKEN, opening the pull request relies on the repo -# setting "Allow GitHub Actions to create and approve pull requests". -on: - schedule: - - cron: "0 5 * * 1" - workflow_dispatch: - -permissions: {} - -concurrency: - group: postgres-image-bump - cancel-in-progress: true - -env: - BRANCH: bot/postgres-image-bump - -jobs: - bump: - name: Refresh pins - runs-on: ubuntu-24.04 - permissions: - contents: write - outputs: - changed: ${{ steps.bump.outputs.changed }} - sha: ${{ steps.commit.outputs.sha }} - candidate: ${{ steps.commit.outputs.candidate }} - steps: - # A pull request opened or pushed with GITHUB_TOKEN starts no workflows, - # so the required checks never run on it. With POSTGRES_BUMP_TOKEN (a - # fine-grained token with contents and pull-requests write on this repo) - # they run as usual; without it, close and reopen the pull request. - # Always bump main, whatever ref dispatched the run: the pull request - # targets main and must carry nothing but the bump. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: main - token: ${{ secrets.POSTGRES_BUMP_TOKEN || secrets.GITHUB_TOKEN }} - - # The script asks an arm64 container which pgdg builds it sees. - - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - - - name: Bump pins - id: bump - run: | - set -euo pipefail - build/package/postgres-bump.sh | tee "$RUNNER_TEMP/changes.txt" - if git diff --quiet; then - echo "changed=false" >> "$GITHUB_OUTPUT" - echo "All pins are current." >> "$GITHUB_STEP_SUMMARY" - else - echo "changed=true" >> "$GITHUB_OUTPUT" - { echo '```'; cat "$RUNNER_TEMP/changes.txt"; echo '```'; } >> "$GITHUB_STEP_SUMMARY" - fi - - # The candidate lives on a per-run branch. The pull request branch moves - # to it only after both platforms pass, so an open pull request never - # carries unverified pins. - - name: Push candidate branch - id: commit - if: steps.bump.outputs.changed == 'true' - run: | - set -euo pipefail - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - candidate="$BRANCH-candidate-$GITHUB_RUN_ID" - git switch -c "$candidate" - { - echo "build(postgres): bump image pins" - echo - cat "$RUNNER_TEMP/changes.txt" - } > "$RUNNER_TEMP/message.txt" - git commit -q -a -F "$RUNNER_TEMP/message.txt" - git push origin "$candidate" - echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - echo "candidate=$candidate" >> "$GITHUB_OUTPUT" - - verify: - name: Verify bump (${{ matrix.arch }}) - needs: bump - if: needs.bump.outputs.changed == 'true' - runs-on: ${{ matrix.runner }} - strategy: - fail-fast: true - matrix: - include: - - arch: amd64 - runner: ubuntu-24.04 - - arch: arm64 - runner: ubuntu-24.04-arm - permissions: - contents: read - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.bump.outputs.sha }} - - - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - - - name: Build bumped image - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 - with: - context: . - file: build/package/postgres.Dockerfile - platforms: linux/${{ matrix.arch }} - load: true - tags: onebox-postgres:bump - # Read main's cache but never write it: an unmerged bump must not - # replace the layers the published pins depend on. - cache-from: type=gha,scope=onebox-postgres-${{ matrix.arch }} - - - name: Verify bumped image - run: build/package/postgres-verify.sh onebox-postgres:bump - - pull-request: - name: Open or update pull request - needs: [bump, verify] - runs-on: ubuntu-24.04 - permissions: - contents: write - pull-requests: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.bump.outputs.sha }} - token: ${{ secrets.POSTGRES_BUMP_TOKEN || secrets.GITHUB_TOKEN }} - - - name: Move pull request branch to the verified commit - env: - CANDIDATE: ${{ needs.bump.outputs.candidate }} - run: | - set -euo pipefail - git push -f origin "HEAD:refs/heads/$BRANCH" - git push origin --delete "$CANDIDATE" - - - name: Open or update pull request - env: - GH_TOKEN: ${{ secrets.POSTGRES_BUMP_TOKEN || secrets.GITHUB_TOKEN }} - HAS_BUMP_TOKEN: ${{ secrets.POSTGRES_BUMP_TOKEN != '' }} - run: | - set -euo pipefail - { - echo "## What this changes" - echo - echo "The weekly pin refresh found newer builds:" - echo - echo '```' - git log -1 --format=%b - echo '```' - echo - echo "## Why this is correct" - echo - echo "Both platforms built from this commit and passed \`build/package/postgres-verify.sh\` on native runners." - echo - echo "## Effect on the safety envelope" - echo - echo "Merging republishes \`ghcr.io/labstack/onebox-postgres:18\`. Each host picks it up on its next pull, which restarts Postgres. Existing databases keep their extension versions until \`ALTER EXTENSION ... UPDATE\` runs. Merge at a quiet time and check that Postgres starts and WAL archiving works on each host afterward." - if [ "$HAS_BUMP_TOKEN" != true ]; then - echo - echo "> [!NOTE]" - echo "> This pull request was opened with \`GITHUB_TOKEN\`, which starts no workflows. Close and reopen it to run the required checks." - fi - } > "$RUNNER_TEMP/body.md" - number=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number // empty') - if [ -n "$number" ]; then - gh pr edit "$number" --body-file "$RUNNER_TEMP/body.md" - else - gh pr create --base main --head "$BRANCH" \ - --title "build(postgres): bump image pins" \ - --body-file "$RUNNER_TEMP/body.md" - fi - - cleanup: - name: Delete unverified candidate - needs: [bump, verify] - if: always() && needs.bump.outputs.candidate != '' && needs.verify.result != 'success' - runs-on: ubuntu-24.04 - permissions: - contents: write - steps: - - name: Delete candidate branch - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CANDIDATE: ${{ needs.bump.outputs.candidate }} - run: gh api -X DELETE "repos/$GITHUB_REPOSITORY/git/refs/heads/$CANDIDATE" diff --git a/.github/workflows/postgres-image.yml b/.github/workflows/postgres-image.yml index e5640323..3569e17b 100644 --- a/.github/workflows/postgres-image.yml +++ b/.github/workflows/postgres-image.yml @@ -7,13 +7,24 @@ on: - build/package/postgres.Dockerfile - build/package/postgres-verify.sh - .github/workflows/postgres-image.yml + # Weekly rebuild: the base image and pgdg packages are unpinned, so this is + # how PostgreSQL minor releases and security fixes reach hosts. + schedule: + - cron: "0 5 * * 1" workflow_dispatch: permissions: {} +# Publishes queue rather than cancel each other partway. concurrency: group: postgres-18-image - cancel-in-progress: true + cancel-in-progress: false + +env: + IMAGE: ghcr.io/labstack/onebox-postgres + # Every run gets its own tags, so a weekly rebuild of the same commit never + # overwrites an earlier image and each one stays a rollback target. + RUN_TAG: 18-${{ github.sha }}-${{ github.run_id }} jobs: platform: @@ -33,7 +44,7 @@ jobs: contents: read packages: write env: - CANDIDATE: ghcr.io/labstack/onebox-postgres:18-${{ github.sha }}-${{ matrix.arch }} + ARCH: ${{ matrix.arch }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -48,20 +59,27 @@ jobs: # The per-platform tag is a candidate only. Hosts pull # onebox-postgres:18, which the merge job moves after both platforms pass. - name: Build and publish platform candidate + id: build uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: context: . file: build/package/postgres.Dockerfile platforms: linux/${{ matrix.arch }} push: true - tags: ${{ env.CANDIDATE }} + tags: ${{ env.IMAGE }}:${{ env.RUN_TAG }}-${{ matrix.arch }} provenance: mode=max sbom: true + # A cached apt layer would hide every package update, so only a push + # (a Dockerfile change) reuses the cache. Scheduled and manual runs + # rebuild from scratch and still refresh the cache for the next push. + no-cache: ${{ github.event_name != 'push' }} cache-from: type=gha,scope=onebox-postgres-${{ matrix.arch }} cache-to: type=gha,mode=max,scope=onebox-postgres-${{ matrix.arch }} - name: Verify exact published platform image - run: build/package/postgres-verify.sh "$CANDIDATE" + env: + DIGEST: ${{ steps.build.outputs.digest }} + run: build/package/postgres-verify.sh "$IMAGE@$DIGEST" publish: name: Publish PostgreSQL 18 image @@ -79,9 +97,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Merge verified platforms into commit-addressed candidate + - name: Merge verified platforms into run-addressed candidate run: | - candidate="ghcr.io/labstack/onebox-postgres:18-${GITHUB_SHA}" + candidate="$IMAGE:$RUN_TAG" docker buildx imagetools create --tag "$candidate" "${candidate}-amd64" "${candidate}-arm64" # Promote only an index holding exactly the two verified platforms, # each at the digest its own runner tested. @@ -102,8 +120,43 @@ jobs: fi done + # The SBOM lists every installed package and version per platform. A + # scheduled rebuild that changed none of them is not published: a new + # digest alone would restart Postgres on every host for nothing. + - name: Compare packages with the published image + id: compare + run: | + set -euo pipefail + packages() { + docker buildx imagetools inspect "$1" --format '{{json .SBOM}}' | + jq -r 'to_entries[] | .key as $platform | .value.SPDX.packages[] | "\($platform) \(.name) \(.versionInfo)"' | + sort -u + } + packages "$IMAGE:$RUN_TAG" > "$RUNNER_TEMP/new.txt" + if ! packages "$IMAGE:18" > "$RUNNER_TEMP/old.txt"; then + : > "$RUNNER_TEMP/old.txt" + fi + if [ ! -s "$RUNNER_TEMP/new.txt" ]; then + echo "::error::$IMAGE:$RUN_TAG has no SBOM package list" + exit 1 + fi + if diff "$RUNNER_TEMP/old.txt" "$RUNNER_TEMP/new.txt" > "$RUNNER_TEMP/diff.txt"; then + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "No package changed since the published $IMAGE:18." >> "$GITHUB_STEP_SUMMARY" + else + echo "changed=true" >> "$GITHUB_OUTPUT" + { + echo "Package changes since the published $IMAGE:18:" + echo + echo '```diff' + grep -E '^[<>]' "$RUNNER_TEMP/diff.txt" | sed -e 's/^/+/' + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + fi + - name: Promote tested manifest to PostgreSQL 18 - run: docker buildx imagetools create --tag ghcr.io/labstack/onebox-postgres:18 "ghcr.io/labstack/onebox-postgres:18-${GITHUB_SHA}" + if: github.event_name != 'schedule' || steps.compare.outputs.changed == 'true' + run: docker buildx imagetools create --tag "$IMAGE:18" "$IMAGE:$RUN_TAG" - name: Verify public anonymous access env: diff --git a/build/package/postgres-bump.sh b/build/package/postgres-bump.sh deleted file mode 100755 index 31d8e02e..00000000 --- a/build/package/postgres-bump.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -# Refresh the pins in the onebox-postgres Dockerfile in place: -# - POSTGRES_IMAGE and DEBIAN_IMAGE move to the digest their tag points at now. -# - Each pgdg extension package moves to the newest build apt.postgresql.org -# offers for the new base image. -# WAL-G, pgvector, and pgvectorscale are pinned by checksum or commit and stay -# as they are; bump those by hand. Prints one line per changed pin. -# Usage: build/package/postgres-bump.sh [DOCKERFILE] -set -euo pipefail - -dockerfile=${1:-build/package/postgres.Dockerfile} - -arg_value() { - sed -n "s/^ARG $1=//p" "$dockerfile" -} - -set_arg() { - local name=$1 new=$2 old - old=$(arg_value "$name") - if [ -z "$old" ]; then - echo "ARG $name not found in $dockerfile" >&2 - exit 1 - fi - if [ "$old" != "$new" ]; then - # '|' delimits: image references and Debian versions never contain it. - sed -i.bak "s|^ARG $name=.*|ARG $name=$new|" "$dockerfile" - rm -f "$dockerfile.bak" - echo "$name: $old -> $new" - fi -} - -bump_image() { - local name=$1 ref tag digest - ref=$(arg_value "$name") - tag=${ref%@*} - digest=$(docker buildx imagetools inspect "$tag" --format '{{json .Manifest}}' | jq -r .digest) - case "$digest" in - sha256:*) ;; - *) echo "could not resolve a digest for $tag" >&2; exit 1 ;; - esac - set_arg "$name" "$tag@$digest" -} - -bump_image POSTGRES_IMAGE -bump_image DEBIAN_IMAGE - -pg_major=$(arg_value PG_MAJOR) -postgres_image=$(arg_value POSTGRES_IMAGE) -case "$postgres_image" in - "postgres:$pg_major-"*) ;; - *) echo "PG_MAJOR=$pg_major does not match POSTGRES_IMAGE=$postgres_image" >&2; exit 1 ;; -esac -packages=( - "POSTGIS_PACKAGE_VERSION=postgresql-$pg_major-postgis-3" - "PG_CRON_PACKAGE_VERSION=postgresql-$pg_major-cron" - "PGAUDIT_PACKAGE_VERSION=postgresql-$pg_major-pgaudit" - "PG_REPACK_PACKAGE_VERSION=postgresql-$pg_major-repack" - "PG_PARTMAN_PACKAGE_VERSION=postgresql-$pg_major-partman" - "HYPOPG_PACKAGE_VERSION=postgresql-$pg_major-hypopg" -) -names=() -for entry in "${packages[@]}"; do - names+=("${entry#*=}") -done - -# Ask the new base image, once per published platform, which builds its pgdg -# source offers now. pgdg can publish a build for one architecture before the -# other, so a pin moves only to a version both offer. -# Each run uses the platform's own manifest digest: Docker's containerd image -# store refuses to pull one index digest for a second platform ("cannot -# overwrite digest"). The index is read once. -if ! index=$(docker buildx imagetools inspect "$postgres_image" --raw); then - echo "could not read the image index for $postgres_image" >&2 - exit 1 -fi -platform_digest() { - jq -er --arg arch "$1" \ - 'first(.manifests[]? | select(.platform.os == "linux" and .platform.architecture == $arch) | .digest)' \ - <<<"$index" -} -candidates() { - docker run --rm --platform "linux/$1" "${postgres_image%@*}@$2" sh -c ' - apt-get update -qq >/dev/null || { echo "apt-get update failed" >&2; exit 1; } - for package in "$@"; do - printf "%s %s\n" "$package" "$(apt-cache policy "$package" | sed -n "s/^ *Candidate: //p")" - done' sh "${names[@]}" -} -amd64="" -arm64="" -for arch in amd64 arm64; do - if ! digest=$(platform_digest "$arch"); then - echo "$postgres_image has no linux/$arch image" >&2 - exit 1 - fi - if ! result=$(candidates "$arch" "$digest"); then - echo "could not list pgdg candidates for linux/$arch" >&2 - exit 1 - fi - case "$arch" in - amd64) amd64=$result ;; - arm64) arm64=$result ;; - esac -done - -for entry in "${packages[@]}"; do - name=${entry%%=*} - package=${entry#*=} - version=$(printf '%s\n' "$amd64" | awk -v p="$package" '$1 == p { print $2 }') - other=$(printf '%s\n' "$arm64" | awk -v p="$package" '$1 == p { print $2 }') - if [ -z "$version" ] || [ "$version" = "(none)" ]; then - echo "no candidate for $package" >&2 - exit 1 - fi - if [ "$version" != "$other" ]; then - echo "$package: amd64 offers $version, arm64 offers ${other:-nothing}; keeping the current pin" >&2 - continue - fi - set_arg "$name" "$version" -done diff --git a/build/package/postgres.Dockerfile b/build/package/postgres.Dockerfile index 126ed6ec..9c729a8f 100644 --- a/build/package/postgres.Dockerfile +++ b/build/package/postgres.Dockerfile @@ -3,21 +3,18 @@ # PG_MAJOR must match the major version in POSTGRES_IMAGE; change both together. ARG PG_MAJOR=18 ARG PGVECTORSCALE_VERSION=0.9.0 -# Digest pins fix the base images, so PostgreSQL minor releases and Debian -# security updates arrive only by bumping these digests. The pgdg extension -# packages below are pinned too, but apt.postgresql.org keeps only recent -# builds: a rebuild without a warm layer cache fails once a pinned version -# leaves the index, and the fix is to bump that pin. -# .github/workflows/postgres-image-bump.yml refreshes these pins weekly in a -# pull request; merging it, or any change to this file or postgres-verify.sh, -# republishes the image. -ARG POSTGRES_IMAGE=postgres:18-trixie@sha256:64c8b0d31e4ab6ea665e8426ea406a94bf52de3c05b3a4a8bf713704eefa9328 -ARG DEBIAN_IMAGE=debian:trixie-slim@sha256:8aa5a7bf5a1955bddbe7d74fcdd0b91ab30e74362a8b73af672b0481b35b44a0 +# The base images and the pgdg extension packages follow their current +# releases on purpose. .github/workflows/postgres-image.yml rebuilds weekly +# without the layer cache, verifies both platforms, and publishes only when the +# installed packages changed, so PostgreSQL minor releases and Debian security +# fixes arrive without anyone bumping a pin. Only the downloads Onebox must +# trust (WAL-G, pgvector, pgvectorscale) are pinned, by checksum or commit. +ARG POSTGRES_IMAGE=postgres:18-trixie +ARG DEBIAN_IMAGE=debian:trixie-slim # Downloads and checksum checks run here so curl and unzip never enter the -# final image. -# The stage only downloads and checksums, so it runs on the build platform and -# never needs emulation. TARGETARCH still selects the assets. +# final image. The stage runs on the build platform and never needs emulation; +# TARGETARCH still selects the assets. FROM --platform=$BUILDPLATFORM ${DEBIAN_IMAGE} AS fetch # The official releases have separate Linux binaries. This mapping is @@ -91,12 +88,6 @@ FROM ${POSTGRES_IMAGE} ARG PG_MAJOR ARG TARGETARCH ARG PGVECTORSCALE_VERSION -ARG POSTGIS_PACKAGE_VERSION=3.7.0+dfsg-2.pgdg13+1 -ARG PG_CRON_PACKAGE_VERSION=1.6.8-2.pgdg13+1 -ARG PGAUDIT_PACKAGE_VERSION=18.1-1.pgdg13+1 -ARG PG_REPACK_PACKAGE_VERSION=1.5.3-3.pgdg13+1 -ARG PG_PARTMAN_PACKAGE_VERSION=5.5.1-1.pgdg13+1 -ARG HYPOPG_PACKAGE_VERSION=1.4.5-2.pgdg13+1 LABEL org.opencontainers.image.source="https://github.com/labstack/onebox" \ org.opencontainers.image.description="PostgreSQL for Onebox-managed applications" \ @@ -114,12 +105,12 @@ RUN --mount=type=bind,from=fetch,source=/out/deb,target=/tmp/pgvectorscale \ apt-mark hold locales && \ apt-get install -y --no-install-recommends \ ca-certificates \ - postgresql-${PG_MAJOR}-postgis-3=${POSTGIS_PACKAGE_VERSION} \ - postgresql-${PG_MAJOR}-cron=${PG_CRON_PACKAGE_VERSION} \ - postgresql-${PG_MAJOR}-pgaudit=${PGAUDIT_PACKAGE_VERSION} \ - postgresql-${PG_MAJOR}-repack=${PG_REPACK_PACKAGE_VERSION} \ - postgresql-${PG_MAJOR}-partman=${PG_PARTMAN_PACKAGE_VERSION} \ - postgresql-${PG_MAJOR}-hypopg=${HYPOPG_PACKAGE_VERSION} \ + postgresql-${PG_MAJOR}-postgis-3 \ + postgresql-${PG_MAJOR}-cron \ + postgresql-${PG_MAJOR}-pgaudit \ + postgresql-${PG_MAJOR}-repack \ + postgresql-${PG_MAJOR}-partman \ + postgresql-${PG_MAJOR}-hypopg \ "/tmp/pgvectorscale/pgvectorscale-postgresql-${PG_MAJOR}_${PGVECTORSCALE_VERSION}-Linux_${TARGETARCH}.deb" && \ grep -Fqx "default_version = '${PGVECTORSCALE_VERSION}'" \ "/usr/share/postgresql/${PG_MAJOR}/extension/vectorscale.control" && \ From 3f99a9116ec6a82ef6c18779dc9f51c69a280d28 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 07:07:50 -0800 Subject: [PATCH 2/2] build(postgres): address review of the weekly rebuild - Resolve the postgres:18-trixie digest once and build both platforms on it, labelled with org.opencontainers.image.base.digest. - Count a changed base digest as a change, not only changed packages. - Refuse to publish when amd64 and arm64 differ in PostgreSQL or extension packages. - Fail closed when the published image's SBOM cannot be read. - Drop the layer cache: a cached apt layer hid updates and let a push roll packages back. Native builds take a few minutes. - Gate manual runs like scheduled ones; only a push always publishes. - Add run_attempt to the run tag so a re-run never overwrites an image that may already be promoted. - Correct the concurrency comment and drop an unused env variable. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/postgres-image.yml | 93 ++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/.github/workflows/postgres-image.yml b/.github/workflows/postgres-image.yml index 3569e17b..87efca7f 100644 --- a/.github/workflows/postgres-image.yml +++ b/.github/workflows/postgres-image.yml @@ -15,7 +15,8 @@ on: permissions: {} -# Publishes queue rather than cancel each other partway. +# A running publish is never cancelled partway. GitHub keeps at most one +# pending run per group, so a newer trigger replaces an older pending one. concurrency: group: postgres-18-image cancel-in-progress: false @@ -24,13 +25,32 @@ env: IMAGE: ghcr.io/labstack/onebox-postgres # Every run gets its own tags, so a weekly rebuild of the same commit never # overwrites an earlier image and each one stays a rollback target. - RUN_TAG: 18-${{ github.sha }}-${{ github.run_id }} + RUN_TAG: 18-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }} + BASE: postgres:18-trixie jobs: + # Both platforms must build on the same base. Resolving the tag once keeps a + # Docker Hub retag between the two builds from splitting the image. + base: + name: Resolve PostgreSQL base image + runs-on: ubuntu-24.04 + permissions: {} + outputs: + digest: ${{ steps.resolve.outputs.digest }} + steps: + - name: Resolve base digest + id: resolve + run: | + set -euo pipefail + digest=$(docker buildx imagetools inspect "$BASE" --format '{{json .Manifest}}' | jq -er .digest) + echo "digest=$digest" >> "$GITHUB_OUTPUT" + echo "Base: \`$BASE@$digest\`" >> "$GITHUB_STEP_SUMMARY" + platform: name: Build and verify PostgreSQL 18 (${{ matrix.arch }}) # Each platform builds on a native runner. Compiling pgvector under QEMU # was the slowest step of the old single-runner build. + needs: base runs-on: ${{ matrix.runner }} strategy: fail-fast: true @@ -43,8 +63,6 @@ jobs: permissions: contents: read packages: write - env: - ARCH: ${{ matrix.arch }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -67,14 +85,15 @@ jobs: platforms: linux/${{ matrix.arch }} push: true tags: ${{ env.IMAGE }}:${{ env.RUN_TAG }}-${{ matrix.arch }} + build-args: POSTGRES_IMAGE=${{ env.BASE }}@${{ needs.base.outputs.digest }} + labels: | + org.opencontainers.image.base.name=docker.io/library/${{ env.BASE }} + org.opencontainers.image.base.digest=${{ needs.base.outputs.digest }} provenance: mode=max sbom: true - # A cached apt layer would hide every package update, so only a push - # (a Dockerfile change) reuses the cache. Scheduled and manual runs - # rebuild from scratch and still refresh the cache for the next push. - no-cache: ${{ github.event_name != 'push' }} - cache-from: type=gha,scope=onebox-postgres-${{ matrix.arch }} - cache-to: type=gha,mode=max,scope=onebox-postgres-${{ matrix.arch }} + # No layer cache: a cached apt layer would hide package updates, or + # roll them back on a push. A native build takes a few minutes. + no-cache: true - name: Verify exact published platform image env: @@ -120,32 +139,50 @@ jobs: fi done - # The SBOM lists every installed package and version per platform. A - # scheduled rebuild that changed none of them is not published: a new - # digest alone would restart Postgres on every host for nothing. - - name: Compare packages with the published image + # The SBOM lists every installed package and version per platform. Only + # a push publishes unconditionally; scheduled and manual rebuilds publish + # when a package or the base image changed, since a new digest alone + # would restart Postgres on every host for nothing. + - name: Compare with the published image id: compare run: | set -euo pipefail packages() { docker buildx imagetools inspect "$1" --format '{{json .SBOM}}' | - jq -r 'to_entries[] | .key as $platform | .value.SPDX.packages[] | "\($platform) \(.name) \(.versionInfo)"' | + jq -er 'to_entries[] | .key as $platform | .value.SPDX.packages[] | "\($platform) \(.name) \(.versionInfo)"' | sort -u } + base_digest() { + docker buildx imagetools inspect "$1" --format '{{json .Image}}' | + jq -r '[.. | objects | .config?.Labels?["org.opencontainers.image.base.digest"]? // empty] | first // ""' + } packages "$IMAGE:$RUN_TAG" > "$RUNNER_TEMP/new.txt" - if ! packages "$IMAGE:18" > "$RUNNER_TEMP/old.txt"; then - : > "$RUNNER_TEMP/old.txt" - fi - if [ ! -s "$RUNNER_TEMP/new.txt" ]; then - echo "::error::$IMAGE:$RUN_TAG has no SBOM package list" + # Fail closed: a registry error must not read as "everything changed". + packages "$IMAGE:18" > "$RUNNER_TEMP/old.txt" + + # One index must not ship different PostgreSQL or extension builds per + # platform, for example when pgdg publishes one architecture first. + for arch in amd64 arm64; do + grep "^linux/$arch " "$RUNNER_TEMP/new.txt" | cut -d' ' -f2- | + grep -E '^(postgresql-|pgvectorscale-)' > "$RUNNER_TEMP/pg-$arch.txt" || true + done + if ! diff "$RUNNER_TEMP/pg-amd64.txt" "$RUNNER_TEMP/pg-arm64.txt" > "$RUNNER_TEMP/split.txt"; then + echo "::error::amd64 and arm64 differ in PostgreSQL packages; not publishing" + cat "$RUNNER_TEMP/split.txt" exit 1 fi - if diff "$RUNNER_TEMP/old.txt" "$RUNNER_TEMP/new.txt" > "$RUNNER_TEMP/diff.txt"; then - echo "changed=false" >> "$GITHUB_OUTPUT" - echo "No package changed since the published $IMAGE:18." >> "$GITHUB_STEP_SUMMARY" - else - echo "changed=true" >> "$GITHUB_OUTPUT" + + new_base=$(base_digest "$IMAGE:$RUN_TAG") + old_base=$(base_digest "$IMAGE:18") + changed=false + if [ "$new_base" != "$old_base" ]; then + changed=true + echo "Base image: \`${old_base:-unknown}\` → \`$new_base\`" >> "$GITHUB_STEP_SUMMARY" + fi + if ! diff "$RUNNER_TEMP/old.txt" "$RUNNER_TEMP/new.txt" > "$RUNNER_TEMP/diff.txt"; then + changed=true { + echo echo "Package changes since the published $IMAGE:18:" echo echo '```diff' @@ -153,9 +190,13 @@ jobs: echo '```' } >> "$GITHUB_STEP_SUMMARY" fi + if [ "$changed" = false ]; then + echo "No package or base image changed since the published $IMAGE:18." >> "$GITHUB_STEP_SUMMARY" + fi + echo "changed=$changed" >> "$GITHUB_OUTPUT" - name: Promote tested manifest to PostgreSQL 18 - if: github.event_name != 'schedule' || steps.compare.outputs.changed == 'true' + if: github.event_name == 'push' || steps.compare.outputs.changed == 'true' run: docker buildx imagetools create --tag "$IMAGE:18" "$IMAGE:$RUN_TAG" - name: Verify public anonymous access