Skip to content

Commit ef4533f

Browse files
committed
Backport image scan patch
1 parent 9953157 commit ef4533f

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: Create output for `runs-on` variable
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
runner_env:
8+
description: 'The environment input from caller workflow'
9+
default: 'SMS Lab'
10+
required: True
11+
type: string
12+
outputs:
13+
runner_name_image_build:
14+
description: "Image builder runner name"
15+
value: ${{ jobs.define_runner.outputs.image-build-runner }}
16+
runner_name_container_image_build:
17+
description: "Container image build runner name"
18+
value: ${{ jobs.define_runner.outputs.container-image-build-runner }}
19+
runner_name_aio:
20+
description: "AiO runner name"
21+
value: ${{ jobs.define_runner.outputs.aio-runner }}
22+
23+
jobs:
24+
define_runner:
25+
environment: ${{ inputs.runner_env }}
26+
runs-on: ubuntu-latest
27+
outputs:
28+
image-build-runner: ${{ steps.builder-runner.outputs.runner_name_image_build }}
29+
container-image-build-runner: ${{ steps.container-image-build-runner.outputs.runner_name_container_image_build }}
30+
aio-runner: ${{ steps.aio-runner.outputs.runner_name_aio }}
31+
steps:
32+
- name: Set output for image builder runner
33+
run: echo "Setting runner for ${{ inputs.runner_env }} -> ${{ vars.RUNS_ON_TARGET_IMAGE_BUILDER }}"
34+
35+
- id: builder-runner
36+
run: echo "runner_name_image_build=${{ vars.RUNS_ON_TARGET_IMAGE_BUILDER }}" >> $GITHUB_OUTPUT
37+
38+
- name: Set output for container image build runner
39+
run: echo "Setting runner for ${{ inputs.runner_env }} -> ${{ vars.RUNS_ON_TARGET_CONTAINER_IMAGE_BUILDER }}"
40+
41+
- id: container-image-build-runner
42+
run: echo "runner_name_container_image_build=${{ vars.RUNS_ON_TARGET_CONTAINER_IMAGE_BUILDER }}" >> $GITHUB_OUTPUT
43+
44+
- name: Set output for aio runner
45+
run: echo "Setting runner for ${{ inputs.runner_env }} -> ${{ vars.RUNS_ON_TARGET_AIO }}"
46+
47+
- id: aio-runner
48+
run: echo "runner_name_aio=${{ vars.RUNS_ON_TARGET_AIO }}" >> $GITHUB_OUTPUT

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,45 @@ jobs:
101101
run: |
102102
echo "${{ steps.datetime_tag.outputs.datetime_tag }}"
103103
104+
# Dynamically define job matrix.
105+
# We need a separate matrix entry for each distribution, when the relevant input is true.
106+
# https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
107+
# NOTE(bbezak): Both amd64 and aarch64 need to be built in a single workflow to create a multi-architecture manifest.
108+
# For now include only RL9 in aarch64
109+
- name: Generate build matrix
110+
id: set-matrix
111+
run: |
112+
output="{'distro': ["
113+
if [[ ${{ inputs.rocky-linux-9 }} == 'true' ]]; then
114+
output+="{'name': 'rocky', 'release': 9, 'arch': 'amd64'},"
115+
output+="{'name': 'rocky', 'release': 9, 'arch': 'aarch64'},"
116+
fi
117+
if [[ ${{ inputs.ubuntu-jammy }} == 'true' ]]; then
118+
output+="{'name': 'ubuntu', 'release': 'jammy', 'arch': 'amd64'},"
119+
fi
120+
if [[ ${{ inputs.ubuntu-noble }} == 'true' ]]; then
121+
output+="{'name': 'ubuntu', 'release': 'noble', 'arch': 'amd64'},"
122+
fi
123+
# remove trailing comma
124+
output="${output%,}"
125+
output+="]}"
126+
echo "matrix=$output" >> $GITHUB_OUTPUT
127+
128+
- name: Display container datetime tag
129+
run: |
130+
echo "${{ steps.datetime_tag.outputs.datetime_tag }}"
131+
132+
runner-selection:
133+
uses: ./.github/workflows/runner-selector.yml
134+
with:
135+
runner_env: ${{ inputs.runner_env }}
136+
104137
container-image-build:
105138
name: Build Kolla container images
106139
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
107-
runs-on: arc-skc-container-image-builder-runner
140+
runs-on: ${{ matrix.distro.arch == 'aarch64'
141+
&& fromJson('["self-hosted","sms","arm64"]')
142+
|| needs.runner-selection.outputs.runner_name_container_image_build }}
108143
timeout-minutes: 720
109144
permissions: {}
110145
strategy:
@@ -144,7 +179,7 @@ jobs:
144179
145180
- name: Install Trivy
146181
run: |
147-
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.49.0
182+
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.67.2
148183
149184
- name: Install yq
150185
run: |
@@ -164,7 +199,7 @@ jobs:
164199
- name: Install Docker Python SDK
165200
run: |
166201
sudo pip install docker 'requests<2.32.0'
167-
202+
168203
- name: Get Kolla tag
169204
id: write-kolla-tag
170205
run: echo "kolla-tag=${{ needs.generate-tag.outputs.openstack_release }}-${{ matrix.distro }}-${{ matrix.distro == 'rocky' && '9' || 'jammy' }}-${{ needs.generate-tag.outputs.datetime_tag }}" >> $GITHUB_OUTPUT

tools/scan-images.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -u
1111

1212
# Check that trivy is installed
1313
if ! trivy --version; then
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'
14+
echo 'Please install trivy: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.67.2'
1515
fi
1616

1717
# Clear any previous outputs
@@ -21,10 +21,12 @@ rm -rf image-scan-output
2121
mkdir -p image-scan-output
2222

2323
# Get built container images
24-
docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/*:$2" > $1-scanned-container-images.txt
24+
images=$(docker image ls \
25+
--filter "reference=ark.stackhpc.com/stackhpc-dev/*:$2*" \
26+
--format "{{.Repository}}:{{.Tag}}")
2527

26-
# Make a file of imagename:tag
27-
images=$(grep --invert-match --no-filename ^REPOSITORY $1-scanned-container-images.txt | sed 's/ \+/:/g' | cut -f 1,2 -d:)
28+
# Save list of images to file
29+
echo "$images" > "$1-scanned-container-images.txt"
2830

2931
# Ensure output files exist
3032
touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt image-scan-output/critical-images.txt

0 commit comments

Comments
 (0)