Skip to content

Commit c032f68

Browse files
committed
Container image builds misc improvements
1 parent 06857bd commit c032f68

File tree

2 files changed

+66
-30
lines changed

2 files changed

+66
-30
lines changed

.github/workflows/stackhpc-container-image-build.yml

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ on:
3838
type: boolean
3939
required: false
4040
default: true
41-
scan-push:
41+
push-dirty:
4242
description: Push scanned images that have vulnerabilities?
4343
type: boolean
4444
required: false
45+
# NOTE(Alex-Welsh): This default should be flipped once we resolve existing failures
4546
default: true
4647

4748
env:
@@ -171,11 +172,14 @@ jobs:
171172
env:
172173
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
173174

175+
- name: Create build logs output directory
176+
run: mkdir image-build-logs
177+
174178
- name: Build kolla overcloud images
175179
id: build_overcloud_images
176180
continue-on-error: true
177181
run: |
178-
args="${{ github.event.inputs.regexes }}"
182+
args="${{ inputs.regexes }}"
179183
args="$args -e kolla_base_distro=${{ matrix.distro }}"
180184
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
181185
args="$args -e stackhpc_repo_mirror_auth_proxy_enabled=true"
@@ -184,7 +188,11 @@ jobs:
184188
kayobe overcloud container image build $args
185189
env:
186190
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
187-
if: github.event.inputs.overcloud == 'true'
191+
if: inputs.overcloud
192+
193+
- name: Copy overcloud container image build logs to output directory
194+
run: sudo mv /var/log/kolla-build.log image-build-logs/kolla-build-overcloud.log
195+
if: inputs.overcloud
188196

189197
- name: Build kolla seed images
190198
id: build_seed_images
@@ -198,7 +206,11 @@ jobs:
198206
kayobe seed container image build $args
199207
env:
200208
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
201-
if: github.event.inputs.seed == 'true'
209+
if: inputs.seed
210+
211+
- name: Copy seed container image build logs to output directory
212+
run: sudo mv /var/log/kolla-build.log image-build-logs/kolla-build-seed.log
213+
if: inputs.seed
202214

203215
- name: Get built container images
204216
run: |
@@ -208,57 +220,74 @@ jobs:
208220
run: if [ $(wc -l < ${{ matrix.distro }}-container-images) -le 1 ]; then exit 1; fi
209221

210222
- name: Scan built container images
211-
run: src/kayobe-config/tools/scan-images.sh ${{ matrix.distro }} ${{ needs.generate-tag.outputs.kolla_tag }}
212-
213-
- name: Upload Trivy scan results artifact
214-
uses: actions/upload-artifact@v4
215-
with:
216-
name: ${{ matrix.distro }}-image-scan-output
217-
path: image-scan-output
218-
retention-days: 7
223+
run: |
224+
src/kayobe-config/tools/scan-images.sh ${{ matrix.distro }} ${{ needs.generate-tag.outputs.kolla_tag }}
219225
220226
- name: Fail if no images have passed scanning
221227
run: if [ $(wc -l < image-scan-output/clean-images.txt) -le 0 ]; then exit 1; fi
222-
if: github.event.inputs.scan-push == 'false'
228+
if: ${{ !inputs.push-dirty }}
229+
230+
- name: Copy clean images to push-attempt-images list
231+
run: cp image-scan-output/clean-images.txt image-scan-output/push-attempt-images.txt
223232

224-
- name: Append dirty images to clean list
233+
- name: Append dirty images to push list
225234
run: |
226-
cat image-scan-output/dirty-images.txt >> image-scan-output/clean-images.txt
227-
if: github.event.inputs.scan-push == 'true'
235+
cat image-scan-output/dirty-images.txt >> image-scan-output/push-attempt-images.txt
236+
if: inputs.push-dirty
228237

229238
- name: Push images
230239
run: |
240+
touch image-scan-output/push-failed-images.txt
231241
source venvs/kayobe/bin/activate &&
232242
source src/kayobe-config/kayobe-env --environment ci-builder &&
233243
kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml &&
234244
235245
while read -r image; do
236246
# Retries!
237-
for i in {1..10}; do
238-
docker push ${image} && break || sleep 5
247+
for i in {1..5}; do
248+
if docker push $image; then
249+
echo "Pushed $image"
250+
break
251+
elif $i == 5; then
252+
echo "Failed to push $image"
253+
echo $image >> image-scan-output/push-failed-images.txt
254+
else
255+
echo "Failed on retry $i"
256+
sleep 5
257+
fi;
239258
done
240-
done < image-scan-output/clean-images.txt
259+
done < image-scan-output/push-attempt-images.txt &&
260+
mv image-scan-output image-build-logs/image-scan-output
241261
shell: bash
242262
env:
243263
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
244-
if: github.event.inputs.push == 'true'
264+
if: inputs.push
245265

246-
- name: Upload pushed container images artifact
266+
- name: Upload output artifact
247267
uses: actions/upload-artifact@v4
248268
with:
249-
name: ${{ matrix.distro }}-pushed-container-images
250-
path: image-scan-output/clean-images.txt
269+
name: ${{ matrix.distro }}-logs
270+
path: image-build-logs
251271
retention-days: 7
272+
if: ${{ !cancelled() }}
252273

253274
- name: Fail when images failed to build
254-
run: exit 1
255-
if: steps.build_overcloud_images.outcome == 'failure' || steps.build_seed_images.outcome == 'failure'
275+
run: echo "An image build failed. Check the workflow artifact for build logs" && exit 1
276+
if: ${{ steps.build_overcloud_images.outcome == 'failure' || steps.build_seed_images.outcome == 'failure' }}
277+
278+
- name: Fail when images failed to push
279+
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
280+
if: ${{ !cancelled() }}
281+
282+
- name: Fail when images failed scanning
283+
run: if [ $(wc -l < image-build-logs/dirty-images.txt) -gt 0 ]; then cat image-build-logs/dirty-images.txt && exit 1; fi
284+
if: ${{ !inputs.push-dirty && !cancelled() }}
256285

257286
sync-container-repositories:
258287
name: Trigger container image repository sync
259288
needs:
260289
- container-image-build
261-
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push == 'true'
290+
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push
262291
runs-on: ubuntu-latest
263292
permissions: {}
264293
steps:
@@ -267,7 +296,7 @@ jobs:
267296
- name: Trigger container image repository sync
268297
run: |
269298
filter='${{ inputs.regexes }}'
270-
if [[ -n $filter ]] && [[ ${{ github.event.inputs.seed }} == 'true' ]]; then
299+
if [[ -n $filter ]] && [[ ${{ inputs.seed }} == 'true' ]]; then
271300
filter="$filter bifrost"
272301
fi
273302
gh workflow run \

tools/scan-images.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
#!/usr/bin/env bash
12
set -eo pipefail
23

34
# Check correct usage
45
if [[ ! $2 ]]; then
5-
echo "Usage: overcloud-ubuntu-upgrade.sh <os-distribution> <image-tag>"
6-
exit 2
6+
echo "Usage: scan-images.sh <os-distribution> <image-tag>"
7+
exit 2
78
fi
89

910
set -u
1011

1112
# Check that trivy is installed
1213
if ! trivy --version; then
13-
echo 'Please install trivy: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.49.1'
14+
echo 'Please install trivy: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.49.1'
1415
fi
1516

17+
# Clear any previous outputs
18+
rm -rf image-scan-output
19+
1620
# Make a fresh output directory
1721
mkdir -p image-scan-output
1822

@@ -22,6 +26,9 @@ docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/$1-*:$2" > $1-
2226
# Make a file of imagename:tag
2327
images=$(grep --invert-match --no-filename ^REPOSITORY $1-scanned-container-images.txt | sed 's/ \+/:/g' | cut -f 1,2 -d:)
2428

29+
# Ensure output files exist
30+
touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt
31+
2532
# If Trivy detects no vulnerabilities, add the image name to clean-images.txt.
2633
# If there are vulnerabilities detected, add it to dirty-images.txt and
2734
# generate a csv summary

0 commit comments

Comments
 (0)