-
Notifications
You must be signed in to change notification settings - Fork 0
435 lines (368 loc) · 16.3 KB
/
deploy-staging.yml
File metadata and controls
435 lines (368 loc) · 16.3 KB
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
name: Deploy Staging
on:
push:
branches: [develop]
workflow_dispatch:
inputs:
imageTag:
description: 'Docker image tag to deploy'
required: false
default: 'latest'
env:
AZURE_RESOURCE_GROUP: rg-raysoncv-staging
LOCATION: uksouth
ACR_NAME: acrraysoncvstaging
API_IMAGE_NAME: raysoncv-api
UI_IMAGE_NAME: raysoncv-ui
OLLAMA_IMAGE_NAME: raysoncv-ollama
jobs:
build:
runs-on: ubuntu-latest
outputs:
imageTag: ${{ steps.set-tag.outputs.imageTag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: Rayson.CV/UI/package-lock.json
- name: Build API
run: dotnet build Rayson.CV/Api/Presentation/Presentation.csproj --configuration Release
- name: Install UI dependencies
run: cd Rayson.CV/UI && npm ci
- name: Build UI
run: cd Rayson.CV/UI && npm run build
- name: Set image tag
id: set-tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.imageTag }}" ]; then
echo "imageTag=${{ github.event.inputs.imageTag }}" >> $GITHUB_OUTPUT
else
echo "imageTag=${{ github.sha }}" >> $GITHUB_OUTPUT
fi
deploy-core:
runs-on: ubuntu-latest
needs: build
outputs:
acrLoginServer: ${{ steps.deploy.outputs.acrLoginServer }}
acrName: ${{ steps.deploy.outputs.acrName }}
caeId: ${{ steps.deploy.outputs.caeId }}
caeName: ${{ steps.deploy.outputs.caeName }}
defaultDomain: ${{ steps.deploy.outputs.defaultDomain }}
storageAccountName: ${{ steps.deploy.outputs.storageAccountName }}
storageAccountKey: ${{ steps.deploy.outputs.storageAccountKey }}
blobBaseUrl: ${{ steps.deploy.outputs.blobBaseUrl }}
postgresFqdn: ${{ steps.deploy.outputs.postgresFqdn }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.STAGING_AZURE_CREDENTIALS }}
- name: Deploy core infrastructure
id: deploy
run: |
az deployment sub create \
--name raysoncv-staging-core \
--location ${{ env.LOCATION }} \
--template-file infra/main-core.bicep \
--parameters location=${{ env.LOCATION }} \
resourceGroupName=${{ env.AZURE_RESOURCE_GROUP }} \
environmentName=staging \
acrName=${{ env.ACR_NAME }} \
postgresAdminUsername=raysoncvadmin \
postgresAdminPassword="${{ secrets.STAGING_POSTGRES_PASSWORD }}"
ACR_LOGIN_SERVER=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.acrLoginServer.value --output tsv)
ACR_NAME_OUT=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.acrName.value --output tsv)
CAE_ID=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.containerAppEnvId.value --output tsv)
CAE_NAME=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.containerAppEnvName.value --output tsv)
DEFAULT_DOMAIN=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.defaultDomain.value --output tsv)
STORAGE_ACCOUNT_NAME=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.storageAccountName.value --output tsv)
STORAGE_ACCOUNT_KEY=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.storageAccountKey.value --output tsv)
BLOB_BASE_URL=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.blobBaseUrl.value --output tsv)
POSTGRES_FQDN=$(az deployment sub show --name raysoncv-staging-core --query properties.outputs.postgresFqdn.value --output tsv)
echo "acrLoginServer=$ACR_LOGIN_SERVER" >> $GITHUB_OUTPUT
echo "acrName=$ACR_NAME_OUT" >> $GITHUB_OUTPUT
echo "caeId=$CAE_ID" >> $GITHUB_OUTPUT
echo "caeName=$CAE_NAME" >> $GITHUB_OUTPUT
echo "defaultDomain=$DEFAULT_DOMAIN" >> $GITHUB_OUTPUT
echo "storageAccountName=$STORAGE_ACCOUNT_NAME" >> $GITHUB_OUTPUT
echo "storageAccountKey=$STORAGE_ACCOUNT_KEY" >> $GITHUB_OUTPUT
echo "blobBaseUrl=$BLOB_BASE_URL" >> $GITHUB_OUTPUT
echo "postgresFqdn=$POSTGRES_FQDN" >> $GITHUB_OUTPUT
push:
runs-on: ubuntu-latest
needs: [build, deploy-core]
outputs:
apiFqdn: ${{ steps.set-fqdn.outputs.apiFqdn }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.STAGING_AZURE_CREDENTIALS }}
- name: Login to Azure Container Registry
run: az acr login --name ${{ env.ACR_NAME }}
- name: Build and push API image
run: |
docker build \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.API_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }} \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.API_IMAGE_NAME }}:latest \
./Rayson.CV/Api
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.API_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }}
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.API_IMAGE_NAME }}:latest
- name: Build and push UI image
run: |
API_FQDN="ca-api-staging.${{ needs.deploy-core.outputs.defaultDomain }}"
BLOB_URL="${{ needs.deploy-core.outputs.blobBaseUrl }}"
docker build \
--build-arg VITE_API_BASE_URL=https://$API_FQDN/ \
--build-arg VITE_APP_DOWNLOAD_URL=$BLOB_URL \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.UI_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }} \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.UI_IMAGE_NAME }}:latest \
./Rayson.CV/UI
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.UI_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }}
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.UI_IMAGE_NAME }}:latest
echo "apiFqdn=$API_FQDN" >> $GITHUB_OUTPUT
- name: Build and push Ollama image
run: |
docker build \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.OLLAMA_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }} \
-t ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.OLLAMA_IMAGE_NAME }}:latest \
-f Rayson.CV/ollama.Dockerfile \
Rayson.CV
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.OLLAMA_IMAGE_NAME }}:${{ needs.build.outputs.imageTag }}
docker push ${{ needs.deploy-core.outputs.acrLoginServer }}/${{ env.OLLAMA_IMAGE_NAME }}:latest
- name: Set FQDN output
id: set-fqdn
run: |
echo "apiFqdn=ca-api-staging.${{ needs.deploy-core.outputs.defaultDomain }}" >> $GITHUB_OUTPUT
build-electron-linux:
runs-on: ubuntu-latest
needs: [build, deploy-core]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: Rayson.CV/UI/package-lock.json
- name: Install dependencies
run: cd Rayson.CV/UI && npm ci
- name: Build Electron app
run: |
API_FQDN="https://ca-api-staging.${{ needs.deploy-core.outputs.defaultDomain }}/"
cd Rayson.CV/UI && VITE_API_BASE_URL=$API_FQDN npm run electron:build -- --linux
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: electron-linux
path: Rayson.CV/UI/build/*.AppImage
build-electron-mac:
runs-on: macos-latest
needs: [build, deploy-core]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: Rayson.CV/UI/package-lock.json
- name: Install dependencies
run: cd Rayson.CV/UI && npm ci
- name: Build Electron app
run: |
apiFqdn="https://ca-api-staging.${{ needs.deploy-core.outputs.defaultDomain }}/"
cd Rayson.CV/UI
VITE_API_BASE_URL=$apiFqdn npm run electron:build -- --mac
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: electron-mac
path: Rayson.CV/UI/build/*.dmg
build-electron-windows:
runs-on: windows-latest
needs: [build, deploy-core]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: Rayson.CV/UI/package-lock.json
- name: Install dependencies
run: cd Rayson.CV/UI && npm ci
- name: Build Electron app
run: |
$apiFqdn = "https://ca-api-staging.${{ needs.deploy-core.outputs.defaultDomain }}/"
cd Rayson.CV/UI
$env:VITE_API_BASE_URL=$apiFqdn
npm run electron:build -- --win
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: electron-windows
path: Rayson.CV/UI/build/*.exe
upload-electron:
runs-on: ubuntu-latest
needs: [build-electron-linux, build-electron-mac, build-electron-windows, deploy-core]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.STAGING_AZURE_CREDENTIALS }}
- name: Wait for storage account
run: |
echo "Waiting for storage account to be ready..."
until STORAGE_STATE=$(az storage account show \
--name strraysoncvstaging \
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \
--query "provisioningState" \
--output tsv 2>/dev/null) && [ "$STORAGE_STATE" = "Succeeded" ]; do
echo "Storage account status: $STORAGE_STATE. Waiting..."
sleep 5
done
echo "Storage account is ready!"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: List downloaded artifacts
run: |
echo "=== Linux ==="
find artifacts/electron-linux -type f -exec ls -lh {} \;
echo "=== macOS ==="
find artifacts/electron-mac -type f -exec ls -lh {} \;
echo "=== Windows ==="
find artifacts/electron-windows -type f -exec ls -lh {} \;
- name: Upload Linux app
run: |
FILE=$(ls artifacts/electron-linux/*.AppImage | head -1)
echo "Uploading Linux: $FILE"
az storage blob upload \
--container-name '$web' \
--file "$FILE" \
--name "RaysonCV.AppImage" \
--account-name ${{ needs.deploy-core.outputs.storageAccountName }} \
--account-key "${{ needs.deploy-core.outputs.storageAccountKey }}" \
--overwrite
- name: Upload macOS app
run: |
FILE=$(ls artifacts/electron-mac/*.dmg | head -1)
echo "Uploading macOS: $FILE"
az storage blob upload \
--container-name '$web' \
--file "$FILE" \
--name "RaysonCV.dmg" \
--account-name ${{ needs.deploy-core.outputs.storageAccountName }} \
--account-key "${{ needs.deploy-core.outputs.storageAccountKey }}" \
--overwrite
- name: Upload Windows app
run: |
FILE=$(ls artifacts/electron-windows/*.exe | head -1)
echo "Uploading Windows: $FILE"
az storage blob upload \
--container-name '$web' \
--file "$FILE" \
--name "RaysonCV-Setup.exe" \
--account-name ${{ needs.deploy-core.outputs.storageAccountName }} \
--account-key "${{ needs.deploy-core.outputs.storageAccountKey }}" \
--overwrite
- name: Upload CV PDF
run: |
az storage blob upload \
--container-name '$web' \
--file "Rayson.CV/UI/public/CV-September-2024.pdf" \
--name "CV-September-2024.pdf" \
--account-name ${{ needs.deploy-core.outputs.storageAccountName }} \
--account-key "${{ needs.deploy-core.outputs.storageAccountKey }}" \
--overwrite
deploy-apps:
runs-on: ubuntu-latest
needs: [build, deploy-core, push]
outputs:
apiFqdn: ${{ steps.deploy.outputs.apiFqdn }}
uiFqdn: ${{ steps.deploy.outputs.uiFqdn }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.STAGING_AZURE_CREDENTIALS }}
- name: Deploy container apps
id: deploy
run: |
az deployment group create \
--name raysoncv-staging-apps \
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \
--template-file infra/main-apps.bicep \
--parameters location=${{ env.LOCATION }} \
caeId=${{ needs.deploy-core.outputs.caeId }} \
caeName=${{ needs.deploy-core.outputs.caeName }} \
defaultDomain=${{ needs.deploy-core.outputs.defaultDomain }} \
acrLoginServer=${{ needs.deploy-core.outputs.acrLoginServer }} \
acrName=${{ needs.deploy-core.outputs.acrName }} \
imageTag=${{ needs.build.outputs.imageTag }} \
environmentName=staging \
blobBaseUrl="${{ needs.deploy-core.outputs.blobBaseUrl }}" \
postgresFqdn=${{ needs.deploy-core.outputs.postgresFqdn }} \
postgresAdminUsername=raysoncvadmin \
postgresAdminPassword="${{ secrets.STAGING_POSTGRES_PASSWORD }}" \
logLevel=Debug
API_FQDN=$(az deployment group show --name raysoncv-staging-apps --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --query properties.outputs.apiFqdn.value --output tsv)
UI_FQDN=$(az deployment group show --name raysoncv-staging-apps --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --query properties.outputs.uiFqdn.value --output tsv)
echo "apiFqdn=$API_FQDN" >> $GITHUB_OUTPUT
echo "uiFqdn=$UI_FQDN" >> $GITHUB_OUTPUT
- name: Deployment Summary
run: |
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Service | URL |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-----|" >> $GITHUB_STEP_SUMMARY
echo "| API | https://${{ steps.deploy.outputs.apiFqdn }} |" >> $GITHUB_STEP_SUMMARY
echo "| UI | https://${{ steps.deploy.outputs.uiFqdn }} |" >> $GITHUB_STEP_SUMMARY
e2e-tests:
runs-on: ubuntu-latest
needs: deploy-apps
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
run: cd Rayson.CV/Test/e2e && npm ci
- name: Install Playwright browsers
run: npx playwright install chromium
- name: Run E2E tests
working-directory: Rayson.CV/Test/e2e
run: npm run e2e:staging
env:
E2E_API_URL: https://${{ needs.deploy-apps.outputs.apiFqdn }}
E2E_UI_URL: https://${{ needs.deploy-apps.outputs.uiFqdn }}
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-report
path: Rayson.CV/Test/e2e/reports/