From 52ec8f95b1c2a1d7e2b7eb058e2155aaf5652184 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 05:52:27 -0800 Subject: [PATCH 1/4] build(images): slim the Postgres image and build each platform natively 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 --- .github/workflows/discovery-image.yml | 6 +- .github/workflows/postgres-image.yml | 125 ++++++++---------- .github/workflows/release.yml | 5 +- build/package/onebox-discovery.Dockerfile | 5 +- build/package/postgres.Dockerfile | 150 ++++++++++++---------- 5 files changed, 140 insertions(+), 151 deletions(-) diff --git a/.github/workflows/discovery-image.yml b/.github/workflows/discovery-image.yml index ffe71e48..3a33c785 100644 --- a/.github/workflows/discovery-image.yml +++ b/.github/workflows/discovery-image.yml @@ -27,8 +27,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - + # No QEMU: the Go stage cross-compiles on the build platform and the + # scratch stage runs no commands, so no step executes foreign binaries. - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 @@ -43,6 +43,8 @@ jobs: context: . file: build/package/onebox-discovery.Dockerfile platforms: linux/amd64,linux/arm64 + cache-from: type=gha,scope=onebox-discovery + cache-to: type=gha,mode=max,scope=onebox-discovery push: true tags: ghcr.io/labstack/onebox-discovery:edge provenance: mode=max diff --git a/.github/workflows/postgres-image.yml b/.github/workflows/postgres-image.yml index c672cd96..2153a57e 100644 --- a/.github/workflows/postgres-image.yml +++ b/.github/workflows/postgres-image.yml @@ -15,43 +15,70 @@ concurrency: cancel-in-progress: true jobs: - verify: - name: Verify PostgreSQL 18 image - runs-on: ubuntu-24.04 + 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. + 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 + packages: write + env: + CANDIDATE: ghcr.io/labstack/onebox-postgres:18-${{ github.sha }}-${{ matrix.arch }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - - name: Build test image + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # 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 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: context: . file: build/package/postgres.Dockerfile - load: true - tags: onebox-postgres:test + platforms: linux/${{ matrix.arch }} + push: true + tags: ${{ env.CANDIDATE }} + 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 }} - - name: Verify bundled extensions + - name: Verify exact published platform image shell: bash run: | set -euo pipefail container=onebox-postgres-test trap 'docker rm -f "$container" >/dev/null 2>&1 || true' EXIT - docker run -d --name "$container" -e POSTGRES_PASSWORD=test onebox-postgres:test \ + docker run -d --name "$container" -e POSTGRES_PASSWORD=test "$CANDIDATE" \ -c shared_preload_libraries=pg_cron,pgaudit,pg_stat_statements \ -c cron.database_name=postgres \ -c cron.use_background_workers=on - for attempt in $(seq 1 30); do + for attempt in $(seq 1 60); do if docker exec "$container" pg_isready -U postgres -d postgres >/dev/null 2>&1; then break fi - if [ "$attempt" -eq 30 ]; then + if [ "$attempt" -eq 60 ]; then docker logs "$container" exit 1 fi sleep 1 done - docker run --rm onebox-postgres:test wal-g --version docker exec "$container" psql -U postgres -d postgres -v ON_ERROR_STOP=1 \ -c 'CREATE EXTENSION vector' \ -c 'CREATE EXTENSION vectorscale' \ @@ -76,19 +103,23 @@ jobs: -c "SELECT indexrelid IS NOT NULL FROM hypopg_create_index('CREATE INDEX ON onebox_hypopg(id)')" \ -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('vector', 'vectorscale', 'postgis', 'pg_cron', 'pgaudit', 'pg_repack', 'pg_partman', 'hypopg', 'pg_stat_statements') ORDER BY extname" docker exec "$container" pg_repack --version + docker exec "$container" wal-g --version + # WAL-G reaches object storage over TLS and needs the CA bundle. + docker exec "$container" test -s /etc/ssl/certs/ca-certificates.crt + # Build tools belong to the pgvector-build stage only. + if docker exec "$container" sh -c 'command -v gcc || command -v cc || command -v make || command -v ld || command -v curl'; then + echo "::error::build tools leaked into the final image" + exit 1 + fi publish: name: Publish PostgreSQL 18 image - needs: verify + needs: platform runs-on: ubuntu-24.04 permissions: contents: read packages: write steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 @@ -97,67 +128,11 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and publish commit-addressed candidate - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 - with: - context: . - file: build/package/postgres.Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ghcr.io/labstack/onebox-postgres:18-${{ github.sha }} - provenance: mode=max - sbom: true - - - name: Verify exact published platform images - shell: bash + - name: Merge verified platforms into commit-addressed candidate run: | - set -euo pipefail candidate="ghcr.io/labstack/onebox-postgres:18-${GITHUB_SHA}" - for platform in linux/amd64 linux/arm64; do - architecture="${platform#linux/}" - container="onebox-postgres-${architecture}" - trap 'docker rm -f "$container" >/dev/null 2>&1 || true' EXIT - docker run -d --platform "$platform" --name "$container" -e POSTGRES_PASSWORD=test "$candidate" \ - -c shared_preload_libraries=pg_cron,pgaudit,pg_stat_statements \ - -c cron.database_name=postgres \ - -c cron.use_background_workers=on - for attempt in $(seq 1 60); do - if docker exec "$container" pg_isready -U postgres -d postgres >/dev/null 2>&1; then - break - fi - if [ "$attempt" -eq 60 ]; then - docker logs "$container" - exit 1 - fi - sleep 1 - done - docker exec "$container" psql -U postgres -d postgres -v ON_ERROR_STOP=1 \ - -c 'CREATE EXTENSION vector' \ - -c 'CREATE EXTENSION vectorscale' \ - -c 'CREATE EXTENSION postgis' \ - -c 'CREATE EXTENSION pg_cron' \ - -c 'CREATE EXTENSION pgaudit' \ - -c 'CREATE EXTENSION pg_repack' \ - -c 'CREATE EXTENSION pg_partman' \ - -c 'CREATE EXTENSION hypopg' \ - -c 'CREATE EXTENSION pg_stat_statements' \ - -c "SELECT '[1,2,3]'::vector <-> '[1,2,4]'::vector" \ - -c 'CREATE TABLE onebox_vectorscale(id bigint, embedding vector(3))' \ - -c "INSERT INTO onebox_vectorscale VALUES (1, '[1,2,3]'), (2, '[4,5,6]'), (3, '[7,8,9]')" \ - -c 'CREATE INDEX onebox_vectorscale_diskann ON onebox_vectorscale USING diskann (embedding vector_l2_ops)' \ - -c "SELECT indexdef FROM pg_indexes WHERE indexname = 'onebox_vectorscale_diskann'" \ - -c 'SET enable_seqscan = off' \ - -c "SELECT id FROM onebox_vectorscale ORDER BY embedding <-> '[1,2,3]' LIMIT 1" \ - -c "SELECT ST_AsText(ST_Point(1, 2))" \ - -c "SELECT cron.schedule('onebox-smoke', '0 0 * * *', 'SELECT 1')" \ - -c "SELECT cron.unschedule('onebox-smoke')" \ - -c 'CREATE TABLE onebox_hypopg(id bigint)' \ - -c "SELECT indexrelid IS NOT NULL FROM hypopg_create_index('CREATE INDEX ON onebox_hypopg(id)')" - docker exec "$container" pg_repack --version - docker exec "$container" wal-g --version - docker rm -f "$container" - trap - EXIT - done + docker buildx imagetools create --tag "$candidate" "${candidate}-amd64" "${candidate}-arm64" + docker buildx imagetools inspect "$candidate" - 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}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a7f9dce0..ac3c9af3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -116,8 +116,8 @@ jobs: fi docker manifest inspect ghcr.io/labstack/onebox-postgres:18 >/dev/null - - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - + # No QEMU: the Go stage cross-compiles on the build platform and the + # scratch stage runs no commands, so no step executes foreign binaries. - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 @@ -134,6 +134,7 @@ jobs: context: . file: build/package/onebox-discovery.Dockerfile platforms: linux/amd64,linux/arm64 + cache-from: type=gha,scope=onebox-discovery push: true tags: ghcr.io/labstack/onebox-discovery:${{ github.ref_name }} provenance: mode=max diff --git a/build/package/onebox-discovery.Dockerfile b/build/package/onebox-discovery.Dockerfile index 2635892b..c357054e 100644 --- a/build/package/onebox-discovery.Dockerfile +++ b/build/package/onebox-discovery.Dockerfile @@ -8,7 +8,10 @@ COPY go.mod go.sum ./ RUN go mod download COPY cmd/onebox-discovery ./cmd/onebox-discovery COPY internal/discovery ./internal/discovery -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ +# Modules stay in the layer above so a CI layer-cache hit skips downloads; +# the build cache mount only speeds up local rebuilds. +RUN --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ go build -trimpath -ldflags="-s -w" -o /out/onebox-discovery ./cmd/onebox-discovery FROM scratch diff --git a/build/package/postgres.Dockerfile b/build/package/postgres.Dockerfile index ba545ebe..f81702d6 100644 --- a/build/package/postgres.Dockerfile +++ b/build/package/postgres.Dockerfile @@ -1,108 +1,116 @@ # syntax=docker/dockerfile:1 ARG PG_MAJOR=18 -ARG DEBIAN_CODENAME=trixie +# Digest pins make every rebuild reproducible. Bump the digest to take a new +# PostgreSQL minor release or Debian security update; this workflow rebuilds +# only when this file changes. +ARG POSTGRES_IMAGE=postgres:18-trixie@sha256:64c8b0d31e4ab6ea665e8426ea406a94bf52de3c05b3a4a8bf713704eefa9328 +ARG DEBIAN_IMAGE=debian:trixie-slim@sha256:8aa5a7bf5a1955bddbe7d74fcdd0b91ab30e74362a8b73af672b0481b35b44a0 -FROM debian:trixie-slim AS walg-build +# Downloads and checksum checks run here so curl and unzip never enter the +# final image. +FROM ${DEBIAN_IMAGE} AS fetch -# The official release has separate Linux binaries. This mapping is build-time -# only: Buildx selects TARGETARCH and the resulting multi-arch image manifest -# selects the matching image at the host. ob neither detects an architecture -# nor transfers a WAL-G binary. +# The official releases have separate Linux binaries. This mapping is +# build-time only: Buildx selects TARGETARCH and the resulting multi-arch image +# manifest selects the matching image at the host. ob neither detects an +# architecture nor transfers a WAL-G binary. +ARG PG_MAJOR ARG TARGETARCH ARG WALG_VERSION=v3.0.8 ARG WALG_AMD64_SHA256=f30544c5ce93cf83b87578e3c4a2e9c0e0ffc3d160ef89ecddaf75f397d98deb ARG WALG_ARM64_SHA256=794d1a81f0c27825a1603bd39c0f2cf5dd8bed7cc36b598ca05d8d963c3d5fcf +ARG PGVECTORSCALE_COMMIT=c66cae4b621664b68546587da9fafd80b791e643 +ARG PGVECTORSCALE_VERSION=0.9.0 +ARG PGVECTORSCALE_AMD64_SHA256=7a5450b81a7403ca20ff5e5a2f81aa13c81795ddd1fdfe9b986c42c48b12ed67 +ARG PGVECTORSCALE_ARM64_SHA256=8d0916df999f082ceb3d019bdfa72f5df395c31b152f7906de59e429ee11edc7 RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates curl && \ + apt-get install -y --no-install-recommends ca-certificates curl unzip && \ case "${TARGETARCH}" in \ - amd64) walg_asset="wal-g-pg-22.04-amd64"; walg_sha="${WALG_AMD64_SHA256}" ;; \ - arm64) walg_asset="wal-g-pg-22.04-aarch64"; walg_sha="${WALG_ARM64_SHA256}" ;; \ - *) echo "unsupported WAL-G architecture: ${TARGETARCH}" >&2; exit 1 ;; \ + amd64) walg_asset="wal-g-pg-22.04-amd64"; walg_sha="${WALG_AMD64_SHA256}"; pgvectorscale_sha="${PGVECTORSCALE_AMD64_SHA256}" ;; \ + arm64) walg_asset="wal-g-pg-22.04-aarch64"; walg_sha="${WALG_ARM64_SHA256}"; pgvectorscale_sha="${PGVECTORSCALE_ARM64_SHA256}" ;; \ + *) echo "unsupported architecture: ${TARGETARCH}" >&2; exit 1 ;; \ esac && \ - install -d /out && \ - curl -fsSL "https://github.com/wal-g/wal-g/releases/download/${WALG_VERSION}/${walg_asset}" -o /out/wal-g && \ - echo "${walg_sha} /out/wal-g" | sha256sum -c - && \ - chmod 0755 /out/wal-g + install -d /out/bin /out/deb /out/doc/pgvectorscale && \ + curl -fsSL "https://github.com/wal-g/wal-g/releases/download/${WALG_VERSION}/${walg_asset}" -o /out/bin/wal-g && \ + echo "${walg_sha} /out/bin/wal-g" | sha256sum -c - && \ + chmod 0755 /out/bin/wal-g && \ + pgvectorscale_archive="pgvectorscale-${PGVECTORSCALE_VERSION}-pg${PG_MAJOR}-${TARGETARCH}.zip" && \ + curl -fsSL \ + "https://github.com/timescale/pgvectorscale/releases/download/${PGVECTORSCALE_VERSION}/${pgvectorscale_archive}" \ + -o "/tmp/${pgvectorscale_archive}" && \ + echo "${pgvectorscale_sha} /tmp/${pgvectorscale_archive}" | sha256sum -c - && \ + unzip -j "/tmp/${pgvectorscale_archive}" \ + "pgvectorscale-postgresql-${PG_MAJOR}_${PGVECTORSCALE_VERSION}-Linux_${TARGETARCH}.deb" \ + -d /out/deb && \ + curl -fsSL \ + "https://raw.githubusercontent.com/timescale/pgvectorscale/${PGVECTORSCALE_COMMIT}/LICENSE" \ + -o /out/doc/pgvectorscale/LICENSE && \ + curl -fsSL \ + "https://raw.githubusercontent.com/timescale/pgvectorscale/${PGVECTORSCALE_COMMIT}/NOTICE" \ + -o /out/doc/pgvectorscale/NOTICE && \ + echo "df34f0384d53261f4dc47b3d834a13b570f177b8ab1c8a00266a98f30de2e117 /out/doc/pgvectorscale/LICENSE" | sha256sum -c - && \ + echo "4e204f7b0aa175af0a3b38c3bc56852954adf0110e25babe94eab6e35eeef114 /out/doc/pgvectorscale/NOTICE" | sha256sum -c - -FROM postgres:${PG_MAJOR}-${DEBIAN_CODENAME} +# pgvector compiles against the same server image it ships in. Only the +# installed files are copied out, so the final image never contains a +# compiler, binutils, or server headers. +FROM ${POSTGRES_IMAGE} AS pgvector-build ARG PG_MAJOR -ARG TARGETARCH ARG PGVECTOR_COMMIT=8ee86c96f0fd72390f890aa8a336fda6d3ab4c6c ARG PGVECTOR_VERSION=0.8.6 -ARG PGVECTORSCALE_COMMIT=c66cae4b621664b68546587da9fafd80b791e643 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + postgresql-server-dev-${PG_MAJOR} +# The full commit is immutable. BuildKit checks out that exact source instead +# of trusting a movable release tag. +ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_COMMIT} /src/pgvector +WORKDIR /src/pgvector +RUN make OPTFLAGS="" && \ + make install DESTDIR=/out && \ + grep -Fqx "default_version = '${PGVECTOR_VERSION}'" vector.control && \ + install -d /out/usr/share/doc/pgvector && \ + install -m 0644 LICENSE README.md /out/usr/share/doc/pgvector/ && \ + printf '%s\n' "${PGVECTOR_VERSION}" > /out/usr/share/doc/pgvector/VERSION + +FROM ${POSTGRES_IMAGE} + +ARG PG_MAJOR +ARG TARGETARCH ARG PGVECTORSCALE_VERSION=0.9.0 -ARG PGVECTORSCALE_AMD64_SHA256=7a5450b81a7403ca20ff5e5a2f81aa13c81795ddd1fdfe9b986c42c48b12ed67 -ARG PGVECTORSCALE_ARM64_SHA256=8d0916df999f082ceb3d019bdfa72f5df395c31b152f7906de59e429ee11edc7 -ARG POSTGIS_PACKAGE_VERSION=3.6.4+dfsg-2.pgdg13+1 -ARG PG_CRON_PACKAGE_VERSION=1.6.7-3.pgdg13+1 -ARG PGAUDIT_PACKAGE_VERSION=18.0-3.pgdg13+1 -ARG PG_REPACK_PACKAGE_VERSION=1.5.3-1.pgdg13+1 -ARG PG_PARTMAN_PACKAGE_VERSION=5.5.0-1.pgdg13+1 -ARG HYPOPG_PACKAGE_VERSION=1.4.3-1.pgdg13+1 +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" \ org.opencontainers.image.licenses="PostgreSQL AND GPL-2.0-or-later" -COPY --from=walg-build /out/wal-g /usr/local/bin/wal-g +COPY --from=fetch /out/bin/wal-g /usr/local/bin/wal-g +COPY --from=fetch /out/doc/ /usr/share/doc/ +COPY --from=pgvector-build /out/ / -# The full commit is immutable. BuildKit checks out that exact source instead -# of trusting a movable release tag, and the final image contains no compiler. -ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_COMMIT} /tmp/pgvector -RUN apt-get update && \ +# The pgvectorscale package is bind-mounted, not copied, so the .deb never +# lands in an image layer. ca-certificates is explicit: the base image does not +# ship a CA bundle, and WAL-G needs one to reach object storage over TLS. +RUN --mount=type=bind,from=fetch,source=/out/deb,target=/tmp/pgvectorscale \ + apt-get update && \ apt-mark hold locales && \ apt-get install -y --no-install-recommends \ - build-essential \ ca-certificates \ - curl \ - postgresql-server-dev-${PG_MAJOR} \ 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} \ - unzip && \ - cd /tmp/pgvector && \ - make clean && \ - make OPTFLAGS="" && \ - make install && \ - grep -Fqx "default_version = '${PGVECTOR_VERSION}'" vector.control && \ - install -d /usr/share/doc/pgvector && \ - install -m 0644 LICENSE README.md /usr/share/doc/pgvector/ && \ - printf '%s\n' "${PGVECTOR_VERSION}" > /usr/share/doc/pgvector/VERSION && \ - case "${TARGETARCH}" in \ - amd64) pgvectorscale_sha="${PGVECTORSCALE_AMD64_SHA256}" ;; \ - arm64) pgvectorscale_sha="${PGVECTORSCALE_ARM64_SHA256}" ;; \ - *) echo "unsupported pgvectorscale architecture: ${TARGETARCH}" >&2; exit 1 ;; \ - esac && \ - pgvectorscale_archive="pgvectorscale-${PGVECTORSCALE_VERSION}-pg${PG_MAJOR}-${TARGETARCH}.zip" && \ - curl -fsSL \ - "https://github.com/timescale/pgvectorscale/releases/download/${PGVECTORSCALE_VERSION}/${pgvectorscale_archive}" \ - -o "/tmp/${pgvectorscale_archive}" && \ - echo "${pgvectorscale_sha} /tmp/${pgvectorscale_archive}" | sha256sum -c - && \ - install -d /tmp/pgvectorscale-package && \ - unzip -j "/tmp/${pgvectorscale_archive}" \ - "pgvectorscale-postgresql-${PG_MAJOR}_${PGVECTORSCALE_VERSION}-Linux_${TARGETARCH}.deb" \ - -d /tmp/pgvectorscale-package && \ - apt-get install -y --no-install-recommends \ - "/tmp/pgvectorscale-package/pgvectorscale-postgresql-${PG_MAJOR}_${PGVECTORSCALE_VERSION}-Linux_${TARGETARCH}.deb" && \ + "/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" && \ - install -d /usr/share/doc/pgvectorscale && \ - curl -fsSL \ - "https://raw.githubusercontent.com/timescale/pgvectorscale/${PGVECTORSCALE_COMMIT}/LICENSE" \ - -o /usr/share/doc/pgvectorscale/LICENSE && \ - curl -fsSL \ - "https://raw.githubusercontent.com/timescale/pgvectorscale/${PGVECTORSCALE_COMMIT}/NOTICE" \ - -o /usr/share/doc/pgvectorscale/NOTICE && \ - echo "df34f0384d53261f4dc47b3d834a13b570f177b8ab1c8a00266a98f30de2e117 /usr/share/doc/pgvectorscale/LICENSE" | sha256sum -c - && \ - echo "4e204f7b0aa175af0a3b38c3bc56852954adf0110e25babe94eab6e35eeef114 /usr/share/doc/pgvectorscale/NOTICE" | sha256sum -c - && \ - cd / && \ - rm -rf /tmp/pgvector /tmp/pgvectorscale-package "/tmp/${pgvectorscale_archive}" && \ - apt-get remove -y build-essential curl postgresql-server-dev-${PG_MAJOR} unzip && \ - apt-get autoremove -y && \ apt-mark unhold locales && \ rm -rf /var/lib/apt/lists/* From c8d96487d8ce764972b3792e3704fa6d8a47a0e0 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 06:00:04 -0800 Subject: [PATCH 2/4] build(images): address review of the Postgres image rework - 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 --- .github/workflows/postgres-image.yml | 27 +++++++++++++++++++++++---- build/package/postgres.Dockerfile | 27 ++++++++++++++++++--------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/.github/workflows/postgres-image.yml b/.github/workflows/postgres-image.yml index 2153a57e..0fc4176f 100644 --- a/.github/workflows/postgres-image.yml +++ b/.github/workflows/postgres-image.yml @@ -70,7 +70,9 @@ jobs: -c cron.database_name=postgres \ -c cron.use_background_workers=on for attempt in $(seq 1 60); do - if docker exec "$container" pg_isready -U postgres -d postgres >/dev/null 2>&1; then + # The entrypoint init server listens only on the Unix socket; TCP + # answers only once the real server is up. + if docker exec "$container" pg_isready -h 127.0.0.1 -U postgres -d postgres >/dev/null 2>&1; then break fi if [ "$attempt" -eq 60 ]; then @@ -106,8 +108,8 @@ jobs: docker exec "$container" wal-g --version # WAL-G reaches object storage over TLS and needs the CA bundle. docker exec "$container" test -s /etc/ssl/certs/ca-certificates.crt - # Build tools belong to the pgvector-build stage only. - if docker exec "$container" sh -c 'command -v gcc || command -v cc || command -v make || command -v ld || command -v curl'; then + # Build tools belong to the pgvector-build and fetch stages only. + if docker exec "$container" sh -c 'for tool in gcc cc clang make ld llvm-config curl unzip; do command -v "$tool" && exit 0; done; ls -d /usr/lib/llvm-*/bin/clang 2>/dev/null && exit 0; exit 1'; then echo "::error::build tools leaked into the final image" exit 1 fi @@ -132,7 +134,24 @@ jobs: run: | candidate="ghcr.io/labstack/onebox-postgres:18-${GITHUB_SHA}" docker buildx imagetools create --tag "$candidate" "${candidate}-amd64" "${candidate}-arm64" - docker buildx imagetools inspect "$candidate" + # Promote only an index holding exactly the two verified platforms, + # each at the digest its own runner tested. + platforms=$(docker buildx imagetools inspect "$candidate" --raw | + jq -r '[.manifests[] | select(.platform.os == "linux") | .platform.architecture] | sort | join(",")') + if [ "$platforms" != "amd64,arm64" ]; then + echo "::error::merged index has platforms '$platforms', want amd64,arm64" + exit 1 + fi + for arch in amd64 arm64; do + tested=$(docker buildx imagetools inspect "${candidate}-${arch}" --raw | + jq -r --arg arch "$arch" '.manifests[] | select(.platform.architecture == $arch) | .digest') + merged=$(docker buildx imagetools inspect "$candidate" --raw | + jq -r --arg arch "$arch" '.manifests[] | select(.platform.architecture == $arch) | .digest') + if [ -z "$tested" ] || [ "$tested" != "$merged" ]; then + echo "::error::$arch digest in merged index ($merged) differs from tested candidate ($tested)" + exit 1 + fi + done - 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}" diff --git a/build/package/postgres.Dockerfile b/build/package/postgres.Dockerfile index f81702d6..3de692a3 100644 --- a/build/package/postgres.Dockerfile +++ b/build/package/postgres.Dockerfile @@ -1,15 +1,22 @@ # syntax=docker/dockerfile:1 +# PG_MAJOR must match the major version in POSTGRES_IMAGE; change both together. ARG PG_MAJOR=18 -# Digest pins make every rebuild reproducible. Bump the digest to take a new -# PostgreSQL minor release or Debian security update; this workflow rebuilds -# only when this file changes. +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. The workflow runs only +# when this file changes. ARG POSTGRES_IMAGE=postgres:18-trixie@sha256:64c8b0d31e4ab6ea665e8426ea406a94bf52de3c05b3a4a8bf713704eefa9328 ARG DEBIAN_IMAGE=debian:trixie-slim@sha256:8aa5a7bf5a1955bddbe7d74fcdd0b91ab30e74362a8b73af672b0481b35b44a0 # Downloads and checksum checks run here so curl and unzip never enter the # final image. -FROM ${DEBIAN_IMAGE} AS fetch +# The stage only downloads and checksums, so it 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 # build-time only: Buildx selects TARGETARCH and the resulting multi-arch image @@ -21,7 +28,7 @@ ARG WALG_VERSION=v3.0.8 ARG WALG_AMD64_SHA256=f30544c5ce93cf83b87578e3c4a2e9c0e0ffc3d160ef89ecddaf75f397d98deb ARG WALG_ARM64_SHA256=794d1a81f0c27825a1603bd39c0f2cf5dd8bed7cc36b598ca05d8d963c3d5fcf ARG PGVECTORSCALE_COMMIT=c66cae4b621664b68546587da9fafd80b791e643 -ARG PGVECTORSCALE_VERSION=0.9.0 +ARG PGVECTORSCALE_VERSION ARG PGVECTORSCALE_AMD64_SHA256=7a5450b81a7403ca20ff5e5a2f81aa13c81795ddd1fdfe9b986c42c48b12ed67 ARG PGVECTORSCALE_ARM64_SHA256=8d0916df999f082ceb3d019bdfa72f5df395c31b152f7906de59e429ee11edc7 RUN apt-get update && \ @@ -52,9 +59,11 @@ RUN apt-get update && \ echo "df34f0384d53261f4dc47b3d834a13b570f177b8ab1c8a00266a98f30de2e117 /out/doc/pgvectorscale/LICENSE" | sha256sum -c - && \ echo "4e204f7b0aa175af0a3b38c3bc56852954adf0110e25babe94eab6e35eeef114 /out/doc/pgvectorscale/NOTICE" | sha256sum -c - -# pgvector compiles against the same server image it ships in. Only the -# installed files are copied out, so the final image never contains a -# compiler, binutils, or server headers. +# pgvector compiles against the same server image it ships in. Only the files +# `make install` produces are copied out: the library, its LLVM bitcode, SQL +# scripts, and pgvector's own headers (which other extensions build against). +# The compiler, binutils, clang/LLVM, and postgresql-server-dev never reach the +# final image. FROM ${POSTGRES_IMAGE} AS pgvector-build ARG PG_MAJOR @@ -79,7 +88,7 @@ FROM ${POSTGRES_IMAGE} ARG PG_MAJOR ARG TARGETARCH -ARG PGVECTORSCALE_VERSION=0.9.0 +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 From 085fed8bdff6b10f36d9eb55c20823b7009e8cee Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 06:08:38 -0800 Subject: [PATCH 3/4] build(postgres): open a weekly pull request that bumps image pins 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 --- .github/workflows/cla.yml | 2 +- .github/workflows/postgres-image-bump.yml | 156 ++++++++++++++++++++++ .github/workflows/postgres-image.yml | 55 +------- build/package/postgres-bump.sh | 77 +++++++++++ build/package/postgres-verify.sh | 61 +++++++++ 5 files changed, 297 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/postgres-image-bump.yml create mode 100755 build/package/postgres-bump.sh create mode 100755 build/package/postgres-verify.sh diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 24eb4f46..ce782cec 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] + allowlist: vishr,dependabot[bot],github-actions[bot] diff --git a/.github/workflows/postgres-image-bump.yml b/.github/workflows/postgres-image-bump.yml new file mode 100644 index 00000000..c7424ebe --- /dev/null +++ b/.github/workflows/postgres-image-bump.yml @@ -0,0 +1,156 @@ +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. +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 }} + 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. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + token: ${{ secrets.POSTGRES_BUMP_TOKEN || secrets.GITHUB_TOKEN }} + + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # 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 + + - name: Push bump 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" + git switch -c "$BRANCH" + { + 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 -f origin "$BRANCH" + echo "sha=$(git rev-parse HEAD)" >> "$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 + cache-from: type=gha,scope=onebox-postgres-${{ matrix.arch }} + cache-to: type=gha,mode=max,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: read + pull-requests: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.bump.outputs.sha }} + fetch-depth: 2 + + - 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 diff --git a/.github/workflows/postgres-image.yml b/.github/workflows/postgres-image.yml index 0fc4176f..e5640323 100644 --- a/.github/workflows/postgres-image.yml +++ b/.github/workflows/postgres-image.yml @@ -5,6 +5,7 @@ on: branches: [main] paths: - build/package/postgres.Dockerfile + - build/package/postgres-verify.sh - .github/workflows/postgres-image.yml workflow_dispatch: @@ -60,59 +61,7 @@ jobs: cache-to: type=gha,mode=max,scope=onebox-postgres-${{ matrix.arch }} - name: Verify exact published platform image - shell: bash - run: | - set -euo pipefail - container=onebox-postgres-test - trap 'docker rm -f "$container" >/dev/null 2>&1 || true' EXIT - docker run -d --name "$container" -e POSTGRES_PASSWORD=test "$CANDIDATE" \ - -c shared_preload_libraries=pg_cron,pgaudit,pg_stat_statements \ - -c cron.database_name=postgres \ - -c cron.use_background_workers=on - for attempt in $(seq 1 60); do - # The entrypoint init server listens only on the Unix socket; TCP - # answers only once the real server is up. - if docker exec "$container" pg_isready -h 127.0.0.1 -U postgres -d postgres >/dev/null 2>&1; then - break - fi - if [ "$attempt" -eq 60 ]; then - docker logs "$container" - exit 1 - fi - sleep 1 - done - docker exec "$container" psql -U postgres -d postgres -v ON_ERROR_STOP=1 \ - -c 'CREATE EXTENSION vector' \ - -c 'CREATE EXTENSION vectorscale' \ - -c 'CREATE EXTENSION postgis' \ - -c 'CREATE EXTENSION pg_cron' \ - -c 'CREATE EXTENSION pgaudit' \ - -c 'CREATE EXTENSION pg_repack' \ - -c 'CREATE EXTENSION pg_partman' \ - -c 'CREATE EXTENSION hypopg' \ - -c 'CREATE EXTENSION pg_stat_statements' \ - -c "SELECT '[1,2,3]'::vector <-> '[1,2,4]'::vector" \ - -c 'CREATE TABLE onebox_vectorscale(id bigint, embedding vector(3))' \ - -c "INSERT INTO onebox_vectorscale VALUES (1, '[1,2,3]'), (2, '[4,5,6]'), (3, '[7,8,9]')" \ - -c 'CREATE INDEX onebox_vectorscale_diskann ON onebox_vectorscale USING diskann (embedding vector_l2_ops)' \ - -c "SELECT indexdef FROM pg_indexes WHERE indexname = 'onebox_vectorscale_diskann'" \ - -c 'SET enable_seqscan = off' \ - -c "SELECT id FROM onebox_vectorscale ORDER BY embedding <-> '[1,2,3]' LIMIT 1" \ - -c "SELECT ST_AsText(ST_Point(1, 2))" \ - -c "SELECT cron.schedule('onebox-smoke', '0 0 * * *', 'SELECT 1')" \ - -c "SELECT cron.unschedule('onebox-smoke')" \ - -c 'CREATE TABLE onebox_hypopg(id bigint)' \ - -c "SELECT indexrelid IS NOT NULL FROM hypopg_create_index('CREATE INDEX ON onebox_hypopg(id)')" \ - -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('vector', 'vectorscale', 'postgis', 'pg_cron', 'pgaudit', 'pg_repack', 'pg_partman', 'hypopg', 'pg_stat_statements') ORDER BY extname" - docker exec "$container" pg_repack --version - docker exec "$container" wal-g --version - # WAL-G reaches object storage over TLS and needs the CA bundle. - docker exec "$container" test -s /etc/ssl/certs/ca-certificates.crt - # Build tools belong to the pgvector-build and fetch stages only. - if docker exec "$container" sh -c 'for tool in gcc cc clang make ld llvm-config curl unzip; do command -v "$tool" && exit 0; done; ls -d /usr/lib/llvm-*/bin/clang 2>/dev/null && exit 0; exit 1'; then - echo "::error::build tools leaked into the final image" - exit 1 - fi + run: build/package/postgres-verify.sh "$CANDIDATE" publish: name: Publish PostgreSQL 18 image diff --git a/build/package/postgres-bump.sh b/build/package/postgres-bump.sh new file mode 100755 index 00000000..406347a3 --- /dev/null +++ b/build/package/postgres-bump.sh @@ -0,0 +1,77 @@ +#!/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) +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 which builds its pgdg source offers now. +candidates=$(docker run --rm "$(arg_value POSTGRES_IMAGE)" sh -c ' + apt-get update -qq >/dev/null 2>&1 + for package in "$@"; do + printf "%s %s\n" "$package" "$(apt-cache policy "$package" | sed -n "s/^ *Candidate: //p")" + done' sh "${names[@]}") + +for entry in "${packages[@]}"; do + name=${entry%%=*} + package=${entry#*=} + version=$(printf '%s\n' "$candidates" | awk -v p="$package" '$1 == p { print $2 }') + if [ -z "$version" ] || [ "$version" = "(none)" ]; then + echo "no candidate for $package" >&2 + exit 1 + fi + set_arg "$name" "$version" +done diff --git a/build/package/postgres-verify.sh b/build/package/postgres-verify.sh new file mode 100755 index 00000000..d1b8a373 --- /dev/null +++ b/build/package/postgres-verify.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Smoke-test a built onebox-postgres image: start it, create every bundled +# extension, exercise each one, and check that build-only tools stayed out. +# Usage: build/package/postgres-verify.sh IMAGE +set -euo pipefail +if [ "$#" -ne 1 ]; then + echo "usage: $0 IMAGE" >&2 + exit 2 +fi +CANDIDATE=$1 +container=onebox-postgres-verify-$$ +trap 'docker rm -f "$container" >/dev/null 2>&1 || true' EXIT +docker run -d --name "$container" -e POSTGRES_PASSWORD=test "$CANDIDATE" \ + -c shared_preload_libraries=pg_cron,pgaudit,pg_stat_statements \ + -c cron.database_name=postgres \ + -c cron.use_background_workers=on +for attempt in $(seq 1 60); do + # The entrypoint init server listens only on the Unix socket; TCP + # answers only once the real server is up. + if docker exec "$container" pg_isready -h 127.0.0.1 -U postgres -d postgres >/dev/null 2>&1; then + break + fi + if [ "$attempt" -eq 60 ]; then + docker logs "$container" + exit 1 + fi + sleep 1 +done +docker exec "$container" psql -U postgres -d postgres -v ON_ERROR_STOP=1 \ + -c 'CREATE EXTENSION vector' \ + -c 'CREATE EXTENSION vectorscale' \ + -c 'CREATE EXTENSION postgis' \ + -c 'CREATE EXTENSION pg_cron' \ + -c 'CREATE EXTENSION pgaudit' \ + -c 'CREATE EXTENSION pg_repack' \ + -c 'CREATE EXTENSION pg_partman' \ + -c 'CREATE EXTENSION hypopg' \ + -c 'CREATE EXTENSION pg_stat_statements' \ + -c "SELECT '[1,2,3]'::vector <-> '[1,2,4]'::vector" \ + -c 'CREATE TABLE onebox_vectorscale(id bigint, embedding vector(3))' \ + -c "INSERT INTO onebox_vectorscale VALUES (1, '[1,2,3]'), (2, '[4,5,6]'), (3, '[7,8,9]')" \ + -c 'CREATE INDEX onebox_vectorscale_diskann ON onebox_vectorscale USING diskann (embedding vector_l2_ops)' \ + -c "SELECT indexdef FROM pg_indexes WHERE indexname = 'onebox_vectorscale_diskann'" \ + -c 'SET enable_seqscan = off' \ + -c "SELECT id FROM onebox_vectorscale ORDER BY embedding <-> '[1,2,3]' LIMIT 1" \ + -c "SELECT ST_AsText(ST_Point(1, 2))" \ + -c "SELECT cron.schedule('onebox-smoke', '0 0 * * *', 'SELECT 1')" \ + -c "SELECT cron.unschedule('onebox-smoke')" \ + -c 'CREATE TABLE onebox_hypopg(id bigint)' \ + -c "SELECT indexrelid IS NOT NULL FROM hypopg_create_index('CREATE INDEX ON onebox_hypopg(id)')" \ + -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('vector', 'vectorscale', 'postgis', 'pg_cron', 'pgaudit', 'pg_repack', 'pg_partman', 'hypopg', 'pg_stat_statements') ORDER BY extname" +docker exec "$container" pg_repack --version +docker exec "$container" wal-g --version +# WAL-G reaches object storage over TLS and needs the CA bundle. +docker exec "$container" test -s /etc/ssl/certs/ca-certificates.crt +# Build tools belong to the pgvector-build and fetch stages only. +if docker exec "$container" sh -c 'for tool in gcc cc clang make ld llvm-config curl unzip; do command -v "$tool" && exit 0; done; ls -d /usr/lib/llvm-*/bin/clang 2>/dev/null && exit 0; exit 1'; then + echo "::error::build tools leaked into the final image" + exit 1 +fi + From 0d41aa3df842628d99f066e466176838ab26a01c Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 29 Nov 2026 06:23:24 -0800 Subject: [PATCH 4/4] build(postgres): address review of the weekly pin bump - 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 --- .github/workflows/postgres-image-bump.yml | 50 +++++++++++++++++++---- build/package/postgres-bump.sh | 30 ++++++++++---- build/package/postgres.Dockerfile | 6 ++- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/.github/workflows/postgres-image-bump.yml b/.github/workflows/postgres-image-bump.yml index c7424ebe..fad2035d 100644 --- a/.github/workflows/postgres-image-bump.yml +++ b/.github/workflows/postgres-image-bump.yml @@ -5,6 +5,9 @@ name: PostgreSQL image pin bump # 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" @@ -28,16 +31,21 @@ jobs: 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 }} - - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 + # The script asks an arm64 container which pgdg builds it sees. + - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - name: Bump pins id: bump @@ -52,22 +60,27 @@ jobs: { echo '```'; cat "$RUNNER_TEMP/changes.txt"; echo '```'; } >> "$GITHUB_STEP_SUMMARY" fi - - name: Push bump branch + # 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" - git switch -c "$BRANCH" + 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 -f origin "$BRANCH" + git push origin "$candidate" echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + echo "candidate=$candidate" >> "$GITHUB_OUTPUT" verify: name: Verify bump (${{ matrix.arch }}) @@ -99,8 +112,9 @@ jobs: 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 }} - cache-to: type=gha,mode=max,scope=onebox-postgres-${{ matrix.arch }} - name: Verify bumped image run: build/package/postgres-verify.sh onebox-postgres:bump @@ -110,13 +124,21 @@ jobs: needs: [bump, verify] runs-on: ubuntu-24.04 permissions: - contents: read + contents: write pull-requests: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ needs.bump.outputs.sha }} - fetch-depth: 2 + 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: @@ -154,3 +176,17 @@ jobs: --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/build/package/postgres-bump.sh b/build/package/postgres-bump.sh index 406347a3..618ec9ff 100755 --- a/build/package/postgres-bump.sh +++ b/build/package/postgres-bump.sh @@ -45,6 +45,11 @@ 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" @@ -58,20 +63,31 @@ for entry in "${packages[@]}"; do names+=("${entry#*=}") done -# Ask the new base image which builds its pgdg source offers now. -candidates=$(docker run --rm "$(arg_value POSTGRES_IMAGE)" sh -c ' - apt-get update -qq >/dev/null 2>&1 - for package in "$@"; do - printf "%s %s\n" "$package" "$(apt-cache policy "$package" | sed -n "s/^ *Candidate: //p")" - done' sh "${names[@]}") +# 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. +candidates() { + docker run --rm --platform "$1" "$postgres_image" 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=$(candidates linux/amd64) +arm64=$(candidates linux/arm64) for entry in "${packages[@]}"; do name=${entry%%=*} package=${entry#*=} - version=$(printf '%s\n' "$candidates" | awk -v p="$package" '$1 == p { print $2 }') + 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 3de692a3..126ed6ec 100644 --- a/build/package/postgres.Dockerfile +++ b/build/package/postgres.Dockerfile @@ -7,8 +7,10 @@ ARG PGVECTORSCALE_VERSION=0.9.0 # 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. The workflow runs only -# when this file changes. +# 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