ci: mirror postgres service image in ghcr (#2110)

This commit is contained in:
Carlos Florêncio
2026-07-31 19:27:55 +01:00
committed by GitHub
parent aeb7c62e49
commit b5a80d9b23
2 changed files with 37 additions and 1 deletions
+8 -1
View File
@@ -176,7 +176,14 @@ jobs:
container: ghcr.io/kdlbs/kandev-ci:build-latest
services:
postgres:
image: postgres:16@sha256:fe03a7605299a34ddf5e4f285dff78c3d7190a576b3c6b46f2fcff69f4bffd54
# Mirrored from the digest-pinned Docker Hub image by
# ci-base-image.yml. Service images are pulled before steps begin, so
# moving this pull to GHCR removes an otherwise unwrappable Docker Hub
# timeout from job startup.
image: ghcr.io/kdlbs/kandev-ci:postgres-16@sha256:fe03a7605299a34ddf5e4f285dff78c3d7190a576b3c6b46f2fcff69f4bffd54
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
POSTGRES_USER: kandev
POSTGRES_PASSWORD: kandev
+29
View File
@@ -25,6 +25,9 @@ permissions:
env:
IMAGE_NAME: ghcr.io/kdlbs/kandev-ci
POSTGRES_DIGEST: sha256:fe03a7605299a34ddf5e4f285dff78c3d7190a576b3c6b46f2fcff69f4bffd54
POSTGRES_SOURCE: docker.io/library/postgres:16@sha256:fe03a7605299a34ddf5e4f285dff78c3d7190a576b3c6b46f2fcff69f4bffd54
POSTGRES_TARGET: ghcr.io/kdlbs/kandev-ci:postgres-16
jobs:
build-and-push:
@@ -51,6 +54,31 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Service containers are pulled before any job step can add retries. Keep
# the Postgres image beside the job image in GHCR so backend CI has one
# registry dependency. A single image-index source is copied byte-for-byte,
# so the upstream digest remains valid at the mirrored location.
- name: Mirror Postgres to GHCR
if: |
github.event_name == 'workflow_dispatch'
|| (github.event_name == 'push' && github.ref == 'refs/heads/main')
run: |
set -euo pipefail
docker buildx imagetools create \
--tag "${POSTGRES_TARGET}" \
"${POSTGRES_SOURCE}"
mirrored_digest="sha256:$(
docker buildx imagetools inspect --raw "${POSTGRES_TARGET}" \
| sha256sum \
| cut -d ' ' -f 1
)"
if [[ "${mirrored_digest}" != "${POSTGRES_DIGEST}" ]]; then
echo "::error::Postgres mirror digest ${mirrored_digest} does not match ${POSTGRES_DIGEST}"
exit 1
fi
- name: Compute image tag
id: tag
run: |
@@ -111,6 +139,7 @@ jobs:
echo ""
echo "- runtime: \`${IMAGE_NAME}:runtime-sha-${IMAGE_TAG}\` / \`runtime-latest\`"
echo "- build: \`${IMAGE_NAME}:build-sha-${IMAGE_TAG}\` / \`build-latest\`"
echo "- postgres: \`${POSTGRES_TARGET}@${POSTGRES_DIGEST}\`"
echo "- pushed: \`${PUSHED}\`"
} >> "$GITHUB_STEP_SUMMARY"
env: