1+ # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+ # More GitHub Actions for Azure: https://github.com/Azure/actions
3+ # More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
4+
5+ name : Build and deploy Python app to Azure Web App - hvalfangstlinuxwebapp
6+
7+ on :
8+ push :
9+ branches :
10+ - main
11+ workflow_dispatch :
12+
13+ jobs :
14+ build :
15+ runs-on : ubuntu-latest
16+
17+ steps :
18+ - uses : actions/checkout@v4
19+
20+ - name : Set up Python version
21+ uses : actions/setup-python@v5
22+ with :
23+ python-version : ' 3.10'
24+
25+ - name : Create and start virtual environment
26+ run : |
27+ python -m venv venv
28+ source venv/bin/activate
29+
30+ - name : Install dependencies
31+ run : pip install -r server/requirements.txt
32+
33+ # Optional: Add step to run tests here (PyTest, Django test suites, etc.)
34+
35+ - name : Zip artifact for deployment
36+ run : cd server && zip -r ../release.zip ./*
37+
38+ - name : Upload artifact for deployment jobs
39+ uses : actions/upload-artifact@v4
40+ with :
41+ name : python-app
42+ path : |
43+ release.zip
44+ !venv/
45+
46+ deploy :
47+ runs-on : ubuntu-latest
48+ needs : build
49+ environment :
50+ name : ' Production'
51+ url : ${{ steps.deploy-to-webapp.outputs.webapp-url }}
52+ permissions :
53+ id-token : write # This is required for requesting the JWT
54+ env :
55+ HVALFANGST_TENANT_ID : ${{ secrets.HVALFANGST_TENANT_ID }}
56+ HVALFANGST_API_SERVER_CLIENT_ID : ${{ secrets.HVALFANGST_API_SERVER_CLIENT_ID }}
57+
58+ steps :
59+ - name : Download artifact from build job
60+ uses : actions/download-artifact@v4
61+ with :
62+ name : python-app
63+
64+ - name : Unzip artifact for deployment
65+ run : unzip release.zip -d .
66+
67+ - name : Login to Azure
68+ uses : azure/login@v2
69+ with :
70+ client-id : ${{ secrets.AZUREAPPSERVICE_CLIENTID_40531D048E714BC9BF1FF2DB2DD35753 }}
71+ tenant-id : ${{ secrets.AZUREAPPSERVICE_TENANTID_336AC753681745D78B7B262945914F63 }}
72+ subscription-id : ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_97162121CF214550B81AF6E0B11ADA2C }}
73+
74+ - name : Check and set environment variables on Azure App Service if not already set
75+ run : |
76+ # Check for HVALFANGST_TENANT_ID and set it if missing
77+ existing_tenant_id=$(az webapp config appsettings list --name hvalfangstlinuxwebapp \
78+ --resource-group hvalfangstresourcegroup \
79+ --query "[?name=='HVALFANGST_TENANT_ID'].value" \
80+ --output tsv)
81+ if [ -z "$existing_tenant_id" ]; then
82+ echo "Setting HVALFANGST_TENANT_ID..."
83+ az webapp config appsettings set --name hvalfangstlinuxwebapp \
84+ --resource-group hvalfangstresourcegroup \
85+ --settings HVALFANGST_TENANT_ID=${{ secrets.HVALFANGST_TENANT_ID }}
86+ else
87+ echo "HVALFANGST_TENANT_ID is already set."
88+ fi
89+
90+ # Check for HVALFANGST_API_SERVER_CLIENT_ID and set it if missing
91+ existing_client_id=$(az webapp config appsettings list --name hvalfangstlinuxwebapp \
92+ --resource-group hvalfangstresourcegroup \
93+ --query "[?name=='HVALFANGST_API_SERVER_CLIENT_ID'].value" \
94+ --output tsv)
95+ if [ -z "$existing_client_id" ]; then
96+ echo "Setting HVALFANGST_API_SERVER_CLIENT_ID..."
97+ az webapp config appsettings set --name hvalfangstlinuxwebapp \
98+ --resource-group hvalfangstresourcegroup \
99+ --settings HVALFANGST_API_SERVER_CLIENT_ID=${{ secrets.HVALFANGST_API_SERVER_CLIENT_ID }}
100+ else
101+ echo "HVALFANGST_API_SERVER_CLIENT_ID is already set."
102+ fi
103+
104+
105+ - name : ' Deploy to Azure Web App'
106+ uses : azure/webapps-deploy@v3
107+ id : deploy-to-webapp
108+ with :
109+ app-name : ' hvalfangstlinuxwebapp'
110+ slot-name : ' Production'
0 commit comments