Skip to content

Container Images from PostgreSQL sources #29

Container Images from PostgreSQL sources

Container Images from PostgreSQL sources #29

Workflow file for this run

name: Container Images from PostgreSQL sources
on:
workflow_dispatch:
inputs:
pg_repo:
description: "Name of the target PG repository"
required: true
default: "https://git.postgresql.org/git/postgresql.git"
pg_branch:
description: "Name of the branch in the target PG repository"
required: true
default: "master"
major_version:
description: "PostgreSQL major version (leave empty for default)"
required: false
defaults:
run:
# default failure handling for shell scripts in 'run' steps
shell: 'bash -Eeuo pipefail -x {0}'
jobs:
build-pg:
name: Build generic PostgreSQL image from sources
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
outputs:
images: ${{ env.IMAGES }}
pg_major: ${{ env.PG_MAJOR }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set env variables from defaults.json
run: |
for key in $(jq -r 'keys[]' defaults.json); do
echo "$key=$(cat defaults.json | jq -r --arg key "$key" '.[$key]')" >> $GITHUB_ENV
done
# Inputs have priority over defaults.json.
- name: Evaluate E2E workflow inputs
run: |
if [[ -n "${{ github.event.inputs.major_version }}" ]]; then
echo "PG_MAJOR=${{ github.event.inputs.major_version }}" >> $GITHUB_ENV
fi
- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/bake-action@v6
id: build
env:
environment: production
registry: ghcr.io/${{ github.repository_owner }}
revision: ${{ github.sha }}
pgMajor: ${{ env.PG_MAJOR }}
with:
set: |
*.args.PG_REPO=${{ github.event.inputs.pg_repo }}
*.args.PG_BRANCH=${{ github.event.inputs.pg_branch }}
minimal.tags=${registry}/postgresql-trunk:18-minimal-${{ github.run_number }}
standard.tags=${registry}/postgresql-trunk:18-standard-${{ github.run_number }}
postgis.tags=${registry}/postgresql-trunk:18-postgis-${{ github.run_number }}
push: true
# Get a list of the images that were built and pushed.
- name: Generated images
id: images
run: |
echo "IMAGES=$(echo '${{ steps.build.outputs.metadata }}' | jq -c '.[]."image.name"')" >> $GITHUB_ENV
generate-summary:
name: PostgreSQL Image Build summary
runs-on: ubuntu-24.04
needs:
- build-pg
steps:
- name: Output summary
run: |
pg_major="${{ needs.build-pg.outputs.pg_major }}"
images="${{ needs.build-pg.outputs.images }}"
images_list="$(echo $images | jq -r | tr ' ' '\n' | sed 's/^/https:\/\//')"
standardImage="$(echo $images | jq -r | grep standard)"
standardImageURL="https://${standardImage}"
echo "# PostgreSQL Image Build summary" >> $GITHUB_STEP_SUMMARY
echo "Here's the list of images that have been built:" >> $GITHUB_STEP_SUMMARY
echo "$images_list" >> $GITHUB_STEP_SUMMARY
echo "## CloudNativePG Cluster definition (example using the standard image)" >> $GITHUB_STEP_SUMMARY
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
echo "(cat <<EOF" >> $GITHUB_STEP_SUMMARY
echo "apiVersion: postgresql.cnpg.io/v1" >> $GITHUB_STEP_SUMMARY
echo "kind: Cluster" >> $GITHUB_STEP_SUMMARY
echo "metadata:" >> $GITHUB_STEP_SUMMARY
echo " name: pg-$pg_major-build" >> $GITHUB_STEP_SUMMARY
echo "spec:" >> $GITHUB_STEP_SUMMARY
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
echo " storage:" >> $GITHUB_STEP_SUMMARY
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY
echo "EOF" >> $GITHUB_STEP_SUMMARY
echo ") | kubectl apply -f -" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY