Skip to content

Container Images from PostgreSQL sources #22

Container Images from PostgreSQL sources

Container Images from PostgreSQL sources #22

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
extra_tag:
description: "Optional extra tag (make sure it starts with the PG major)"
required: false
run_e2e:
description: "Run E2Es on the built image"
required: false
type: boolean
default: "false"
cnpg_branch:
description: "Name of the branch/tag used to build & load the operator (leave empty for default)"
required: false
test_depth:
description: 'E2E test level: 0(highest) to 4(lowest) (leave empty for default)'
required: false
feature_type:
description: 'E2E feature type filter. See https://github.com/cloudnative-pg/cloudnative-pg/blob/main/contribute/e2e_testing_environment/README.md#using-feature-type-test-selectionfilter'
required: false
# set up environment variables to be used across all the jobs
env:
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
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-22.04
permissions:
contents: read
packages: write
outputs:
pg_image: ${{ env.TAG }}
pg_major: ${{ env.PG_MAJOR }}
cnpg_branch: ${{ env.CNPG_BRANCH }}
test_depth: ${{ env.TEST_DEPTH }}
feature_type: ${{ env.FEATURE_TYPE }}
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
if [[ -n "${{ github.event.inputs.cnpg_branch }}" ]]; then
echo "CNPG_BRANCH=${{ github.event.inputs.cnpg_branch }}" >> $GITHUB_ENV
fi
if [[ -n "${{ github.event.inputs.test_depth }}" ]]; then
echo "TEST_DEPTH=${{ github.event.inputs.test_depth }}" >> $GITHUB_ENV
fi
if [[ -n "${{ github.event.inputs.feature_type }}" ]]; then
echo "FEATURE_TYPE=${{ github.event.inputs.feature_type }}" >> $GITHUB_ENV
fi
- name: Set tag and optional extra tag
run: |
TAG="${{ env.REGISTRY }}:${{ env.PG_MAJOR }}-build-${{ github.run_number }}"
EXTRA_TAG=""
if [[ "${{ github.event.inputs.extra_tag }}" != "" ]]; then
EXTRA_TAG="${{ env.REGISTRY }}:${{ github.event.inputs.extra_tag }}"
fi
echo "TAG=${TAG}" >> $GITHUB_ENV
echo "EXTRA_TAG=${EXTRA_TAG}" >> $GITHUB_ENV
- 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: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
load: false
tags: |
${{ env.TAG }}
${{ env.EXTRA_TAG }}
build-args: |
PG_REPO=${{ github.event.inputs.pg_repo }}
PG_BRANCH=${{ github.event.inputs.pg_branch }}
generate-summary:
name: PostgreSQL Image Build summary
runs-on: ubuntu-22.04
needs:
- build-pg
steps:
- name: Output summary
run: |
pg_major="${{ needs.build-pg.outputs.pg_major }}"
image="${{ needs.build-pg.outputs.pg_image }}"
imageURL="https://${image}"
echo "# PostgreSQL Image Build summary" >> $GITHUB_STEP_SUMMARY
echo "**Container Image**: [$image]($imageURL)" >> $GITHUB_STEP_SUMMARY
echo "## CloudNativePG Cluster definition" >> $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: $image" >> $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
call-run-e2e:
if: github.event.inputs.run_e2e == 'true'
needs:
- build-pg
uses: ./.github/workflows/run-e2e.yml
with:
postgres_img: ${{ needs.build-pg.outputs.pg_image }}
major_version: ${{ needs.build-pg.outputs.pg_major }}
cnpg_branch: ${{ needs.build-pg.outputs.cnpg_branch }}
test_depth: ${{ needs.build-pg.outputs.test_depth }}
feature_type: ${{ needs.build-pg.outputs.feature_type }}