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]
allowlist: vishr,dependabot[bot],github-actions[bot]
6 changes: 4 additions & 2 deletions .github/workflows/discovery-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
192 changes: 192 additions & 0 deletions .github/workflows/postgres-image-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
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"
Loading
Loading