22
22
env :
23
23
# GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache
24
24
CACHE : " ghcr.io/${{ github.repository }}/workbench-images/build-cache"
25
+ # Targets (and their folder) that should be scanned using FS instead of IMAGE scan due to resource constraints
26
+ TRIVY_SCAN_FS_JSON : ' {"rocm-jupyter-pytorch-ubi9-python-3.9": "jupyter/rocm/pytorch/ubi9-python-3.9"}'
25
27
26
28
steps :
27
29
@@ -113,10 +115,12 @@ jobs:
113
115
114
116
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
115
117
- name : " push|schedule: make ${{ inputs.target }}"
116
- run : " make ${{ inputs.target }}"
118
+ run : |
119
+ SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
120
+ export IMAGE_TAG="${SANITIZED_REF_NAME}_${{ github.sha }}"
121
+ make ${{ inputs.target }}
117
122
if : ${{ fromJson(inputs.github).event_name == 'push' || fromJson(inputs.github).event_name == 'schedule' }}
118
123
env :
119
- IMAGE_TAG : " ${{ github.ref_name }}_${{ github.sha }}"
120
124
IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
121
125
CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
122
126
@@ -138,27 +142,42 @@ jobs:
138
142
- name : " Show podman images information"
139
143
run : podman images
140
144
141
- - name : " pull_request|schedule: resolve image name if Trivy scan should run"
142
- id : resolve-image
145
+ - name : " pull_request|schedule: resolve target if Trivy scan should run"
146
+ id : resolve-target
143
147
if : ${{ fromJson(inputs.github).event_name == 'pull_request' || fromJson(inputs.github).event_name == 'schedule' }}
144
148
env :
145
149
EVENT_NAME : ${{ fromJson(inputs.github).event_name }}
146
150
HAS_TRIVY_LABEL : ${{ contains(fromJson(inputs.github).event.pull_request.labels.*.name, 'trivy-scan') }}
151
+ FS_SCAN_FOLDER : ${{ fromJson(env.TRIVY_SCAN_FS_JSON)[inputs.target] }}
147
152
run : |
148
153
if [[ "$EVENT_NAME" == "pull_request" && "$HAS_TRIVY_LABEL" == "true" ]]; then
149
- IMAGE_NAME="localhost:5000/workbench-images:${{ inputs.target }}-${{ github.sha }}"
150
- echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
154
+ if [[ -n "$FS_SCAN_FOLDER" ]]; then
155
+ TARGET="$FS_SCAN_FOLDER"
156
+ TYPE="fs"
157
+ else
158
+ TARGET="localhost:5000/workbench-images:${{ inputs.target }}-${{ github.sha }}"
159
+ TYPE="image"
160
+ fi
151
161
elif [[ "$EVENT_NAME" == "schedule" ]]; then
152
- IMAGE_NAME="ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}"
153
- echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
162
+ if [[ -n "$FS_SCAN_FOLDER" ]]; then
163
+ TARGET="$FS_SCAN_FOLDER"
164
+ TYPE="fs"
165
+ else
166
+ TARGET="ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}"
167
+ TYPE="image"
168
+ fi
154
169
fi
155
170
156
- if [[ -z "$IMAGE_NAME" ]]; then
171
+ if [[ -n "$TARGET" ]]; then
172
+ echo "target=$TARGET" >> $GITHUB_OUTPUT
173
+ echo "type=$TYPE" >> $GITHUB_OUTPUT
174
+ echo "Trivy scan will run on $TARGET ($TYPE)"
175
+ else
157
176
echo "Trivy scan won't run"
158
177
fi
159
178
160
179
- name : Run Trivy vulnerability scanner
161
- if : ${{ steps.resolve-image .outputs.image }}
180
+ if : ${{ steps.resolve-target .outputs.target }}
162
181
run : |
163
182
TRIVY_VERSION=0.53.0
164
183
REPORT_FOLDER=${{ github.workspace }}/report
@@ -168,22 +187,31 @@ jobs:
168
187
mkdir -p $REPORT_FOLDER
169
188
cp ci/$REPORT_TEMPLATE $REPORT_FOLDER
170
189
171
- IMAGE_NAME=${{ steps.resolve-image.outputs.image }}
172
- echo "Scanning $IMAGE_NAME"
190
+ SCAN_TARGET=${{ steps.resolve-target.outputs.target }}
191
+ SCAN_TYPE=${{ steps.resolve-target.outputs.type }}
192
+ echo "Scanning $SCAN_TARGET ($SCAN_TYPE)"
193
+
194
+ if [[ "$SCAN_TYPE" == "image" ]]; then
195
+ SCAN_ARGS="--image-src podman --podman-host /var/run/podman/podman.sock"
196
+ PODMAN_ARGS="-v ${PODMAN_SOCK}:/var/run/podman/podman.sock"
197
+ elif [[ "$SCAN_TYPE" == "fs" ]]; then
198
+ WORKSPACE_FOLDER="/workspace"
199
+ SCAN_TARGET="$WORKSPACE_FOLDER/$SCAN_TARGET"
200
+ PODMAN_ARGS="-v ${{ github.workspace }}:$WORKSPACE_FOLDER"
201
+ fi
173
202
174
203
# have trivy access podman socket,
175
204
# https://github.com/aquasecurity/trivy/issues/580#issuecomment-666423279
176
205
podman run --rm \
177
- -v ${PODMAN_SOCK}:/var/run/podman/podman.sock \
206
+ $PODMAN_ARGS \
178
207
-v ${REPORT_FOLDER}:/report \
179
208
docker.io/aquasec/trivy:$TRIVY_VERSION \
180
- image \
181
- --image-src podman \
182
- --podman-host /var/run/podman/podman.sock \
209
+ $SCAN_TYPE \
210
+ $SCAN_ARGS \
183
211
--scanners vuln --ignore-unfixed \
184
212
--exit-code 0 --timeout 30m \
185
213
--format template --template "@/report/$REPORT_TEMPLATE" -o /report/$REPORT_FILE \
186
- $IMAGE_NAME
214
+ $SCAN_TARGET
187
215
188
216
cat $REPORT_FOLDER/$REPORT_FILE >> $GITHUB_STEP_SUMMARY
189
217
0 commit comments