Skip to content

Commit 1a9ab2e

Browse files
committed
Correct workflow syntax
1 parent dd34768 commit 1a9ab2e

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

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

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ on:
4343
type: boolean
4444
required: false
4545
default: true
46-
scan-upload:
47-
description: Upload scanned images that have vulnerabilities?
46+
scan-push:
47+
description: Push scanned images that have vulnerabilities?
4848
type: boolean
4949
required: false
5050
default: true
@@ -135,11 +135,6 @@ jobs:
135135
run: |
136136
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.44.0
137137
138-
- name: Install jq
139-
run: |
140-
curl --output /usr/local/bin/jq -sfL https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64
141-
chmod +x /usr/local/bin/jq
142-
143138
- name: Setup networking
144139
run: |
145140
if ! ip l show breth1 >/dev/null 2>&1; then
@@ -186,7 +181,7 @@ jobs:
186181
env:
187182
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
188183

189-
- name: Build and push kolla overcloud images
184+
- name: Build kolla overcloud images
190185
run: |
191186
args="${{ github.event.inputs.regexes }}"
192187
args="$args -e kolla_base_distro=${{ matrix.distro }}"
@@ -198,7 +193,7 @@ jobs:
198193
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
199194
if: github.event.inputs.overcloud == 'true'
200195

201-
- name: Build and push kolla seed images
196+
- name: Build kolla seed images
202197
run: |
203198
args="kolla_base_distro=${{ matrix.distro }}"
204199
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
@@ -222,40 +217,57 @@ jobs:
222217

223218
- name: Generate list of images to scan/push
224219
run: |
220+
# Clean up any stale data
221+
rm -rf ${{ matrix.distro }}-docker-images.txt
222+
225223
# Make a file of imagename:tag
226224
grep --invert-match --no-filename ^REPOSITORY ${{ matrix.distro }}-container-images |\
227225
sed 's/ \+/:/g' |\
228-
cut -f 1,2 -d: > docker-images.txt
226+
cut -f 1,2 -d: > ${{ matrix.distro }}-docker-images.txt
229227
230228
- name: Scan built container images
231229
run: |
232230
set -euo pipefail
233-
mkdir -p image-scan-output
234231
232+
# Clean any stale data
233+
rm -rf ${{ matrix.distro }}-image-scan-output
235234
rm -f images-to-push.txt
236235
236+
# Make a fresh output directory
237+
mkdir -p ${{ matrix.distro }}-image-scan-output
238+
237239
# If Trivy detects no vulnerabilities, add the image name to images-to-push.txt.
238240
# If there are vulnerabilities detected, generate a CSV summary and do not add to
239241
# images-to-push.txt.
240242
while read -r image; do
241243
filename=$(basename $image | sed 's/:/\./g')
242244
if $(trivy image \
245+
--quiet \
243246
--exit-code 1 \
244247
--scanners vuln \
245248
--format json \
246249
--severity HIGH,CRITICAL \
247-
--output image-scan-output/${filename}.json \
250+
--output ${{ matrix.distro }}-image-scan-output/${filename}.json \
248251
--ignore-unfixed \
249252
$image); then
250-
echo "${image}" >> images-to-push.txt
251-
rm image-scan-output/${filename}.json
253+
# Clean up the output file for any images with no vulnerabilities
254+
rm -f ${{ matrix.distro }}-image-scan-output/${filename}.json
255+
256+
# Add the image to the list to push
257+
echo "${image}" >> ${{ matrix.distro }}-images-to-push.txt
252258
else
253-
if [${{github.event.input.scan-upload}} == 'true' ]; then
254-
echo "${image}" >> images-to-push.txt
259+
# Still add the image to the list to push if we're ignoring fails
260+
if [ "${{github.event.inputs.scan-push}}" == "true" ]; then
261+
echo "${image}" >> ${{ matrix.distro }}-images-to-push.txt
255262
fi
256263
257-
echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > image-scan-output/${filename}.csv
258-
jq -r '.Results[].Vulnerabilities
264+
# Write a header for the summary CSV
265+
echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > ${{ matrix.distro }}-image-scan-output/${filename}.summary.csv
266+
267+
# Write the summary CSV data
268+
jq -r '.Results[]
269+
| select(.Vulnerabilities)
270+
| .Vulnerabilities
259271
# Ignore packages with "kernel" in the PkgName
260272
| map(select(.PkgName | test("kernel") | not ))
261273
| group_by(.VulnerabilityID)
@@ -271,37 +283,40 @@ jobs:
271283
]
272284
)
273285
| .[]
274-
| @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv
286+
| @csv' ${{ matrix.distro }}-image-scan-output/${filename}.json >> ${{ matrix.distro }}-image-scan-output/${filename}.summary.csv
275287
fi
276-
done < docker-images.txt
277-
mv images-to-push.txt docker-images.txt
288+
done < ${{ matrix.distro }}-docker-images.txt
289+
290+
# Rename the file of vulnerability scanned images so that it can
291+
# be consumed by the docker push step
292+
mv ${{ matrix.distro }}-images-to-push.txt ${{ matrix.distro }}-docker-images.txt
278293
shell: bash
279294
if: github.event.inputs.scan == 'true'
280295

281296
- name: Upload Trivy scan artefacts
282297
uses: actions/upload-artifact@v3
283298
with:
284-
name: "trivy-scan-output"
285-
path: |
286-
'image-scan-output/*.json'
287-
'image-scan-output/*.summary.csv'
299+
name: ${{ matrix.distro }}-image-scan-output
300+
path: ${{ matrix.distro }}-image-scan-output
288301
retention-days: 7
289-
if: github.event.inputs.scan == 'true'
302+
if: always()
290303

291304
- name: Push images
292305
run: |
293306
source venvs/kayobe/bin/activate &&
294307
source src/kayobe-config/kayobe-env --environment ci-builder &&
295-
kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml
308+
kayobe playbook run --become ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml
296309
297310
while read -r image; do
298311
# Retries!
299312
for i in {1..10}; do
300-
docker push ${image} && break || sleep 5
313+
sudo docker push ${image} && break || sleep 2
301314
done
302-
done < docker-images.txt
315+
done < ${{ matrix.distro }}-docker-images.txt
303316
shell: bash
304-
if: ${{ inputs.push }}
317+
env:
318+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
319+
if: github.event.inputs.push == 'true'
305320

306321
- name: Prune local Kolla container images over 1 week old
307322
run: |

etc/kayobe/ansible/docker-registry-login.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
- name: Login to docker registry
23
gather_facts: false
34
hosts: container-image-builders
@@ -7,4 +8,4 @@
78
registry_url: "{{ kolla_docker_registry or omit }}"
89
username: "{{ kolla_docker_registry_username }}"
910
password: "{{ kolla_docker_registry_password }}"
10-
reauthorize: yes
11+
reauthorize: yes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
# Used in CI workflow
33
dev_tools_packages_extra:
4-
- jq
4+
- jq

0 commit comments

Comments
 (0)