Skip to content

Commit

Permalink
trivy scanning improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Sep 24, 2024
1 parent 55c4544 commit 39f0c49
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin
- name: Trivy Scanning with Retry
- name: Trivy Scanning
run: |
# Enable exit on error
set -e
# Disable exit on error for the retry logic
set +e
# Retry logic for Trivy
max_retries=5
Expand All @@ -48,24 +48,31 @@ jobs:
while [ $attempt -le $max_retries ]; do
echo "Running Trivy scan, attempt $attempt..."

# Run the Trivy scan and capture the exit status
trivy image --severity CRITICAL --exit-code 1 --quiet udx-worker/udx-worker:latest | tee trivy.log | grep -v 'INFO'
scan_exit_code=$?

# Check for CRITICAL vulnerabilities
if grep -E "Total: [1-9]" trivy.log; then
echo "CRITICAL vulnerabilities detected!"
exit 1
else
fi

# Check if Trivy exited with an error
if [ $scan_exit_code -eq 0 ]; then
echo "No CRITICAL vulnerabilities found."
success=true
break
else
echo "Trivy scan failed, retrying in 2 minutes..."
sleep 120
attempt=$((attempt+1))
fi

# If the attempt fails, wait for 2 minutes before retrying
echo "Trivy scan failed, retrying in 2 minutes..."
sleep 120
attempt=$((attempt+1))
done

# If all retries fail, exit with an error
if [ "$success" = false ]; then
echo "Failed to complete Trivy scan after $max_retries attempts."
exit 1
fi
fi

0 comments on commit 39f0c49

Please sign in to comment.