Skip to content

Commit 3ce5bc4

Browse files
committed
ci: use bake in build.yml
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent ca13f3f commit 3ce5bc4

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

.github/workflows/build.yml

Lines changed: 34 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,38 @@ 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=${registry}/postgresql-trunk:18-minimal-${{ github.run_number }}
73+
standard.tags=${registry}/postgresql-trunk:18-standard-${{ github.run_number }}
74+
postgis.tags=${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+
echo "IMAGES=$(echo '${{ steps.build.outputs.metadata }}' | jq -c '.[]."image.name"')" >> $GITHUB_ENV
8582
8683
generate-summary:
8784
name: PostgreSQL Image Build summary
@@ -92,11 +89,16 @@ jobs:
9289
- name: Output summary
9390
run: |
9491
pg_major="${{ needs.build-pg.outputs.pg_major }}"
95-
image="${{ needs.build-pg.outputs.pg_image }}"
96-
imageURL="https://${image}"
92+
images="${{ needs.build-pg.outputs.images }}"
93+
images_list="$(echo $images | jq -r | tr ' ' '\n' | sed 's/^/https:\/\//')"
94+
standardImage="$(echo $images | jq -r | grep standard)"
95+
standardImageURL="https://${standardImage}"
96+
9797
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
98+
echo "Here's the list of images that have been built:" >> $GITHUB_STEP_SUMMARY
99+
echo "$images_list" >> $GITHUB_STEP_SUMMARY
100+
101+
echo "## CloudNativePG Cluster definition (example using the standard image)" >> $GITHUB_STEP_SUMMARY
100102
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
101103
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
102104
echo "(cat <<EOF" >> $GITHUB_STEP_SUMMARY
@@ -105,7 +107,7 @@ jobs:
105107
echo "metadata:" >> $GITHUB_STEP_SUMMARY
106108
echo " name: pg-$pg_major-build" >> $GITHUB_STEP_SUMMARY
107109
echo "spec:" >> $GITHUB_STEP_SUMMARY
108-
echo " imageName: $image" >> $GITHUB_STEP_SUMMARY
110+
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
109111
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
110112
echo " storage:" >> $GITHUB_STEP_SUMMARY
111113
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)