@@ -47,13 +47,19 @@ jobs:
47
47
env :
48
48
TAGS : ${{ toJson(matrix.tags) }}
49
49
run : |
50
+ # Set a default image
51
+ echo "BASE_IMAGE=${IMAGE_STAGING}" >> $GITHUB_ENV
52
+
50
53
RESULT=""
51
54
for tag in $(jq -r '.[]' <<< "${TAGS}")
52
55
do
53
56
RESULT="${RESULT},ghcr.io/${IMAGE_STAGING}:${tag}"
54
57
# If we are running the pipeline in the main branch images are pushed in both -testing and PROD repo
55
58
if [ "${GITHUB_REF#refs/heads/}" == main ]
56
59
then
60
+ # Set prod as default image
61
+ echo "BASE_IMAGE=${IMAGE_RELEASE}" >> $GITHUB_ENV
62
+
57
63
RESULT="${RESULT},ghcr.io/${IMAGE_RELEASE}:${tag}"
58
64
fi
59
65
done
@@ -103,10 +109,83 @@ jobs:
103
109
sarif_file : snyk.sarif
104
110
105
111
- name : Build and push
112
+ id : build
106
113
uses : docker/build-push-action@v5
107
114
with :
108
115
context : ${{ matrix.dir }}
109
116
file : ${{ matrix.file }}
110
117
platforms : ${{ matrix.platforms }}
111
118
push : true
112
119
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
+
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