|
2 | 2 | - name: Deploy frontend to Azure Web App |
3 | 3 | hosts: localhost |
4 | 4 | connection: local |
5 | | - gather_facts: no |
6 | 5 | vars: |
7 | | - resource_group: softdevrg |
8 | | - app_name: softdefault-movies-app |
9 | | - frontend_path: /home/adminuser/frontend |
10 | | - zip_path: /tmp/frontend.zip |
| 6 | + APP_SERVICE_NAME: "{{ lookup('env', 'APP_SERVICE_NAME') }}" |
| 7 | + RESOURCE_GROUP_NAME: "{{ lookup('env', 'RESOURCE_GROUP_NAME') }}" |
| 8 | + FRONTEND_PATH: "../src/movie-analyst-ui" |
| 9 | + ZIP_PATH: "/tmp/frontend.zip" |
| 10 | + BACKEND_URL: "{{ lookup('env', 'LB_API_URL') }}" |
11 | 11 |
|
12 | 12 | tasks: |
| 13 | + |
| 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 |
| 23 | + |
| 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 | + args: |
| 28 | + chdir: "{{ FRONTEND_PATH }}" |
| 29 | + |
13 | 30 | - name: Enable Oryx build (SCM_DO_BUILD_DURING_DEPLOYMENT=true) |
14 | 31 | shell: | |
15 | 32 | az webapp config appsettings set \ |
16 | | - --resource-group {{ resource_group }} \ |
17 | | - --name {{ app_name }} \ |
| 33 | + --resource-group {{ RESOURCE_GROUP_NAME }} \ |
| 34 | + --name {{ APP_SERVICE_NAME }} \ |
18 | 35 | --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true |
19 | 36 |
|
20 | | - - name: Create zip package (exclude node_modules and build artifacts) |
| 37 | + - name: Set backend API URL as environment variable |
21 | 38 | shell: | |
22 | | - zip -r {{ zip_path }} . -x "node_modules/*" -x ".next/*" -x "dist/*" |
23 | | - args: |
24 | | - chdir: "{{ frontend_path }}" |
| 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 }} |
25 | 43 |
|
26 | 44 | - name: Deploy zip to Azure Web App |
27 | 45 | shell: | |
28 | 46 | az webapp deploy \ |
29 | | - --resource-group {{ resource_group }} \ |
30 | | - --name {{ app_name }} \ |
31 | | - --src-path {{ zip_path }} \ |
| 47 | + --resource-group {{ RESOURCE_GROUP_NAME }} \ |
| 48 | + --name {{ APP_SERVICE_NAME }} \ |
| 49 | + --src-path {{ ZIP_PATH }} \ |
32 | 50 | --type zip |
33 | | -
|
34 | | - - name: Show success message |
35 | | - debug: |
36 | | - msg: "✅ Successfully deployed to https://{{ APP_SERVICE_NAME }}.azurewebsites.net" |
|
0 commit comments