Skip to content

Commit 3656c90

Browse files
committed
add delay mechanism for trivy scan job
1 parent 945056a commit 3656c90

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

.github/workflows/trivy-security-scan.yml

+31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,38 @@ on:
1010
types: [trivy-scan-dispatch]
1111

1212
jobs:
13+
wait-for-image:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
image-available: ${{ steps.check-image.outputs.available }}
17+
steps:
18+
- name: Check Docker image availability with retry
19+
run: |
20+
image="ghcr.io/${{ github.repository_owner }}/${{ github.event.client_payload.image }}:${{ github.event.client_payload.sha }}"
21+
timeout=900 # Timeout in seconds (15 minutes)
22+
interval=300 # Interval between retries in seconds (5 minutes)
23+
retry_limit=5 # Number of retries
24+
attempt=0
25+
26+
while ! docker pull $image; do
27+
attempt=$((attempt + 1))
28+
if [ "$attempt" -gt "$retry_limit" ]; then
29+
echo "Image $image is not available after $retry_limit attempts."
30+
echo "::set-output name=available::false"
31+
exit 1
32+
fi
33+
34+
echo "Attempt $attempt: Waiting for $image to be available. Retrying in $interval seconds..."
35+
sleep $interval
36+
done
37+
38+
echo "$image is now available."
39+
echo "::set-output name=available::true"
40+
shell: bash
41+
1342
trivy_scan_image:
43+
needs: wait-for-image
44+
if: needs.wait-for-image.outputs.image-available == 'true'
1445
runs-on: ubuntu-latest
1546
strategy:
1647
matrix:

0 commit comments

Comments
 (0)