|
1 | 1 | --- |
2 | | -- name: Deploy frontend to Azure Web App |
| 2 | +- name: Deploy EJS Frontend to Azure Web App (Node.js) |
3 | 3 | hosts: localhost |
4 | 4 | connection: local |
| 5 | + gather_facts: no |
5 | 6 | vars: |
6 | 7 | APP_SERVICE_NAME: "{{ lookup('env', 'APP_SERVICE_NAME') }}" |
7 | 8 | RESOURCE_GROUP_NAME: "{{ lookup('env', 'RESOURCE_GROUP_NAME') }}" |
|
10 | 11 | BACKEND_URL: "{{ lookup('env', 'LB_API_URL') }}" |
11 | 12 |
|
12 | 13 | tasks: |
| 14 | + - name: Enable Oryx build |
| 15 | + shell: | |
| 16 | + az webapp config appsettings set \ |
| 17 | + --resource-group {{ RESOURCE_GROUP_NAME }} \ |
| 18 | + --name {{ APP_SERVICE_NAME }} \ |
| 19 | + --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true |
13 | 20 |
|
14 | | - - name: Ensure frontend path exists |
15 | | - stat: |
16 | | - path: "{{ FRONTEND_PATH }}" |
17 | | - register: frontend_dir |
18 | | - |
19 | | - - name: Fail if frontend path does not exist |
20 | | - fail: |
21 | | - msg: "The frontend path '{{ FRONTEND_PATH }}' does not exist." |
22 | | - when: not frontend_dir.stat.exists |
| 21 | + - name: Set BACKEND_URL in .env file |
| 22 | + copy: |
| 23 | + dest: "{{ FRONTEND_PATH }}/.env" |
| 24 | + content: | |
| 25 | + BACKEND_URL={{ BACKEND_URL }} |
23 | 26 |
|
24 | | - - name: Create zip package (exclude node_modules and build artifacts) |
25 | | - command: > |
26 | | - zip -r {{ ZIP_PATH }} . -x "node_modules/*" -x ".next/*" -x "dist/*" |
| 27 | + - name: Install Node.js dependencies using npm ci |
| 28 | + shell: npm ci |
27 | 29 | args: |
28 | 30 | chdir: "{{ FRONTEND_PATH }}" |
29 | 31 |
|
30 | | - - name: Enable Oryx build (SCM_DO_BUILD_DURING_DEPLOYMENT=true) |
| 32 | + - name: Set startup file command (npm start) |
31 | 33 | shell: | |
32 | | - az webapp config appsettings set \ |
| 34 | + az webapp config set \ |
33 | 35 | --resource-group {{ RESOURCE_GROUP_NAME }} \ |
34 | 36 | --name {{ APP_SERVICE_NAME }} \ |
35 | | - --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true |
| 37 | + --startup-file "npm start" |
| 38 | +
|
| 39 | + - name: Ensure zip is installed |
| 40 | + package: |
| 41 | + name: zip |
| 42 | + state: present |
| 43 | + become: yes |
36 | 44 |
|
37 | | - - name: Set backend API URL as environment variable |
| 45 | + - name: Create zip package for deployment (excluding node_modules) |
38 | 46 | shell: | |
39 | | - az webapp config appsettings set \ |
40 | | - --resource-group {{ RESOURCE_GROUP_NAME }} \ |
41 | | - --name {{ APP_SERVICE_NAME }} \ |
42 | | - --settings NEXT_PUBLIC_BACKEND_URL={{ BACKEND_URL }} |
| 47 | + zip -r {{ ZIP_PATH }} . -x "node_modules/*" |
| 48 | + args: |
| 49 | + chdir: "{{ FRONTEND_PATH }}" |
43 | 50 |
|
44 | 51 | - name: Deploy zip to Azure Web App |
45 | 52 | shell: | |
|
0 commit comments