Skip to content

Commit 4c92f5f

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

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

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

Lines changed: 36 additions & 26 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:
@@ -175,7 +176,7 @@ jobs:
175176
id: build_overcloud_images
176177
continue-on-error: true
177178
run: |
178-
args="${{ github.event.inputs.regexes }}"
179+
args="${{ inputs.regexes }}"
179180
args="$args -e kolla_base_distro=${{ matrix.distro }}"
180181
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
181182
args="$args -e stackhpc_repo_mirror_auth_proxy_enabled=true"
@@ -184,7 +185,7 @@ jobs:
184185
kayobe overcloud container image build $args
185186
env:
186187
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
187-
if: github.event.inputs.overcloud == 'true'
188+
if: inputs.overcloud
188189

189190
- name: Build kolla seed images
190191
id: build_seed_images
@@ -198,7 +199,7 @@ jobs:
198199
kayobe seed container image build $args
199200
env:
200201
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
201-
if: github.event.inputs.seed == 'true'
202+
if: inputs.seed
202203

203204
- name: Get built container images
204205
run: |
@@ -208,57 +209,66 @@ jobs:
208209
run: if [ $(wc -l < ${{ matrix.distro }}-container-images) -le 1 ]; then exit 1; fi
209210

210211
- 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
212+
run: |
213+
src/kayobe-config/tools/scan-images.sh ${{ matrix.distro }} ${{ needs.generate-tag.outputs.kolla_tag }}
219214
220215
- name: Fail if no images have passed scanning
221-
run: if [ $(wc -l < image-scan-output/clean-images.txt) -le 0 ]; then exit 1; fi
222-
if: github.event.inputs.scan-push == 'false'
216+
run: if [ $(wc -l < image-scan-output/clean-images.txt) -le 0 ]; then exit 1; else cp image-scan-output/clean-images.txt image-scan-output/pushed-images.txt; fi
217+
if: inputs.push-dirty == 'False'
223218

224-
- name: Append dirty images to clean list
219+
- name: Append dirty images to push list
225220
run: |
226-
cat image-scan-output/dirty-images.txt >> image-scan-output/clean-images.txt
227-
if: github.event.inputs.scan-push == 'true'
221+
cp image-scan-output/clean-images.txt image-scan-output/pushed-images.txt
222+
cat image-scan-output/dirty-images.txt >> image-scan-output/pushed-images.txt
223+
if: inputs.push-dirty
228224

229225
- name: Push images
230226
run: |
227+
touch image-scan-output/push-failed-images.txt
231228
source venvs/kayobe/bin/activate &&
232229
source src/kayobe-config/kayobe-env --environment ci-builder &&
233230
kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml &&
234231
235232
while read -r image; do
236233
# Retries!
237-
for i in {1..10}; do
238-
docker push ${image} && break || sleep 5
234+
for i in {1..5}; do
235+
if docker push $image; then
236+
echo "Pushed $image"
237+
break
238+
elif $i == 5; then
239+
echo "Failed to push $image"
240+
echo $image >> image-scan-output/push-failed-images.txt
241+
else
242+
echo "Failed on retry $i"
243+
sleep 5
244+
fi;
239245
done
240-
done < image-scan-output/clean-images.txt
246+
done < image-scan-output/pushed-images.txt &&
247+
mv image-scan-output image-build-logs
241248
shell: bash
242249
env:
243250
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
244-
if: github.event.inputs.push == 'true'
251+
if: inputs.push
245252

246-
- name: Upload pushed container images artifact
253+
- name: Upload output artifact
247254
uses: actions/upload-artifact@v4
248255
with:
249-
name: ${{ matrix.distro }}-pushed-container-images
250-
path: image-scan-output/clean-images.txt
256+
name: ${{ matrix.distro }}-logs
257+
path: image-build-logs
251258
retention-days: 7
252259

253260
- name: Fail when images failed to build
254261
run: exit 1
255262
if: steps.build_overcloud_images.outcome == 'failure' || steps.build_seed_images.outcome == 'failure'
256263

264+
- name: Fail when images failed to push
265+
run: if [ $(wc -l < image-build-logs/push-failed-images.txt) -gt 0 ]; then exit 1; fi
266+
257267
sync-container-repositories:
258268
name: Trigger container image repository sync
259269
needs:
260270
- container-image-build
261-
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push == 'true'
271+
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push
262272
runs-on: ubuntu-latest
263273
permissions: {}
264274
steps:
@@ -267,7 +277,7 @@ jobs:
267277
- name: Trigger container image repository sync
268278
run: |
269279
filter='${{ inputs.regexes }}'
270-
if [[ -n $filter ]] && [[ ${{ github.event.inputs.seed }} == 'true' ]]; then
280+
if [[ -n $filter ]] && [[ ${{ inputs.seed }} == 'true' ]]; then
271281
filter="$filter bifrost"
272282
fi
273283
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)