-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (137 loc) · 5.34 KB
/
azure-webapps-python.yml
File metadata and controls
158 lines (137 loc) · 5.34 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
name: Build and deploy Python app to Azure Web App
env:
AZURE_WEBAPP_NAME: instantapply # set this to the name of your Azure Web App
PYTHON_VERSION: '3.11'
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: jeevanbhatta/instantapply
on:
push:
branches: [ "production" ]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Build React frontend
run: |
cd react-frontend
npm ci
export CI=false
npm run build
echo "React build completed successfully"
- name: Copy React build to backend/static
run: |
mkdir -p backend/static
rm -rf backend/static/*
cp -r react-frontend/build/* backend/static/
echo "React build files copied to backend/static"
ls -la backend/static
- name: Set up Python version
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: '**/requirements.txt'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:latest
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:v1.0.${{ github.run_number }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: 'Login to Azure'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Configure Azure App Service to be able to pull the image from GitHub Container Registry
- name: 'Configure Container Registry Authentication'
uses: azure/cli@v1
with:
azcliversion: latest
inlineScript: |
# Configure Azure to authenticate with GitHub Container Registry
az webapp config container set \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ env.AZURE_WEBAPP_NAME }} \
--docker-registry-server-url https://${{ env.DOCKER_REGISTRY }} \
--docker-registry-server-user ${{ github.actor }} \
--docker-registry-server-password ${{ secrets.GITHUB_TOKEN }}
- name: 'Deploy Docker container to Azure App Service'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:latest
- name: 'Configure App Settings'
uses: azure/cli@v1
with:
azcliversion: latest
inlineScript: |
az webapp config appsettings set --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ env.AZURE_WEBAPP_NAME }} --settings \
FLASK_DEBUG=False \
WEBSITES_PORT=8000 \
WEBSITE_HTTPLOGGING_RETENTION_DAYS=3 \
SCM_DO_BUILD_DURING_DEPLOYMENT=true \
SECRET_KEY="${{ secrets.SECRET_KEY }}" \
DATABASE_URL="${{ secrets.DATABASE_URL }}" \
GEMINI_API_KEY="${{ secrets.GEMINI_API_KEY }}"
- name: 'Configure Health Check'
uses: azure/cli@v1
with:
azcliversion: latest
inlineScript: |
# Configure health check settings using generic-configurations
az webapp config set \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ env.AZURE_WEBAPP_NAME }} \
--generic-configurations '{"healthCheckPath": "/health"}' \
--always-on true
# Configure container settings
az webapp config container set \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ env.AZURE_WEBAPP_NAME }} \
--enable-app-service-storage true \
--docker-registry-server-url https://${{ env.DOCKER_REGISTRY }}
# Set application settings for health check
az webapp config appsettings set \
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ env.AZURE_WEBAPP_NAME }} \
--settings \
WEBSITES_CONTAINER_START_TIME_LIMIT=1800 \
WEBSITES_ENABLE_APP_SERVICE_STORAGE=true \
WEBSITE_HEALTHCHECK_MAXPINGFAILURES=3 \
WEBSITE_HEALTHCHECK_PATH=/health