-
Notifications
You must be signed in to change notification settings - Fork 1
309 lines (274 loc) Β· 11 KB
/
deployment.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
# This GHA is responsible for EXIP deployment.
# Deployment is initiated using `az cli` bash script.
#
# Standard Azure naming convention has been followed:
# https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming
#
#
# Following Azure services are consumed:
# 1. Azure resource group - https://learn.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-create
# 2. Azure container registry - https://learn.microsoft.com/en-us/cli/azure/acr?view=azure-cli-latest#az-acr-create
# 3. Azure WebApp - https://learn.microsoft.com/en-us/azure/app-service/overview
#
#
# Execution
# *********
# GHA is only invoked when following conditions are satisfied:
# 1. Push to the `dev`, `staging` and `production` branches only.
# 2. Any modifications to atleast one of the `paths` targets.
name: Deployment π
run-name: EXIP deployment for ${{ github.repository }}
on:
push:
branches:
- dev
- feature
- staging
- production
paths:
- "src/**"
- "database/**"
- ".github/workflows/deployment.yml"
env:
PRODUCT: exip
ENVIRONMENT: ${{ github.ref_name }}
TIMEZONE: "Europe/London"
# Base artifact
FROM: latest
jobs:
setup:
name: Setup π§
runs-on: [self-hosted, EXIP, deployment]
outputs:
product: ${{ env.PRODUCT }}
environment: ${{ env.ENVIRONMENT }}
timezone: ${{ env.TIMEZONE }}
steps:
- name: Environment π§ͺ
run: echo "Environment set to ${{ env.ENVIRONMENT }}"
- name: Timezone π
run: echo "Timezone set to ${{ env.TIMEZONE }}"
db:
name: Database πΎ
needs: setup
environment: ${{ needs.setup.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.setup.outputs.environment }}
runs-on: [self-hosted, EXIP, deployment]
steps:
- name: Repository ποΈ
uses: actions/checkout@v4
- name: Azure π
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Defaults β¨
uses: azure/cli@v2
with:
inlineScript: |
# Basic
az configure --defaults location=${{ vars.REGION }}
az configure --defaults group=rg-${{ env.PRODUCT }}-${{ github.ref_name }}-${{ vars.VERSION }}
- name: Extension β
if: ${{ '1' == vars.DATABASE }}
uses: azure/cli@v2
with:
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az extension add --name rdbms-connect
- name: Import β¬
if: ${{ '1' == vars.DATABASE }}
uses: azure/cli@v2
with:
inlineScript: |
az mysql flexible-server execute \
--name sqldb-${{ env.PRODUCT }}-${{ github.ref_name }}-${{ vars.VERSION }} \
--admin-user ${{ secrets.MYSQL_USER }} \
--admin-password ${{ secrets.MYSQL_PASSWORD }} \
--database-name ${{ env.PRODUCT }} \
--file-path "database/exip.sql"
api:
name: API π¦οΈ
needs: setup
environment: ${{ needs.setup.outputs.environment }}
env:
NAME: api
ENVIRONMENT: ${{ needs.setup.outputs.environment }}
runs-on: [self-hosted, EXIP, deployment]
steps:
- name: Repository ποΈ
uses: actions/checkout@v4
- name: Azure π
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Defaults β¨
uses: azure/cli@v2
with:
inlineScript: |
# Basic
az configure --defaults location=${{ vars.REGION }}
az configure --defaults group=rg-${{ env.PRODUCT }}-${{ github.ref_name }}-${{ vars.VERSION }}
- name: CLI π
run: |
echo ACR=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query loginServer -o tsv) >> $GITHUB_ENV
echo ACR_USER=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query name -o tsv) >> $GITHUB_ENV
echo WEBAPP=$(az resource list --resource-type 'Microsoft.Web/sites' --query '[?contains(name, `${{ env.NAME }}`)].name' -o tsv) >> $GITHUB_ENV
- name: ACR π
uses: azure/docker-login@v2
with:
login-server: ${{ env.ACR }}
username: ${{ env.ACR_USER }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Artifacts ποΈ
working-directory: src/${{ env.NAME }}
run: |
# Build images
docker build . \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }} \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }} \
--build-arg NODE_ENV=${{ vars.NODE_ENV }} \
--build-arg PORT=${{ vars.API_PORT }} \
--build-arg SESSION_SECRET=${{ secrets.SESSION_SECRET }} \
--build-arg GOV_NOTIFY_API_KEY=${{ secrets.GOV_NOTIFY_API_KEY }}
# Push images
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }}
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }}
- name: Environment π§±
uses: azure/cli@v2
with:
inlineScript: |
az webapp config appsettings set \
--name app-${{ env.PRODUCT }}-${{ env.NAME }}-${{ github.ref_name }}-${{ vars.VERSION }} \
--settings \
TZ='${{ vars.TIMEZONE }}' \
NODE_ENV='${{ vars.NODE_ENV }}' \
PORT='${{ vars.API_PORT }}' \
WEBSITES_PORT='${{ vars.API_PORT }}' \
APIM_MDM_URL='${{ secrets.APIM_MDM_URL }}' \
APIM_MDM_KEY='${{ secrets.APIM_MDM_KEY }}' \
APIM_MDM_VALUE='${{ secrets.APIM_MDM_VALUE }}' \
API_KEY='${{ secrets.API_KEY }}' \
SESSION_SECRET='${{ secrets.SESSION_SECRET }}' \
GOV_NOTIFY_API_KEY='${{ secrets.GOV_NOTIFY_API_KEY }}' \
COMPANIES_HOUSE_API_URL='${{ secrets.COMPANIES_HOUSE_API_URL }}' \
COMPANIES_HOUSE_API_KEY='${{ secrets.COMPANIES_HOUSE_API_KEY }}' \
JWT_SIGNING_KEY='${{ secrets.JWT_SIGNING_KEY }}' \
UNDERWRITING_TEAM_EMAIL='${{ secrets.UNDERWRITING_TEAM_EMAIL }}' \
FEEDBACK_EMAIL_RECIPIENT='${{ secrets.FEEDBACK_EMAIL_RECIPIENT }}' \
EXCELJS_PROTECTION_PASSWORD='${{ secrets.EXCELJS_PROTECTION_PASSWORD }}'
- name: Slot π
uses: azure/cli@v2
with:
inlineScript: |
# Create new temporary slot
az webapp deployment slot create \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--configuration-source ${{ env.WEBAPP }} \
--deployment-container-image-name ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }}
# Swap slot
az webapp deployment slot swap \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--action swap
# Delete temporary slot
az webapp deployment slot delete \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }}
- name: Reboot β»οΈ
uses: azure/cli@v2
with:
inlineScript: |
az webapp restart \
--name ${{ env.WEBAPP }}
ui:
name: UI π¦οΈ
needs: setup
environment: ${{ needs.setup.outputs.environment }}
env:
NAME: ui
ENVIRONMENT: ${{ needs.setup.outputs.environment }}
runs-on: [self-hosted, EXIP, deployment]
steps:
- name: Repository ποΈ
uses: actions/checkout@v4
- name: Azure π
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Defaults β¨
uses: azure/cli@v2
with:
inlineScript: |
# Basic
az configure --defaults location=${{ vars.REGION }}
az configure --defaults group=rg-${{ env.PRODUCT }}-${{ github.ref_name }}-${{ vars.VERSION }}
- name: CLI π
run: |
echo ACR=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query loginServer -o tsv) >> $GITHUB_ENV
echo ACR_USER=$(az acr show -n $(az resource list --resource-type 'Microsoft.ContainerRegistry/registries' --query '[0].name' -o tsv) --query name -o tsv) >> $GITHUB_ENV
echo WEBAPP=$(az resource list --resource-type 'Microsoft.Web/sites' --query '[?contains(name, `${{ env.NAME }}`)].name' -o tsv) >> $GITHUB_ENV
- name: ACR π
uses: azure/docker-login@v2
with:
login-server: ${{ env.ACR }}
username: ${{ env.ACR_USER }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Artifacts ποΈ
working-directory: src/${{ env.NAME }}
run: |
# Build images
docker build . \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }} \
-t ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }} \
--build-arg NODE_ENV=${{ vars.NODE_ENV }} \
--build-arg PORT=${{ vars.UI_PORT }}
# Push images
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ github.sha }}
docker push ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }}
- name: Environment π§±
uses: azure/cli@v2
with:
inlineScript: |
az webapp config appsettings set \
--name app-${{ env.PRODUCT }}-${{ env.NAME }}-${{ github.ref_name }}-${{ vars.VERSION }} \
--settings \
TZ='${{ vars.TIMEZONE }}' \
NODE_ENV='${{ vars.NODE_ENV }}' \
PORT='${{ vars.UI_PORT }}' \
WEBSITES_PORT='${{ vars.UI_PORT }}' \
SESSION_SECRET='${{ secrets.SESSION_SECRET }}' \
GOOGLE_ANALYTICS_ID='${{ secrets.GOOGLE_ANALYTICS_ID }}' \
GOOGLE_TAG_MANAGER_ID='${{ secrets.GOOGLE_TAG_MANAGER_ID }}' \
APIM_MDM_URL='${{ secrets.APIM_MDM_URL }}' \
APIM_MDM_KEY='${{ secrets.APIM_MDM_KEY }}' \
APIM_MDM_VALUE='${{ secrets.APIM_MDM_VALUE }}' \
API_KEY='${{ secrets.API_KEY }}'
APIM_MDM_VALUE='${{ secrets.APIM_MDM_VALUE }}' \
API_KEY='${{ secrets.API_KEY }}'
- name: Slot π
uses: azure/cli@v2
with:
inlineScript: |
# Create new temporary slot
az webapp deployment slot create \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--configuration-source ${{ env.WEBAPP }} \
--deployment-container-image-name ${{ env.ACR }}/${{ env.NAME }}:${{ env.FROM }}
# Swap slot
az webapp deployment slot swap \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }} \
--action swap
# Delete temporary slot
az webapp deployment slot delete \
--slot ${{ github.sha }} \
--name ${{ env.WEBAPP }}
- name: Reboot β»οΈ
uses: azure/cli@v2
with:
inlineScript: |
az webapp restart \
--name ${{ env.WEBAPP }}