-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (65 loc) · 2.25 KB
/
build-and-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Build and Test Docker Image
on:
push:
branches-ignore:
- latest
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run Development Pipeline
run: make dev-pipeline
working-directory: .
- name: Cache Trivy DB
uses: actions/cache@v4
with:
path: ~/.cache/trivy
key: ${{ runner.os }}-trivy-db-${{ github.sha }}
restore-keys: |
${{ runner.os }}-trivy-db-
- name: Install Trivy
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin
- name: Trivy Scanning
run: |
export TRIVY_DISABLE_VEX_NOTICE=true
# Disable exit on error for the retry logic
set +e
# Retry logic for Trivy
max_retries=5
attempt=1
success=false
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
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
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