Skip to content

Commit dc1bf8c

Browse files
committed
feat: generate a ClusterImageCatalog on image update
Signed-off-by: Niccolò Fei <[email protected]>
1 parent 47cc68b commit dc1bf8c

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/build.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ jobs:
4747
env:
4848
TAGS: ${{ toJson(matrix.tags) }}
4949
run: |
50+
# Set a default image
51+
echo "BASE_IMAGE=${IMAGE_STAGING}" >> $GITHUB_ENV
52+
5053
RESULT=""
5154
for tag in $(jq -r '.[]' <<< "${TAGS}")
5255
do
5356
RESULT="${RESULT},ghcr.io/${IMAGE_STAGING}:${tag}"
5457
# If we are running the pipeline in the main branch images are pushed in both -testing and PROD repo
5558
if [ "${GITHUB_REF#refs/heads/}" == main ]
5659
then
60+
# Set prod as default image
61+
echo "BASE_IMAGE=${IMAGE_RELEASE}" >> $GITHUB_ENV
62+
5763
RESULT="${RESULT},ghcr.io/${IMAGE_RELEASE}:${tag}"
5864
fi
5965
done
@@ -103,10 +109,83 @@ jobs:
103109
sarif_file: snyk.sarif
104110

105111
- name: Build and push
112+
id: build
106113
uses: docker/build-push-action@v5
107114
with:
108115
context: ${{ matrix.dir }}
109116
file: ${{ matrix.file }}
110117
platforms: ${{ matrix.platforms }}
111118
push: true
112119
tags: ${{ env.TAGS }}
120+
121+
- name: Create artifact
122+
run: |
123+
DIGEST=ghcr.io/${{ env.BASE_IMAGE }}@${{ steps.build.outputs.digest }} \
124+
MAJOR=${{ matrix.version }} \
125+
yq --null-input '{
126+
"apiVersion": "postgresql.cnpg.io/v1",
127+
"kind": "ClusterImageCatalog",
128+
"metadata": {"name":"postgresql"},
129+
"spec": {
130+
"images": [
131+
{
132+
"major": env(MAJOR),
133+
"image": env(DIGEST)
134+
}
135+
]
136+
}
137+
}' > ${{ matrix.version }}.yaml
138+
139+
- name: Upload artifact
140+
uses: actions/upload-artifact@v4
141+
with:
142+
name: ${{ matrix.version }}-clusterimagecatalog.yaml
143+
path: ${{ matrix.version }}.yaml
144+
145+
image-catalog:
146+
name: Generate ClusterImageCatalog
147+
runs-on: ubuntu-22.04
148+
needs: build
149+
steps:
150+
- name: Checkout Code
151+
uses: actions/checkout@v4
152+
with:
153+
token: ${{ secrets.REPO_GHA_PAT }}
154+
155+
- name: Download artifacts
156+
uses: actions/download-artifact@v4
157+
with:
158+
pattern: '*-clusterimagecatalog.yaml'
159+
path: clusterimagecatalog
160+
merge-multiple: true
161+
162+
- name: Update ClusterImageCatalog
163+
run: |
164+
yq eval-all '. as $item ireduce ({}; . *+ $item )' clusterimagecatalog/*.yaml > Debian/ClusterImageCatalog.yaml
165+
cat Debian/ClusterImageCatalog.yaml
166+
167+
- name: Temporarily disable "include administrators" branch protection
168+
if: ${{ always() && github.ref == 'refs/heads/main' }}
169+
id: disable_include_admins
170+
uses: benjefferies/[email protected]
171+
with:
172+
access_token: ${{ secrets.REPO_GHA_PAT }}
173+
branch: main
174+
enforce_admins: false
175+
176+
- name: Push ClusterImageCatalog updates
177+
uses: EndBug/add-and-commit@v9
178+
if: ${{ github.ref == 'refs/heads/main' }}
179+
with:
180+
author_name: CloudNativePG Automated Updates
181+
author_email: [email protected]
182+
message: 'Automatic ClusterImageCatalog update'
183+
add: 'Debian/ClusterImageCatalog.yaml'
184+
185+
- name: Enable "include administrators" branch protection
186+
uses: benjefferies/[email protected]
187+
if: ${{ always() && github.ref == 'refs/heads/main' }}
188+
with:
189+
access_token: ${{ secrets.REPO_GHA_PAT }}
190+
branch: main
191+
enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}

0 commit comments

Comments
 (0)