Skip to content

Commit fda30aa

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

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

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

Lines changed: 43 additions & 25 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,74 @@ 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
221216
run: if [ $(wc -l < image-scan-output/clean-images.txt) -le 0 ]; then exit 1; fi
222-
if: github.event.inputs.scan-push == 'false'
217+
if: ${{ !inputs.push-dirty }}
218+
219+
- name: Copy clean images to push-attempt-images list
220+
run: cp image-scan-output/clean-images.txt image-scan-output/push-attempt-images.txt
223221

224-
- name: Append dirty images to clean list
222+
- name: Append dirty images to push list
225223
run: |
226-
cat image-scan-output/dirty-images.txt >> image-scan-output/clean-images.txt
227-
if: github.event.inputs.scan-push == 'true'
224+
cat image-scan-output/dirty-images.txt >> image-scan-output/push-attempt-images.txt
225+
if: inputs.push-dirty
228226

229227
- name: Push images
230228
run: |
229+
touch image-scan-output/push-failed-images.txt
231230
source venvs/kayobe/bin/activate &&
232231
source src/kayobe-config/kayobe-env --environment ci-builder &&
233232
kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml &&
234233
235234
while read -r image; do
236235
# Retries!
237-
for i in {1..10}; do
238-
docker push ${image} && break || sleep 5
236+
for i in {1..5}; do
237+
if docker push $image; then
238+
echo "Pushed $image"
239+
break
240+
elif $i == 5; then
241+
echo "Failed to push $image"
242+
echo $image >> image-scan-output/push-failed-images.txt
243+
else
244+
echo "Failed on retry $i"
245+
sleep 5
246+
fi;
239247
done
240-
done < image-scan-output/clean-images.txt
248+
done < image-scan-output/push-attempt-images.txt &&
249+
mv image-scan-output image-build-logs
241250
shell: bash
242251
env:
243252
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
244-
if: github.event.inputs.push == 'true'
253+
if: inputs.push
245254

246-
- name: Upload pushed container images artifact
255+
- name: Upload output artifact
247256
uses: actions/upload-artifact@v4
248257
with:
249-
name: ${{ matrix.distro }}-pushed-container-images
250-
path: image-scan-output/clean-images.txt
258+
name: ${{ matrix.distro }}-logs
259+
path: image-build-logs
251260
retention-days: 7
261+
if: !cancelled()
252262

253263
- name: Fail when images failed to build
254264
run: exit 1
255265
if: steps.build_overcloud_images.outcome == 'failure' || steps.build_seed_images.outcome == 'failure'
256266

267+
- name: Fail when images failed to push
268+
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
269+
if: !cancelled()
270+
271+
- name: Fail when images failed scanning
272+
run: if [ $(wc -l < image-build-logs/dirty-images.txt) -gt 0 ]; then cat image-build-logs/dirty-images.txt && exit 1; fi
273+
if: ${{ !inputs.push-dirty && !cancelled() }}
274+
257275
sync-container-repositories:
258276
name: Trigger container image repository sync
259277
needs:
260278
- container-image-build
261-
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push == 'true'
279+
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push
262280
runs-on: ubuntu-latest
263281
permissions: {}
264282
steps:
@@ -267,7 +285,7 @@ jobs:
267285
- name: Trigger container image repository sync
268286
run: |
269287
filter='${{ inputs.regexes }}'
270-
if [[ -n $filter ]] && [[ ${{ github.event.inputs.seed }} == 'true' ]]; then
288+
if [[ -n $filter ]] && [[ ${{ inputs.seed }} == 'true' ]]; then
271289
filter="$filter bifrost"
272290
fi
273291
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)