-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (210 loc) · 13.7 KB
/
build-frontend.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Build Frontend
on:
push:
branches:
- dev
- main
tags:
- 'r-*'
pull_request:
branches:
- dev
- main
jobs:
build:
name: Build Frontend
runs-on: ubuntu-latest
if: ((github.ref == 'refs/heads/dev') || (github.base_ref == 'main') || (github.base_ref == 'dev'))
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
# Checkout the current working code base
- name: Checkout working branch
uses: actions/checkout@v4
# Installs the correct Node version for the project
- name: Setup Node.js for use with actions
uses: actions/setup-node@v4
with:
node-version: 20
- name: Build frontend (includes Node package install)
run: |
npm ci --include=dev
npm run build:production
deploy_with_tekton:
name: Monitor Dev Deployment
environment: dev
runs-on: ubuntu-latest
if: ((github.ref == 'refs/heads/dev') && (github.event_name != 'pull_request') && (github.actor != 'dependabot[bot]'))
needs: build
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.FPCC_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.FPCC_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup kubectl"
run: |
aws eks update-kubeconfig --name ${{ secrets.FV_CLUSTER_NAME }} --region ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup RUNID"
run: |
echo "RUNID=$(kubectl -n ${{ secrets.TEKTON_NAMESPACE }} get pr --sort-by=.status.completionTime -l triggers.tekton.dev/trigger=${{ secrets.TEKTON_INTERCEPTOR_NAME }} | grep 'fv-web-webhook-' | head -n 1 | cut -d ' ' -f 1)" >> "$GITHUB_ENV";
- name: "Check RUNID Validity"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
if [${{ env.RUNID }} == ""];
then echo "No running pipeline associated with this branch, or the state of the pipeline is ambiguous.";
exit 1;
fi
- name: "Monitor RUNID"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo -e "\n========================================================================================================================================================================"
echo "Running repo cloning..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
echo -e "\n========================================================================================================================================================================"
echo "Running image build..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo -e "\n========================================================================================================================================================================"
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Running URL adjustments for fv-web..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo -e "\n========================================================================================================================================================================"
echo "Running Helm-upgrade..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo -e "\n========================================================================================================================================================================"
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Wrapping up pipeline monitoring";
deploy_with_tekton_preprod:
name: Monitor Preprod Deployment
environment: preprod
runs-on: ubuntu-latest
if: ((github.ref == 'refs/heads/main') && (github.event_name != 'pull_request') && (github.actor != 'dependabot[bot]'))
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.FPCC_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.FPCC_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup kubectl"
run: |
aws eks update-kubeconfig --name ${{ secrets.FV_CLUSTER_NAME }} --region ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup RUNID"
run: |
echo "RUNID=$(kubectl -n ${{ secrets.TEKTON_NAMESPACE }} get pr --sort-by=.status.completionTime -l triggers.tekton.dev/trigger=${{ secrets.TEKTON_INTERCEPTOR_NAME }} | grep 'fv-web-webhook-' | head -n 1 | cut -d ' ' -f 1)" >> "$GITHUB_ENV";
- name: "Check RUNID Validity"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
if [${{ env.RUNID }} == ""];
then echo "No running pipeline associated with this branch, or the state of the pipeline is ambiguous.";
exit 1;
fi
- name: "Monitor RUNID"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "===================================================================================="
echo "Running repo cloning..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
echo "===================================================================================="
echo "Running image build..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Running URL adjustments for fv-web..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
echo "Running Helm-upgrade..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Wrapping up pipeline monitoring";
deploy_with_tekton_prod:
name: Monitor Prod Deployment
environment: prod
runs-on: ubuntu-latest
if: ((github.ref_type == 'tag') && (startsWith(github.ref_name, 'r-')) && (github.event_name != 'pull_request') && (github.actor != 'dependabot[bot]'))
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.FPCC_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.FPCC_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup kubectl"
run: |
aws eks update-kubeconfig --name ${{ secrets.FV_CLUSTER_NAME }} --region ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Setup RUNID"
run: |
echo "RUNID=$(kubectl -n ${{ secrets.TEKTON_NAMESPACE }} get pr --sort-by=.status.completionTime -l triggers.tekton.dev/trigger=${{ secrets.TEKTON_INTERCEPTOR_NAME }} | grep 'fv-web-webhook-' | head -n 1 | cut -d ' ' -f 1)" >> "$GITHUB_ENV";
- name: "Check RUNID Validity"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
if [${{ env.RUNID }} == ""];
then echo "No running pipeline associated with this branch, or the state of the pipeline is ambiguous.";
exit 1;
fi
- name: "Monitor RUNID"
run: |
echo "The run ID associated with this deployment is ${{ env.RUNID }}";
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "===================================================================================="
echo "Running repo cloning..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP1 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
echo "===================================================================================="
echo "Running image build..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP2 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Running URL adjustments for fv-web..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP3 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
echo "Running Helm-upgrade..."
kubectl wait --for=condition=Succeeded TaskRun ${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }} --timeout=300s -n ${{ secrets.TEKTON_NAMESPACE }}
kubectl logs pod/${{ env.RUNID }}-${{ vars.PIPELINE_STEP4 }}-pod -n ${{ secrets.TEKTON_NAMESPACE }}
sleep 1;
echo "===================================================================================="
kubectl get events -n ${{ secrets.TEKTON_NAMESPACE }} | grep "${{ env.RUNID }}";
echo "Wrapping up pipeline monitoring";
image_scan:
name: Check Image for vulnerabilities in Dev
environment: dev
runs-on: ubuntu-22.04
needs: deploy_with_tekton
if: ((github.ref == 'refs/heads/dev') && (github.event_name != 'pull_request'))
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.FPCC_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.FPCC_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.FPCC_DEFAULT_AWS_REGION }}
- name: "Run image scan"
run: |
aws ecr start-image-scan --repository-name ${{ secrets.ECR_REPO_NAME }} --image-id imageTag=build-${{ github.head_ref }}${{ github.sha }}
aws ecr wait image-scan-complete --repository-name ${{ secrets.ECR_REPO_NAME }} --image-id imageTag=build-${{ github.head_ref }}${{ github.sha }}
echo "List of findings are below"
aws ecr describe-image-scan-findings --image-id imageTag=build-${{ github.head_ref }}${{ github.sha }} --repository-name ${{ secrets.ECR_REPO_NAME }} | jq .imageScanFindings.findings
aws ecr describe-image-scan-findings --image-id imageTag=build-${{ github.head_ref }}${{ github.sha }} --repository-name ${{ secrets.ECR_REPO_NAME }} | if [[ $(grep '\"severity\": \"CRITICAL\"') ]]; then echo "CRTICAL Vulnerabilities present in this deployment"; exit 1; fi
aws ecr describe-image-scan-findings --image-id imageTag=build-${{ github.head_ref }}${{ github.sha }} --repository-name ${{ secrets.ECR_REPO_NAME }} | if [[ $(grep '\"severity\": \"HIGH\"') ]]; then echo "HIGH Vulnerabilities present in this deployment"; exit 1; fi