11---
2- - name : Deploy Frontend to Existing Azure App Service
2+ - name : Deploy Frontend to Azure App Service
33 hosts : localhost
44 connection : local
55 vars :
66 frontend_src : " {{ frontend_src_dir | default('src/movie-analyst-ui') }}"
7- node_version : " 16-lts" # Updated to Node.js 16
8- azure_api_version : " 2025-04-01" # Explicit API version
9-
7+ node_version : " 16-lts"
8+
109 tasks :
11- # --- Validate source directory ---
12- - name : Verify frontend directory exists
13- stat :
14- path : " {{ frontend_src }}"
15- register : frontend_dir
16-
17- - name : Fail if frontend directory missing
18- fail :
19- msg : " Frontend source directory not found at {{ frontend_src }}"
20- when : not frontend_dir.stat.exists
21-
22- # --- Show deployment info ---
23- - name : Show deployment configuration
10+ # --- Debug variables first ---
11+ - name : Verify Azure resource variables
2412 debug :
2513 msg : |
26- Deployment Target:
27- - WebApp: {{ app_service_name }}
28- - Resource Group: {{ resource_group_name }}
29- - Backend API: {{ lb_api_url }}:8080
30- - Node.js Version: {{ node_version }}
14+ RESOURCE_GROUP: {{ resource_group_name }}
15+ APP_NAME: {{ app_service_name }}
16+ BACKEND_URL: {{ lb_api_url }}
3117
32- # --- Build frontend ---
18+ # --- Build steps ---
3319 - name : Install dependencies
3420 command : npm install
3521 args :
4531 - " test/"
4632 - " .git/"
4733
48- # --- Configure & Deploy (Azure CLI) ---
49- - name : Update Node.js runtime version
50- command : |
51- az webapp config set \
52- --resource-group "{{ resource_group_name }}" \
53- --name "{{ app_service_name }}" \
54- --linux-fx-version "NODE|{{ node_version }}" \
55- --output none
34+ # --- Azure Deployment with API Version Fix ---
35+ - name : Get latest supported API version
36+ command : >
37+ az provider show --namespace Microsoft.Web
38+ --query "resourceTypes[?resourceType=='sites'].apiVersions[0]"
39+ --output tsv
40+ register : api_version_check
41+ changed_when : false
42+ ignore_errors : yes
43+
44+ - name : Set actual API version
45+ set_fact :
46+ azure_api_version : >-
47+ {% if api_version_check is succeeded %}
48+ {{ api_version_check.stdout }}
49+ {% else %}
50+ 2024-11-01 # Fallback version
51+ {% endif %}
52+
53+ - name : Update Node.js runtime
54+ command : >
55+ az webapp config set
56+ --resource-group "{{ resource_group_name }}"
57+ --name "{{ app_service_name }}"
58+ --linux-fx-version "NODE|{{ node_version }}"
59+ --output none
5660 environment :
5761 AZURE_CLI_DEFAULT_API_VERSION : " {{ azure_api_version }}"
5862
5963 - name : Set app settings
60- command : |
61- az webapp config appsettings set \
62- --resource-group "{{ resource_group_name }}" \
63- --name "{{ app_service_name }}" \
64- --settings \
65- NODE_ENV=production \
66- WEBSITES_PORT=3000 \
67- BACKEND_URL="{{ lb_api_url }}:8080" \
68- WEBSITES_ENABLE_APP_SERVICE_STORAGE=true \
69- --output none
64+ command : >
65+ az webapp config appsettings set
66+ --resource-group "{{ resource_group_name }}"
67+ --name "{{ app_service_name }}"
68+ --settings >-
69+ NODE_ENV=production
70+ WEBSITES_PORT=3000
71+ BACKEND_URL="{{ lb_api_url }}:8080"
72+ WEBSITES_ENABLE_APP_SERVICE_STORAGE=true
73+ --output none
7074 environment :
7175 AZURE_CLI_DEFAULT_API_VERSION : " {{ azure_api_version }}"
7276
7377 - name : Deploy ZIP package
74- command : |
75- az webapp deployment source config-zip \
76- --resource-group "{{ resource_group_name }}" \
77- --name "{{ app_service_name }}" \
78- --src "./frontend-deploy.zip" \
79- --output none
78+ command : >
79+ az webapp deployment source config-zip
80+ --resource-group "{{ resource_group_name }}"
81+ --name "{{ app_service_name }}"
82+ --src "./frontend-deploy.zip"
83+ --output none
8084 environment :
8185 AZURE_CLI_DEFAULT_API_VERSION : " {{ azure_api_version }}"
8286
83- # --- Verify deployment ---
84- - name : Check if application is reachable
87+ # --- Verification ---
88+ - name : Verify deployment
8589 uri :
8690 url : " https://{{ app_service_name }}.azurewebsites.net"
8791 return_content : yes
9498
9599 - name : Show deployment result
96100 debug :
97- msg : " ✅ Frontend deployed successfully: https://{{ app_service_name }}.azurewebsites.net"
101+ msg : " ✅ Successfully deployed to https://{{ app_service_name }}.azurewebsites.net"
98102 when : deployment_check.status == 200
0 commit comments