Skip to content

Commit 4b36ca3

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

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

.github/workflows/build.yml

+47
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,51 @@ 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: Download artifacts
151+
uses: actions/download-artifact@v4
152+
with:
153+
pattern: '*-clusterimagecatalog.yaml'
154+
path: clusterimagecatalog
155+
merge-multiple: true
156+
157+
- name: Test ClusterImageCatalog
158+
run: |
159+
yq eval-all '. as $item ireduce ({}; . *+ $item )' clusterimagecatalog/*.yaml

0 commit comments

Comments
 (0)