-
Notifications
You must be signed in to change notification settings - Fork 6
398 lines (340 loc) · 13.8 KB
/
Copy pathdeploy.yml
File metadata and controls
398 lines (340 loc) · 13.8 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
name: Build and Deploy to Dev and Test
on:
push:
branches:
- master
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: "./app/workers"
AZURE_WEBAPP_PACKAGE_PATH: "./app/next-client-app"
PYTHON_VERSION: "3.11"
NODE_VERSION: 20
app-name: carrot
repo-owner: health-informatics-uon
registry: ghcr.io
permissions:
contents: read # Required to read the repository contents
packages: write # Required to publish packages
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Dependency Review
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1
build-and-publish-workers:
runs-on: ubuntu-latest
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: "Install UV and Pip"
run: |
python -m pip install --upgrade pip
pip install uv
- name: "Resolve Project Dependencies Using UV"
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
uv pip compile pyproject.toml --output-file requirements.txt
popd
shell: bash
- name: "Install Dependencies Using Pip"
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: Upload artifact for deployment job
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: functionsapp
path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
include-hidden-files: true
build-and-publish-web:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- name: Log in to registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ccomreg.azurecr.io
username: ${{ secrets.REGISTRY_USERNAME_DEV }}
password: ${{ secrets.REGISTRY_PASSWORD_DEV }}
- name: Build and push container image to registry
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ./app
push: true
tags: ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}
file: ./app/api/Dockerfile
build-and-publish-next-app:
runs-on: ubuntu-latest
environment: dev
env:
BACKEND_ORIGIN: ${{ secrets.BACKEND_ORIGIN }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm install and build
run: |
npm i --workspaces=false
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Cache .next/cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
env:
cache-name: cache-node-modules
with:
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.next/cache
key: nextjs | $(Agent.OS) | ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/package-lock.json
- name: Build
run: npm run build --workspaces=false
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
env:
BODY_SIZE_LIMIT: ${{ vars.BODY_SIZE_LIMIT }}
- name: Copy Static Assets
run: |
cp -r .next/static .next/standalone/.next/
cp -r public .next/standalone/
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Publish webapp artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.next/standalone
name: frontendwebapp
include-hidden-files: true
build-and-publish-airflow:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Docker Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set timestamp env var
run: echo "RUN_TIMESTAMP=$(TZ="Etc/UTC" date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
# Tag and build webserver of airflow
- name: Extract webserver Docker metadata
id: airflow_webserver_meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-webserver
tags: |
${{ github.sha }}
${{ env.RUN_TIMESTAMP }}
"edge"
- name: Build and push webserver image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ./app/airflow
file: ./app/airflow/Dockerfile
build-args: AIRFLOW_COMPONENT=webserver
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.airflow_webserver_meta.outputs.tags }}
# Tag and build scheduler of airflow
- name: Extract scheduler Docker metadata
id: scheduler_meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-scheduler
tags: |
${{ github.sha }}
${{ env.RUN_TIMESTAMP }}
"edge"
- name: Build and push scheduler image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: ./app/airflow
file: ./app/airflow/Dockerfile
build-args: AIRFLOW_COMPONENT=scheduler
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.scheduler_meta.outputs.tags }}
# Deploy Workers Dev
deploy-workers-dev:
runs-on: ubuntu-latest
needs: [build-and-publish-workers, build-and-publish-web]
environment: dev
steps:
- name: Download artifact from build job
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: functionsapp
name: functionsapp
- name: "Run Azure Functions Action"
uses: Azure/functions-action@0bd707f87c0b6385742bab336c74e1afc61f6369 # v1.5.3
id: fa
with:
app-name: ${{ vars.AZURE_FUNCTIONS_NAME }}
slot-name: "production"
package: ${{ github.workspace }}/functionsapp
publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }}
# Deploy Web App Dev
deploy-web-dev:
runs-on: ubuntu-latest
needs: [build-and-publish-web, deploy-workers-dev]
environment:
name: "dev"
url: ${{ steps.deploy-web-dev.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: "ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}"
# Deploy Next.js Client App Dev
deploy-next-dev:
runs-on: ubuntu-latest
needs: [build-and-publish-next-app, deploy-web-dev]
environment: dev
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download artifact from build job
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: frontendwebapp
name: frontendwebapp
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AZURE_WEBAPP_NEXT_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }}
package: ${{ github.workspace }}/frontendwebapp
# Deploy Airflow Webserver Dev
deploy-airflow-webserver-dev:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [build-and-publish-airflow]
environment:
name: "dev"
url: ${{ steps.deploy-airflow-webserver-dev.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-airflow-webserver-dev
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AIRFLOW_WEBSERVER_NAME }}
publish-profile: ${{ secrets.AIRFLOW_WEBSERVER_PUBLISH_PROFILE }}
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-webserver:${{ github.sha }}
# Deploy Airflow Scheduler Dev
deploy-airflow-scheduler-dev:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [build-and-publish-airflow]
environment:
name: "dev"
url: ${{ steps.deploy-airflow-scheduler-dev.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-airflow-scheduler-dev
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AIRFLOW_SCHEDULER_NAME }}
publish-profile: ${{ secrets.AIRFLOW_SCHEDULER_PUBLISH_PROFILE }}
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-scheduler:${{ github.sha }}
# Deploy Airflow Webserver Test
deploy-airflow-webserver-test:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [deploy-airflow-webserver-dev]
environment:
name: "test"
url: ${{ steps.deploy-airflow-webserver-test.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-airflow-webserver-test
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AIRFLOW_WEBSERVER_NAME }}
publish-profile: ${{ secrets.AIRFLOW_WEBSERVER_PUBLISH_PROFILE }}
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-webserver:${{ github.sha }}
# Deploy Airflow Scheduler Test
deploy-airflow-scheduler-test:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [deploy-airflow-scheduler-dev]
environment:
name: "test"
url: ${{ steps.deploy-airflow-scheduler-test.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-airflow-scheduler-test
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AIRFLOW_SCHEDULER_NAME }}
publish-profile: ${{ secrets.AIRFLOW_SCHEDULER_PUBLISH_PROFILE }}
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-scheduler:${{ github.sha }}
# Deploy Workers Test
deploy-workers-test:
runs-on: ubuntu-latest
needs: deploy-workers-dev
environment: test
steps:
- name: Download artifact from build job
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: functionsapp
name: functionsapp
- name: "Run Azure Functions Action"
uses: Azure/functions-action@0bd707f87c0b6385742bab336c74e1afc61f6369 # v1.5.3
id: fa
with:
app-name: ${{ vars.AZURE_FUNCTIONS_NAME }}
slot-name: "production"
package: ${{ github.workspace }}/functionsapp
publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }}
# Deploy Web App Test
deploy-web-test:
runs-on: ubuntu-latest
needs: [deploy-web-dev, deploy-workers-test]
environment:
name: "test"
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: "ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}"
# Deploy Next.js Client App Test
deploy-next-test:
runs-on: ubuntu-latest
needs: [deploy-next-dev, deploy-web-test]
environment: test
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download artifact from build job
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: frontendwebapp
name: frontendwebapp
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2
with:
app-name: ${{ vars.AZURE_WEBAPP_NEXT_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }}
package: ${{ github.workspace }}/frontendwebapp