-
Notifications
You must be signed in to change notification settings - Fork 0
336 lines (300 loc) · 13.4 KB
/
action.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
name: deploy
on:
workflow_dispatch:
push:
branches:
- 'main'
env:
APP_NAME: "laa-crime-equinity-historical-data-frontend"
IMAGE_TAG: ${{ github.sha }} # Tags ECR image with commit sha
IMAGE_TAG_PDF: ${{ github.sha }}pdf # Tags ECR image with commit sha specifically for PDF Generator
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm ci
- run: npm run build --if-present
- run: npm run test:ci
ecr:
runs-on: ubuntu-latest
needs: tests
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
# Build and push docker image to container repo
- name: Build and push docker image
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
with:
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
push: true
deploy-dev:
runs-on: ubuntu-latest
needs: ecr
environment: dev
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
APP_ENV: "dev"
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Build and push docker image
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
with:
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
push: true
- name: Authenticate to K8 Cluster
run: |
mkdir deployments
cat ./.github/deployments/deployment.yml | envsubst > deployments/deployment.yml
cat ./.github/deployments/ingress.yml | envsubst > deployments/ingress.yml
cat ./.github/deployments/service.yml | envsubst > deployments/service.yml
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
CP_NAMESPACE: "${{ env.APP_NAME }}-${{ env.APP_ENV }}"
- name: Deploy to K8 Cluster
run: |
echo "${{ secrets.KUBE_CERT }}" > ca.crt
echo ${KUBE_NAMESPACE}
echo ${{ env.IMAGE_NAME }}
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
deploy-uat:
runs-on: ubuntu-latest
needs: ecr
environment: uat
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
APP_ENV: "uat"
IMAGE_TAG: ${{ github.sha }} # Tags ECR image with commit sha
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Authenticate to K8 Cluster
run: |
mkdir deployments
cat ./.github/deployments/deployment.yml | envsubst > deployments/deployment.yml
cat ./.github/deployments/ingress.yml | envsubst > deployments/ingress.yml
cat ./.github/deployments/service.yml | envsubst > deployments/service.yml
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
CP_NAMESPACE: "${{ env.APP_NAME }}-${{ env.APP_ENV }}"
- name: Deploy to K8 Cluster
run: |
echo "${{ secrets.KUBE_CERT }}" > ca.crt
echo ${KUBE_NAMESPACE}
echo ${{ env.IMAGE_NAME }}
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
deploy-staging:
runs-on: ubuntu-latest
needs: deploy-uat
environment: staging
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
APP_ENV: "staging"
IMAGE_TAG: ${{ github.sha }}
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Build and push docker image
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
with:
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
push: true
- name: Authenticate to the K8 cluster
run: |
mkdir deployments
cat ./.github/deployments/deployment.yml | envsubst > deployments/deployment.yml
cat ./.github/deployments/ingress.yml | envsubst > deployments/ingress.yml
cat ./.github/deployments/service.yml | envsubst > deployments/service.yml
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
CP_NAMESPACE: "${{ env.APP_NAME }}-${{ env.APP_ENV }}"
- name: Deploy to K8 Cluster
run: |
echo "${{ secrets.KUBE_CERT }}" > ca.crt
echo ${{ secrets.KUBE_NAMESPACE }}
echo ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
deploy-archive:
runs-on: ubuntu-latest
needs: deploy-staging
environment: archive
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
APP_ENV: "archive"
IMAGE_TAG: ${{ github.sha }}
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Build and push docker image
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
with:
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
push: true
- name: Authenticate to the K8 cluster
run: |
mkdir deployments
cat ./.github/deployments/deployment.yml | envsubst > deployments/deployment.yml
cat ./.github/deployments/ingress.yml | envsubst > deployments/ingress.yml
cat ./.github/deployments/service.yml | envsubst > deployments/service.yml
env:
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
CP_NAMESPACE: "${{ env.APP_NAME }}-${{ env.APP_ENV }}"
- name: Deploy to K8 Cluster
run: |
echo "${{ secrets.KUBE_CERT }}" > ca.crt
echo ${{ secrets.KUBE_NAMESPACE }}
echo ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
deploy-prod:
runs-on: ubuntu-latest
needs: deploy-staging
environment: prod
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
APP_ENV: "prod"
IMAGE_TAG: ${{ github.sha }}
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Build and push docker image
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
with:
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
push: true
- name: Authenticate to the K8 cluster
run: |
mkdir deployments
cat ./.github/deployments/deployment.yml | envsubst > deployments/deployment.yml
cat ./.github/deployments/ingress.yml | envsubst > deployments/ingress.yml
cat ./.github/deployments/service.yml | envsubst > deployments/service.yml
env:
IMAGE_NAME: ${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
CP_NAMESPACE: "${{ env.APP_NAME }}-${{ env.APP_ENV }}"
- name: Deploy to K8 Cluster
run: |
echo "${{ secrets.KUBE_CERT }}" > ca.crt
echo ${{ secrets.KUBE_NAMESPACE }}
echo ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl -n ${KUBE_NAMESPACE} apply -f deployments/
env:
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}