Skip to content

Commit 6a6a358

Browse files
NiccoloFeimnencia
andauthored
ci: move the container build process to bake (#80)
Signed-off-by: Niccolò Fei <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]>
1 parent c111aa3 commit 6a6a358

File tree

9 files changed

+310
-101
lines changed

9 files changed

+310
-101
lines changed

.github/workflows/build-commitfest.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ on:
55
inputs:
66
patch_id:
77
description: "ID of the Patch"
8-
required: false
8+
required: true
99
major_version:
1010
description: "PostgreSQL major version (leave empty for default)"
1111
required: false
1212

13-
# set up environment variables to be used across all the jobs
14-
env:
15-
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
16-
BRANCH: "master"
17-
1813
defaults:
1914
run:
2015
# default failure handling for shell scripts in 'run' steps
@@ -28,7 +23,7 @@ jobs:
2823
contents: read
2924
packages: write
3025
outputs:
31-
pg_image: "${{ env.REGISTRY }}:${{ env.TAG }}"
26+
images: ${{ env.IMAGES }}
3227
steps:
3328
- name: Checkout Code
3429
uses: actions/checkout@v4
@@ -47,10 +42,9 @@ jobs:
4742
fi
4843
4944
- name: Set commitfest branch and tag
50-
if: github.event.inputs.patch_id != ''
5145
run: |
5246
BRANCH="cf/${{ github.event.inputs.patch_id }}"
53-
TAG="${{ env.PG_MAJOR }}-${BRANCH////-}"
47+
TAG="${BRANCH////-}"
5448
echo "TAG=${TAG}" >> $GITHUB_ENV
5549
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
5650
@@ -61,17 +55,36 @@ jobs:
6155
username: ${{ github.actor }}
6256
password: ${{ secrets.GITHUB_TOKEN }}
6357

58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
6461
- name: Build and push
65-
uses: docker/build-push-action@v6
62+
uses: docker/bake-action@v6
63+
id: build
64+
env:
65+
environment: production
66+
registry: ghcr.io/${{ github.repository_owner }}
67+
revision: ${{ github.sha }}
68+
pgMajor: ${{ env.PG_MAJOR }}
6669
with:
67-
context: .
70+
set: |
71+
*.args.PG_REPO=https://github.com/postgresql-cfbot/postgresql.git
72+
*.args.PG_BRANCH=${{ env.BRANCH }}
73+
minimal.tags=${{ env.registry }}/postgresql-trunk:18-minimal-${{ env.TAG }}
74+
standard.tags=${{ env.registry }}/postgresql-trunk:18-standard-${{ env.TAG }}
75+
postgis.tags=${{ env.registry }}/postgresql-trunk:18-postgis-${{ env.TAG }}
6876
push: true
69-
load: false
70-
tags: |
71-
${{ env.REGISTRY }}:${{ env.TAG }}
72-
build-args: |
73-
PG_REPO=https://github.com/postgresql-cfbot/postgresql.git
74-
PG_BRANCH=${{ env.BRANCH }}
77+
78+
# Get a list of the images that were built and pushed.
79+
- name: Generated images
80+
id: images
81+
run: |
82+
IMAGES="$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.[]."image.name"')"
83+
{
84+
echo 'IMAGES<<EOF'
85+
echo "${IMAGES}"
86+
echo EOF
87+
} >> $GITHUB_ENV
7588
7689
generate-summary:
7790
name: Commitfest Image Build summary
@@ -83,11 +96,15 @@ jobs:
8396
run: |
8497
commitFestPatchID=${{ github.event.inputs.patch_id }}
8598
commitFestURL="https://commitfest.postgresql.org/patch/${commitFestPatchID}"
86-
image="${{ needs.build-pg.outputs.pg_image }}"
87-
imageURL="https://${image}"
99+
images="${{ needs.build-pg.outputs.images }}"
100+
images_list="$(echo $images | tr ' ' '\n' | sed 's/^/https:\/\//')"
101+
standardImage="$(echo $images | tr ' ' '\n' | grep standard)"
102+
88103
echo "# Commitfest Image Build summary" >> $GITHUB_STEP_SUMMARY
89104
echo "**Commitfest Patch URL**: [$commitFestPatchID]($commitFestURL)" >> $GITHUB_STEP_SUMMARY
90-
echo "**Container Image**: [$image]($imageURL)" >> $GITHUB_STEP_SUMMARY
105+
echo "Here's the list of Container Images that have been built:" >> $GITHUB_STEP_SUMMARY
106+
echo "$images_list" >> $GITHUB_STEP_SUMMARY
107+
91108
echo "## CloudNativePG Cluster definition" >> $GITHUB_STEP_SUMMARY
92109
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
93110
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
@@ -97,7 +114,7 @@ jobs:
97114
echo "metadata:" >> $GITHUB_STEP_SUMMARY
98115
echo " name: commitfest-$commitFestPatchID" >> $GITHUB_STEP_SUMMARY
99116
echo "spec:" >> $GITHUB_STEP_SUMMARY
100-
echo " imageName: $image" >> $GITHUB_STEP_SUMMARY
117+
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
101118
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
102119
echo " storage:" >> $GITHUB_STEP_SUMMARY
103120
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY

.github/workflows/build.yml

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ on:
1414
major_version:
1515
description: "PostgreSQL major version (leave empty for default)"
1616
required: false
17-
extra_tag:
18-
description: "Optional extra tag (make sure it starts with the PG major)"
19-
required: false
20-
21-
# set up environment variables to be used across all the jobs
22-
env:
23-
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
2417

2518
defaults:
2619
run:
@@ -35,7 +28,8 @@ jobs:
3528
contents: read
3629
packages: write
3730
outputs:
38-
pg_image: ${{ env.TAG }}
31+
images: ${{ env.IMAGES }}
32+
pg_major: ${{ env.PG_MAJOR }}
3933
steps:
4034
- name: Checkout Code
4135
uses: actions/checkout@v4
@@ -53,35 +47,43 @@ jobs:
5347
echo "PG_MAJOR=${{ github.event.inputs.major_version }}" >> $GITHUB_ENV
5448
fi
5549
56-
- name: Set tag and optional extra tag
57-
run: |
58-
TAG="${{ env.REGISTRY }}:${{ env.PG_MAJOR }}-build-${{ github.run_number }}"
59-
EXTRA_TAG=""
60-
if [[ "${{ github.event.inputs.extra_tag }}" != "" ]]; then
61-
EXTRA_TAG="${{ env.REGISTRY }}:${{ github.event.inputs.extra_tag }}"
62-
fi
63-
echo "TAG=${TAG}" >> $GITHUB_ENV
64-
echo "EXTRA_TAG=${EXTRA_TAG}" >> $GITHUB_ENV
65-
6650
- name: Log in to the GitHub Container registry
6751
uses: docker/login-action@v3
6852
with:
6953
registry: ghcr.io
7054
username: ${{ github.actor }}
7155
password: ${{ secrets.GITHUB_TOKEN }}
7256

57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
7360
- name: Build and push
74-
uses: docker/build-push-action@v6
61+
uses: docker/bake-action@v6
62+
id: build
63+
env:
64+
environment: production
65+
registry: ghcr.io/${{ github.repository_owner }}
66+
revision: ${{ github.sha }}
67+
pgMajor: ${{ env.PG_MAJOR }}
7568
with:
76-
context: .
69+
set: |
70+
*.args.PG_REPO=${{ github.event.inputs.pg_repo }}
71+
*.args.PG_BRANCH=${{ github.event.inputs.pg_branch }}
72+
minimal.tags=${{ env.registry }}/postgresql-trunk:18-minimal-${{ github.run_number }}
73+
standard.tags=${{ env.registry }}/postgresql-trunk:18-standard-${{ github.run_number }}
74+
postgis.tags=${{ env.registry }}/postgresql-trunk:18-postgis-${{ github.run_number }}
7775
push: true
78-
load: false
79-
tags: |
80-
${{ env.TAG }}
81-
${{ env.EXTRA_TAG }}
82-
build-args: |
83-
PG_REPO=${{ github.event.inputs.pg_repo }}
84-
PG_BRANCH=${{ github.event.inputs.pg_branch }}
76+
77+
# Get a list of the images that were built and pushed.
78+
- name: Generated images
79+
id: images
80+
run: |
81+
IMAGES="$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.[]."image.name"')"
82+
{
83+
echo 'IMAGES<<EOF'
84+
echo "${IMAGES}"
85+
echo EOF
86+
} >> $GITHUB_ENV
8587
8688
generate-summary:
8789
name: PostgreSQL Image Build summary
@@ -92,11 +94,15 @@ jobs:
9294
- name: Output summary
9395
run: |
9496
pg_major="${{ needs.build-pg.outputs.pg_major }}"
95-
image="${{ needs.build-pg.outputs.pg_image }}"
96-
imageURL="https://${image}"
97+
images="${{ needs.build-pg.outputs.images }}"
98+
images_list="$(echo $images | tr ' ' '\n' | sed 's/^/https:\/\//')"
99+
standardImage="$(echo $images | tr ' ' '\n' | grep standard)"
100+
97101
echo "# PostgreSQL Image Build summary" >> $GITHUB_STEP_SUMMARY
98-
echo "**Container Image**: [$image]($imageURL)" >> $GITHUB_STEP_SUMMARY
99-
echo "## CloudNativePG Cluster definition" >> $GITHUB_STEP_SUMMARY
102+
echo "Here's the list of Container Images that have been built:" >> $GITHUB_STEP_SUMMARY
103+
echo "$images_list" >> $GITHUB_STEP_SUMMARY
104+
105+
echo "## CloudNativePG Cluster definition (example using the standard image)" >> $GITHUB_STEP_SUMMARY
100106
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
101107
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
102108
echo "(cat <<EOF" >> $GITHUB_STEP_SUMMARY
@@ -105,7 +111,7 @@ jobs:
105111
echo "metadata:" >> $GITHUB_STEP_SUMMARY
106112
echo " name: pg-$pg_major-build" >> $GITHUB_STEP_SUMMARY
107113
echo "spec:" >> $GITHUB_STEP_SUMMARY
108-
echo " imageName: $image" >> $GITHUB_STEP_SUMMARY
114+
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
109115
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
110116
echo " storage:" >> $GITHUB_STEP_SUMMARY
111117
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY

.github/workflows/continuous-delivery.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ on:
1414
schedule:
1515
- cron: '0 1 * * *'
1616

17-
# set up environment variables to be used across all the jobs
18-
env:
19-
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
20-
2117
defaults:
2218
run:
2319
# default failure handling for shell scripts in 'run' steps
@@ -31,7 +27,7 @@ jobs:
3127
contents: read
3228
packages: write
3329
outputs:
34-
pg_image: ${{ env.TAG }}
30+
pg_image: ${{ env.PG_IMAGE }}
3531
pg_major: ${{ env.PG_MAJOR }}
3632
cnpg_branch: ${{ env.CNPG_BRANCH }}
3733
test_depth: ${{ env.TEST_DEPTH }}
@@ -59,26 +55,32 @@ jobs:
5955
echo "FEATURE_TYPE=${{ github.event.inputs.feature_type }}" >> $GITHUB_ENV
6056
fi
6157
62-
- name: Set tag
63-
run: |
64-
postgres_img="${{ env.REGISTRY }}:${{ env.PG_MAJOR }}-devel"
65-
echo "TAG=${postgres_img}" >> $GITHUB_ENV
66-
6758
- name: Log in to the GitHub Container registry
6859
uses: docker/login-action@v3
6960
with:
7061
registry: ghcr.io
7162
username: ${{ github.actor }}
7263
password: ${{ secrets.GITHUB_TOKEN }}
7364

74-
- name: Build and load
75-
uses: docker/build-push-action@v6
65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v3
67+
68+
- name: Build and push
69+
uses: docker/bake-action@v6
70+
id: build
71+
env:
72+
environment: production
73+
registry: ghcr.io/${{ github.repository_owner }}
74+
revision: ${{ github.sha }}
75+
pgMajor: ${{ env.PG_MAJOR }}
7676
with:
77-
context: .
7877
push: true
79-
load: false
80-
tags: |
81-
${{ env.TAG }}
78+
79+
# Get a list of the images that were built and pushed. We only care about a single tag for each image.
80+
- name: Generated images
81+
id: images
82+
run: |
83+
echo "PG_IMAGE=$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.["standard"].["image.name"]' | grep -oP '[^,]*\d{12}[^,]*')" >> $GITHUB_ENV
8284
8385
call-reusable-e2e:
8486
if: github.event_name == 'schedule'

.github/workflows/reusable-e2e.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
POSTGRES_VERSION: ${{ inputs.major_version }}
4949
POSTGRES_IMG: ${{ inputs.postgres_img }}
5050
POSTGRES_KIND: "PostgreSQL"
51+
MAJOR_UPGRADE_IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
5152

5253
DOCKER_SERVER: ghcr.io
5354
DOCKER_USERNAME: ${{ github.actor }}
@@ -127,6 +128,11 @@ jobs:
127128
docker push $E2E_PRE_ROLLING_UPDATE_IMG
128129
echo "E2E_PRE_ROLLING_UPDATE_IMG=$E2E_PRE_ROLLING_UPDATE_IMG" >> $GITHUB_ENV
129130
131+
- name: Setting up default versions
132+
run: |
133+
# Update pkg/versions/versions.go
134+
sed -i '/DefaultImageName *=/s@".*"@"'"${{ inputs.postgres_img }}"'"@' pkg/versions/versions.go
135+
130136
- name: Run Kind End-to-End tests
131137
run: make e2e-test-kind
132138

0 commit comments

Comments
 (0)