Skip to content

Commit 93ee562

Browse files
committed
Backport image scan patch
1 parent 9953157 commit 93ee562

File tree

3 files changed

+84
-14
lines changed

3 files changed

+84
-14
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: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ on:
3838
type: boolean
3939
required: false
4040
default: false
41+
runner_env:
42+
description: Which cloud to run on?
43+
type: choice
44+
default: SMS Lab
45+
options:
46+
- SMS Lab
47+
- Leafcloud
4148

4249
env:
4350
ANSIBLE_FORCE_COLOR: True
@@ -82,29 +89,42 @@ jobs:
8289
# Dynamically define job matrix.
8390
# We need a separate matrix entry for each distribution, when the relevant input is true.
8491
# https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
92+
# NOTE(bbezak): Both amd64 and aarch64 need to be built in a single workflow to create a multi-architecture manifest.
93+
# For now include only RL9 in aarch64
8594
- name: Generate build matrix
8695
id: set-matrix
8796
run: |
88-
comma=""
89-
echo -n "matrix={\"distro\": [" >> $GITHUB_OUTPUT
97+
output="{'distro': ["
9098
if [[ ${{ inputs.rocky-linux-9 }} == 'true' ]]; then
91-
echo -n "$comma\"rocky\"" >> $GITHUB_OUTPUT
92-
comma=", "
99+
output+="{'name': 'rocky', 'release': 9, 'arch': 'amd64'},"
100+
output+="{'name': 'rocky', 'release': 9, 'arch': 'aarch64'},"
93101
fi
94102
if [[ ${{ inputs.ubuntu-jammy }} == 'true' ]]; then
95-
echo -n "$comma\"ubuntu\"" >> $GITHUB_OUTPUT
96-
comma=", "
103+
output+="{'name': 'ubuntu', 'release': 'jammy', 'arch': 'amd64'},"
97104
fi
98-
echo "]}" >> $GITHUB_OUTPUT
105+
if [[ ${{ inputs.ubuntu-noble }} == 'true' ]]; then
106+
output+="{'name': 'ubuntu', 'release': 'noble', 'arch': 'amd64'},"
107+
fi
108+
# remove trailing comma
109+
output="${output%,}"
110+
output+="]}"
111+
echo "matrix=$output" >> $GITHUB_OUTPUT
99112
100113
- name: Display container datetime tag
101114
run: |
102115
echo "${{ steps.datetime_tag.outputs.datetime_tag }}"
103116
117+
runner-selection:
118+
uses: ./.github/workflows/runner-selector.yml
119+
with:
120+
runner_env: ${{ inputs.runner_env }}
121+
104122
container-image-build:
105123
name: Build Kolla container images
106124
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
107-
runs-on: arc-skc-container-image-builder-runner
125+
runs-on: ${{ matrix.distro.arch == 'aarch64'
126+
&& fromJson('["self-hosted","sms","arm64"]')
127+
|| needs.runner-selection.outputs.runner_name_container_image_build }}
108128
timeout-minutes: 720
109129
permissions: {}
110130
strategy:
@@ -144,7 +164,7 @@ jobs:
144164
145165
- name: Install Trivy
146166
run: |
147-
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.49.0
167+
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.67.2
148168
149169
- name: Install yq
150170
run: |
@@ -164,7 +184,7 @@ jobs:
164184
- name: Install Docker Python SDK
165185
run: |
166186
sudo pip install docker 'requests<2.32.0'
167-
187+
168188
- name: Get Kolla tag
169189
id: write-kolla-tag
170190
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)