Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
192 changes: 0 additions & 192 deletions .github/workflows/postgres-image-bump.yml

This file was deleted.

114 changes: 104 additions & 10 deletions .github/workflows/postgres-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,50 @@ 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: {}

# 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: 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 }}-${{ 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
Expand All @@ -32,8 +63,6 @@ jobs:
permissions:
contents: read
packages: write
env:
CANDIDATE: ghcr.io/labstack/onebox-postgres:18-${{ github.sha }}-${{ matrix.arch }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Expand All @@ -48,20 +77,28 @@ 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 }}
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
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
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
Expand All @@ -79,9 +116,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.
Expand All @@ -102,8 +139,65 @@ jobs:
fi
done

# 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 -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"
# 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

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'
grep -E '^[<>]' "$RUNNER_TEMP/diff.txt" | sed -e 's/^</-/' -e 's/^>/+/'
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
run: docker buildx imagetools create --tag ghcr.io/labstack/onebox-postgres:18 "ghcr.io/labstack/onebox-postgres:18-${GITHUB_SHA}"
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
env:
Expand Down
Loading
Loading