-
Notifications
You must be signed in to change notification settings - Fork 131
189 lines (158 loc) · 5.99 KB
/
azure-deploy.yml
File metadata and controls
189 lines (158 loc) · 5.99 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Deploy Pets Workshop to Azure
on:
push:
branches: [ main, msignite-25 ]
paths:
- 'terraform/**'
- 'server/**'
- 'client/**'
- '.github/workflows/azure-deploy.yml'
pull_request:
branches: [ main ]
paths:
- 'terraform/**'
- 'server/**'
- 'client/**'
workflow_dispatch:
inputs:
terraform_action:
description: 'Terraform action to perform'
required: true
default: 'plan'
type: choice
options:
- plan
- apply
- destroy
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
TF_VAR_sql_admin_password: ${{ secrets.SQL_ADMIN_PASSWORD }}
jobs:
terraform:
name: 'Terraform Infrastructure'
runs-on: ubuntu-latest
environment: production
defaults:
run:
shell: bash
working-directory: ./terraform
outputs:
backend_app_name: ${{ steps.terraform_output.outputs.backend_app_name }}
frontend_deployment_token: ${{ steps.terraform_output.outputs.frontend_deployment_token }}
resource_group_name: ${{ steps.terraform_output.outputs.resource_group_name }}
static_web_app_name: ${{ steps.terraform_output.outputs.static_web_app_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.0
terraform_wrapper: false
- name: Terraform Init
run: terraform init
- name: Terraform Format Check
run: terraform fmt -check
- name: Terraform Validate
run: terraform validate
- name: Terraform Plan
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'plan')
run: terraform plan -no-color
continue-on-error: true
- name: Terraform Plan Status
if: github.event_name == 'pull_request' && steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply')
run: terraform apply -auto-approve
- name: Terraform Destroy
if: github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'destroy'
run: terraform destroy -auto-approve
- name: Terraform Output
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply')
id: terraform_output
run: |
echo "backend_app_name=$(terraform output -raw backend_app_service_name)" >> $GITHUB_OUTPUT
echo "frontend_deployment_token=$(terraform output -raw frontend_deployment_token)" >> $GITHUB_OUTPUT
echo "resource_group_name=$(terraform output -raw resource_group_name)" >> $GITHUB_OUTPUT
echo "static_web_app_name=$(terraform output -raw frontend_static_web_app_name)" >> $GITHUB_OUTPUT
deploy_backend:
name: 'Deploy Flask Backend'
runs-on: ubuntu-latest
needs: terraform
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
working-directory: ./server
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: ${{ needs.terraform.outputs.backend_app_name }}
package: ./server
startup-command: 'gunicorn --bind=0.0.0.0 --timeout 600 app:app'
deploy_frontend:
name: 'Deploy Astro Frontend'
runs-on: ubuntu-latest
needs: terraform
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: './client/package-lock.json'
- name: Install dependencies
working-directory: ./client
run: npm ci
- name: Build Astro app
working-directory: ./client
run: npm run build
env:
# Update API endpoint to point to Azure App Service
VITE_API_URL: https://${{ needs.terraform.outputs.backend_app_name }}.azurewebsites.net
- name: Deploy to Static Web App
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ needs.terraform.outputs.frontend_deployment_token }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: 'upload'
app_location: '/client'
api_location: ''
output_location: 'dist'
database_setup:
name: 'Setup Database'
runs-on: ubuntu-latest
needs: terraform
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Setup Database Schema
run: |
# Note: Add your database migration/setup commands here
echo "Database setup would go here"
echo "You may want to run SQL scripts to create tables and seed data"
# Example: sqlcmd -S $SQL_SERVER -d $SQL_DATABASE -U $SQL_USER -P $SQL_PASSWORD -i ./database/schema.sql