Skip to content

Commit 6477ed4

Browse files
authored
RHOAIENG-16076: tests(gha): pre-pull trivy vulnerabilities db to prevent failures to download later (#777)
* RHOAIENG-16076: tests(gha): pre-pull trivy vulnerabilities db to prevent failures to download later * fix from review; use the only true condition to check if trivy should run
1 parent cd16a28 commit 6477ed4

File tree

1 file changed

+52
-29
lines changed

1 file changed

+52
-29
lines changed

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
env:
2323
# GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache
2424
CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache"
25+
TRIVY_VERSION: 0.57.1
2526
# Targets (and their folder) that should be scanned using FS instead of IMAGE scan due to resource constraints
2627
TRIVY_SCAN_FS_JSON: '{}'
2728

@@ -114,34 +115,6 @@ jobs:
114115
systemctl --user start homebrew.podman.service
115116
echo "PODMAN_SOCK=/run/user/${UID}/podman/podman.sock" >> $GITHUB_ENV
116117
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-
145118
- name: "pull_request|schedule: resolve target if Trivy scan should run"
146119
id: resolve-target
147120
if: ${{ fromJson(inputs.github).event_name == 'pull_request' || fromJson(inputs.github).event_name == 'schedule' }}
@@ -176,10 +149,57 @@ jobs:
176149
echo "Trivy scan won't run"
177150
fi
178151
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+
179200
- name: Run Trivy vulnerability scanner
180201
if: ${{ steps.resolve-target.outputs.target }}
181202
run: |
182-
TRIVY_VERSION=0.53.0
183203
REPORT_FOLDER=${{ github.workspace }}/report
184204
REPORT_FILE=trivy-report.md
185205
REPORT_TEMPLATE=trivy-markdown.tpl
@@ -205,9 +225,12 @@ jobs:
205225
podman run --rm \
206226
$PODMAN_ARGS \
207227
-v ${REPORT_FOLDER}:/report \
228+
-v ${PWD}/trivy_db:/cache \
208229
docker.io/aquasec/trivy:$TRIVY_VERSION \
230+
--cache-dir /cache \
209231
$SCAN_TYPE \
210232
$SCAN_ARGS \
233+
--skip-db-update \
211234
--scanners vuln --ignore-unfixed \
212235
--exit-code 0 --timeout 30m \
213236
--format template --template "@/report/$REPORT_TEMPLATE" -o /report/$REPORT_FILE \

0 commit comments

Comments
 (0)