38
38
type : boolean
39
39
required : false
40
40
default : true
41
+ push-dirty :
42
+ description : Push scanned images that have vulnerabilities?
43
+ type : boolean
44
+ required : false
45
+ # NOTE(Alex-Welsh): This default should be flipped once we resolve existing failures
46
+ default : true
41
47
42
48
env :
43
49
ANSIBLE_FORCE_COLOR : True
@@ -109,7 +115,15 @@ jobs:
109
115
- name : Install package dependencies
110
116
run : |
111
117
sudo apt update
112
- sudo apt install -y build-essential git unzip nodejs python3-wheel python3-pip python3-venv
118
+ sudo apt install -y build-essential git unzip nodejs python3-wheel python3-pip python3-venv curl jq wget
119
+
120
+ - name : Install gh
121
+ run : |
122
+ sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
123
+ sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
124
+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
125
+ sudo apt update
126
+ sudo apt install gh -y
113
127
114
128
- name : Checkout
115
129
uses : actions/checkout@v4
@@ -127,6 +141,10 @@ jobs:
127
141
run : |
128
142
docker ps
129
143
144
+ - name : Install Trivy
145
+ run : |
146
+ curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.49.0
147
+
130
148
- name : Install Kayobe
131
149
run : |
132
150
mkdir -p venvs &&
@@ -162,65 +180,124 @@ jobs:
162
180
env :
163
181
KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
164
182
165
- - name : Build and push kolla overcloud images
183
+ - name : Create build logs output directory
184
+ run : mkdir image-build-logs
185
+
186
+ - name : Build kolla overcloud images
187
+ id : build_overcloud_images
188
+ continue-on-error : true
166
189
run : |
167
- args="${{ github.event. inputs.regexes }}"
190
+ args="${{ inputs.regexes }}"
168
191
args="$args -e kolla_base_distro=${{ matrix.distro }}"
169
192
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
170
193
args="$args -e stackhpc_repo_mirror_auth_proxy_enabled=true"
171
- if ${{ inputs.push }} == 'true'; then
172
- args="$args --push"
173
- fi
174
194
source venvs/kayobe/bin/activate &&
175
195
source src/kayobe-config/kayobe-env --environment ci-builder &&
176
196
kayobe overcloud container image build $args
177
197
env :
178
198
KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
179
- if : github.event.inputs.overcloud == 'true'
199
+ if : inputs.overcloud
200
+
201
+ - name : Copy overcloud container image build logs to output directory
202
+ run : sudo mv /var/log/kolla-build.log image-build-logs/kolla-build-overcloud.log
203
+ if : inputs.overcloud
180
204
181
- - name : Build and push kolla seed images
205
+ - name : Build kolla seed images
206
+ id : build_seed_images
207
+ continue-on-error : true
182
208
run : |
183
209
args="-e kolla_base_distro=${{ matrix.distro }}"
184
210
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
185
211
args="$args -e stackhpc_repo_mirror_auth_proxy_enabled=true"
186
- if ${{ inputs.push }} == 'true'; then
187
- args="$args --push"
188
- fi
189
212
source venvs/kayobe/bin/activate &&
190
213
source src/kayobe-config/kayobe-env --environment ci-builder &&
191
214
kayobe seed container image build $args
192
215
env :
193
216
KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
194
- if : github.event.inputs.seed == 'true'
217
+ if : inputs.seed
218
+
219
+ - name : Copy seed container image build logs to output directory
220
+ run : sudo mv /var/log/kolla-build.log image-build-logs/kolla-build-seed.log
221
+ if : inputs.seed
195
222
196
223
- name : Get built container images
197
- run : |
198
- docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/${{ matrix.distro }}-*:${{ needs.generate-tag.outputs.kolla_tag }}" > ${{ matrix.distro }}-container-images
224
+ run : docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/${{ matrix.distro }}-*:${{ needs.generate-tag.outputs.kolla_tag }}" > ${{ matrix.distro }}-container-images
199
225
200
226
- name : Fail if no images have been built
201
227
run : if [ $(wc -l < ${{ matrix.distro }}-container-images) -le 1 ]; then exit 1; fi
202
228
203
- - name : Upload container images artifact
229
+ - name : Scan built container images
230
+ run : src/kayobe-config/tools/scan-images.sh ${{ matrix.distro }} ${{ needs.generate-tag.outputs.kolla_tag }}
231
+
232
+ - name : Move image scan logs to output artifact
233
+ run : mv image-scan-output image-build-logs/image-scan-output
234
+
235
+ - name : Fail if no images have passed scanning
236
+ run : if [ $(wc -l < image-build-logs/image-scan-output/clean-images.txt) -le 0 ]; then exit 1; fi
237
+ if : ${{ !inputs.push-dirty }}
238
+
239
+ - name : Copy clean images to push-attempt-images list
240
+ run : cp image-build-logs/image-scan-output/clean-images.txt image-build-logs/push-attempt-images.txt
241
+ if : inputs.push
242
+
243
+ - name : Append dirty images to push list
244
+ run : |
245
+ cat image-build-logs/image-scan-output/dirty-images.txt >> image-build-logs/push-attempt-images.txt
246
+ if : ${{ inputs.push && inputs.push-dirty }}
247
+
248
+ - name : Push images
249
+ run : |
250
+ touch image-build-logs/push-failed-images.txt
251
+ source venvs/kayobe/bin/activate &&
252
+ source src/kayobe-config/kayobe-env --environment ci-builder &&
253
+ kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml &&
254
+
255
+ while read -r image; do
256
+ # Retries!
257
+ for i in {1..5}; do
258
+ if docker push $image; then
259
+ echo "Pushed $image"
260
+ break
261
+ elif $i == 5; then
262
+ echo "Failed to push $image"
263
+ echo $image >> image-build-logs/push-failed-images.txt
264
+ else
265
+ echo "Failed on retry $i"
266
+ sleep 5
267
+ fi;
268
+ done
269
+ done < image-build-logs/push-attempt-images.txt
270
+ shell : bash
271
+ env :
272
+ KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
273
+ if : inputs.push
274
+
275
+ - name : Upload output artifact
204
276
uses : actions/upload-artifact@v4
205
277
with :
206
- name : ${{ matrix.distro }} container images
207
- path : ${{ matrix.distro }}-container-images
278
+ name : ${{ matrix.distro }}-logs
279
+ path : image-build-logs
208
280
retention-days : 7
281
+ if : ${{ !cancelled() }}
282
+
283
+ - name : Fail when images failed to build
284
+ run : echo "An image build failed. Check the workflow artifact for build logs" && exit 1
285
+ if : ${{ steps.build_overcloud_images.outcome == 'failure' || steps.build_seed_images.outcome == 'failure' }}
286
+
287
+ - name : Fail when images failed to push
288
+ run : if [ $(wc -l < image-build-logs/push-failed-images.txt) -gt 0 ]; then cat image-build-logs/push-failed-images.txt && exit 1; fi
289
+ if : ${{ !cancelled() }}
290
+
291
+ - name : Fail when images failed scanning
292
+ run : if [ $(wc -l < image-build-logs/dirty-images.txt) -gt 0 ]; then cat image-build-logs/dirty-images.txt && exit 1; fi
293
+ if : ${{ !inputs.push-dirty && !cancelled() }}
209
294
210
- sync-container-repositories :
211
- name : Trigger container image repository sync
212
- needs :
213
- - container-image-build
214
- if : github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push
215
- runs-on : ubuntu-latest
216
- permissions : {}
217
- steps :
218
295
# NOTE(mgoddard): Trigger another CI workflow in the
219
296
# stackhpc-release-train repository.
220
297
- name : Trigger container image repository sync
221
298
run : |
222
299
filter='${{ inputs.regexes }}'
223
- if [[ -n $filter ]] && [[ ${{ github.event. inputs.seed }} == 'true' ]]; then
300
+ if [[ -n $filter ]] && [[ ${{ inputs.seed }} == 'true' ]]; then
224
301
filter="$filter bifrost"
225
302
fi
226
303
gh workflow run \
@@ -231,7 +308,9 @@ jobs:
231
308
-f sync-new-images=false
232
309
env :
233
310
GITHUB_TOKEN : ${{ secrets.STACKHPC_RELEASE_TRAIN_TOKEN }}
311
+ if : ${{ github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push && !cancelled() }}
234
312
235
313
- name : Display link to container image repository sync workflows
236
314
run : |
237
315
echo "::notice Container image repository sync workflows: https://github.com/stackhpc/stackhpc-release-train/actions/workflows/container-sync.yml"
316
+ if : ${{ github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push && !cancelled() }}
0 commit comments