This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
119 lines (99 loc) · 4.29 KB
/
agglayer-dev.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: "Build pipeline for agglayer-dev"
on:
push:
branches:
- DEVOPS-2546/dev-deploy
env:
PROJECT_ID: "prj-polygonlabs-shared-dev"
GAR_LOCATION: "europe-west2"
WIF_PROVIDER: "projects/595403903631/locations/global/workloadIdentityPools/build-pipeline-pool/providers/buildpipeline"
WIF_SERVICE_ACCOUNT: "gcp-apps-build-pipeline-sa@prj-polygonlabs-shared-dev.iam.gserviceaccount.com"
CRITICAL_COUNT: 5
IMAGE_NAME: "europe-west2-docker.pkg.dev/prj-polygonlabs-shared-dev/polygonlabs-docker-dev/agglayer"
ATTESTOR_PROJECT_ID: "prj-polygonlabs-shared-dev"
KEY_RING: "gcp-apps-build-pipeline-ring"
KEY: "gcp-apps-build-pipeline-key"
ATTESTOR: "gcp-apps-build-pipeline-attestor"
jobs:
build-pipeline:
name: "Build pipeline for agglayer-dev"
permissions:
contents: "write"
id-token: "write"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/setup-gcloud@v1
- id: auth
uses: google-github-actions/auth@v1
with:
token_format: "access_token"
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}
- id: docker-auth
uses: docker/login-action@v1
with:
username: "oauth2accesstoken"
password: ${{ steps.auth.outputs.access_token }}
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
- id: build-docker-image
run: |-
docker build -t "${{ env.DOCKER_IMAGE }}:${{ github.sha }}" -f ${{ env.DOCKERFILE_NAME }} ${{ env.DOCKERFILE_PATH }}
shell: bash
- id: push-docker-image
run: |-
docker push "${{ env.DOCKER_IMAGE }}:${{ github.sha }}"
shell: bash
- id: scan-vulnerabilities
run: |-
(gcloud artifacts docker images scan "${{ env.DOCKER_IMAGE }}:${{ github.sha }}" --format="value(response.scan)" --remote --quiet) > ./scan_id.txt
shell: bash
- id: check-critical-vulnerabilities
run: |-
#!/bin/bash
# Check if the scan_id.txt file exists
if [ ! -f ./scan_id.txt ]; then
echo "Error: scan_id.txt not found."
exit 1
fi
# Use gcloud to list vulnerabilities and check for CRITICAL severity
severity=$(gcloud artifacts docker images list-vulnerabilities \
"$(cat ./scan_id.txt)" \
--format="value(vulnerability.effectiveSeverity)")
# Check if CRITICAL vulnerability is found
chk=$(echo "$severity" | grep -c "CRITICAL")
if [ "$chk" -gt ${{ env.CRITICAL_COUNT }} ]; then
echo "Failed vulnerability check for CRITICAL level"
exit 1
else
echo "No CRITICAL vulnerability found. Congratulations!"
exit 0
fi
shell: bash
- id: sign-docker-image
run: |-
export CLOUDSDK_CORE_DISABLE_PROMPTS=1
gcloud components install beta --quiet
DIGEST=$(gcloud container images describe ${{ env.DOCKER_IMAGE }}:${{ github.sha }} --format='get(image_summary.digest)')
gcloud beta container binauthz attestations sign-and-create \
--artifact-url="${{ env.DOCKER_IMAGE }}@${DIGEST}" \
--attestor="${{ env.ATTESTOR }}" \
--attestor-project="${{ env.ATTESTOR_PROJECT }}" \
--keyversion-project="${{ env.KEYVERSION_PROJECT }}" \
--keyversion-location="${{ env.KEYVERSION_LOCATION }}" \
--keyversion-keyring="${{ env.KEYVERSION_KEYRING }}" \
--keyversion-key="${{ env.KEYVERSION_KEY }}" \
--keyversion="1"
shell: bash
- id: update-helm-values
run: |-
DIGEST=$(gcloud container images describe ${{ env.DOCKER_IMAGE }}:${{ github.sha }} \
--format='get(image_summary.digest)')
sed -i "s|image:.*|image: ${{ env.DOCKER_IMAGE }}@${DIGEST}|" ${{ env.HELM_VALUES_PATH }}
shell: bash
- id: push-back
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply automatic changes to Update image repository in Helm values
file_pattern: ${{ env.HELM_VALUES_PATH }}