-
Notifications
You must be signed in to change notification settings - Fork 4
111 lines (102 loc) · 3.82 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Build Postgres Container Images from sources
on:
workflow_dispatch:
inputs:
major_version:
description: "PostgreSQL major version tag (leave empty for default)"
required: false
default: ""
extra_tag:
description: "Use this field to set an extra tag (make sure it starts with the PG major)"
required: false
default: ""
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"
# 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:
tag: ${{ env.TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set PostgreSQL Major version
run: |
majorVersion="${{ github.event.inputs.major_version }}"
if [[ -z "${majorVersion}" ]]; then
majorVersion=`cat pg_major.json | jq -r '.pg_major'`
fi
echo "PG_MAJOR=${majorVersion}" >> $GITHUB_ENV
- name: Set tag and optional extra tag
run: |
TAG="${{ 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.REGISTRY }}:${{ 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="${{ env.PG_MAJOR }}"
image="${{ env.REGISTRY }}:${{ needs.build-pg.outputs.tag }}"
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