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
+ TRIVY_VERSION : 0.57.1
25
26
# Targets (and their folder) that should be scanned using FS instead of IMAGE scan due to resource constraints
26
27
TRIVY_SCAN_FS_JSON : ' {}'
27
28
@@ -114,34 +115,6 @@ jobs:
114
115
systemctl --user start homebrew.podman.service
115
116
echo "PODMAN_SOCK=/run/user/${UID}/podman/podman.sock" >> $GITHUB_ENV
116
117
117
- # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
118
- - name : " push|schedule: make ${{ inputs.target }}"
119
- run : |
120
- SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
121
- export IMAGE_TAG="${SANITIZED_REF_NAME}_${{ github.sha }}"
122
- make ${{ inputs.target }}
123
- if : ${{ fromJson(inputs.github).event_name == 'push' || fromJson(inputs.github).event_name == 'schedule' }}
124
- env :
125
- IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
126
- CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
127
- # dependent images were already built and pushed, so just let podman pull it
128
- BUILD_DEPENDENT_IMAGES : " no"
129
-
130
- # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
131
- - name : " pull_request: make ${{ inputs.target }}"
132
- run : |
133
- make ${{ inputs.target }}
134
- if : " ${{ fromJson(inputs.github).event_name == 'pull_request' }}"
135
- env :
136
- IMAGE_TAG : " ${{ github.sha }}"
137
- IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
138
- CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }}"
139
- # We don't have access to image registry, so disable pushing
140
- PUSH_IMAGES : " no"
141
-
142
- - name : " Show podman images information"
143
- run : podman images --digests
144
-
145
118
- name : " pull_request|schedule: resolve target if Trivy scan should run"
146
119
id : resolve-target
147
120
if : ${{ fromJson(inputs.github).event_name == 'pull_request' || fromJson(inputs.github).event_name == 'schedule' }}
@@ -176,10 +149,57 @@ jobs:
176
149
echo "Trivy scan won't run"
177
150
fi
178
151
152
+ # only one db can be downloaded in one call https://github.com/aquasecurity/trivy/issues/3616
153
+ - name : Pre-pull Trivy vulnerabilities DB
154
+ if : ${{ steps.resolve-target.outputs.target }}
155
+ run : |
156
+ mkdir trivy_db
157
+ podman run --rm \
158
+ --env PODMAN_SOCK \
159
+ -v ${PWD}/trivy_db:/cache \
160
+ docker.io/aquasec/trivy:$TRIVY_VERSION \
161
+ --cache-dir /cache \
162
+ image \
163
+ --download-db-only
164
+ podman run --rm \
165
+ --env PODMAN_SOCK \
166
+ -v ${PWD}/trivy_db:/cache \
167
+ docker.io/aquasec/trivy:$TRIVY_VERSION \
168
+ --cache-dir /cache \
169
+ image \
170
+ --download-java-db-only
171
+
172
+ # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
173
+ - name : " push|schedule: make ${{ inputs.target }}"
174
+ run : |
175
+ SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
176
+ export IMAGE_TAG="${SANITIZED_REF_NAME}_${{ github.sha }}"
177
+ make ${{ inputs.target }}
178
+ if : ${{ fromJson(inputs.github).event_name == 'push' || fromJson(inputs.github).event_name == 'schedule' }}
179
+ env :
180
+ IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
181
+ CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
182
+ # dependent images were already built and pushed, so just let podman pull it
183
+ BUILD_DEPENDENT_IMAGES : " no"
184
+
185
+ # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
186
+ - name : " pull_request: make ${{ inputs.target }}"
187
+ run : |
188
+ make ${{ inputs.target }}
189
+ if : " ${{ fromJson(inputs.github).event_name == 'pull_request' }}"
190
+ env :
191
+ IMAGE_TAG : " ${{ github.sha }}"
192
+ IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
193
+ CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }}"
194
+ # We don't have access to image registry, so disable pushing
195
+ PUSH_IMAGES : " no"
196
+
197
+ - name : " Show podman images information"
198
+ run : podman images --digests
199
+
179
200
- name : Run Trivy vulnerability scanner
180
201
if : ${{ steps.resolve-target.outputs.target }}
181
202
run : |
182
- TRIVY_VERSION=0.53.0
183
203
REPORT_FOLDER=${{ github.workspace }}/report
184
204
REPORT_FILE=trivy-report.md
185
205
REPORT_TEMPLATE=trivy-markdown.tpl
@@ -205,9 +225,12 @@ jobs:
205
225
podman run --rm \
206
226
$PODMAN_ARGS \
207
227
-v ${REPORT_FOLDER}:/report \
228
+ -v ${PWD}/trivy_db:/cache \
208
229
docker.io/aquasec/trivy:$TRIVY_VERSION \
230
+ --cache-dir /cache \
209
231
$SCAN_TYPE \
210
232
$SCAN_ARGS \
233
+ --skip-db-update \
211
234
--scanners vuln --ignore-unfixed \
212
235
--exit-code 0 --timeout 30m \
213
236
--format template --template "@/report/$REPORT_TEMPLATE" -o /report/$REPORT_FILE \
0 commit comments