Skip to content

Commit 323f08b

Browse files
committed
Add CD workflow for Azure deployment to rg-dev-125
1 parent 2e9a8f7 commit 323f08b

1 file changed

Lines changed: 181 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
env:
13+
ENVIRONMENT: dev
14+
INSTANCE: "125"
15+
RESOURCE_GROUP: rg-dev-125
16+
BACKEND_APP_NAME: app-backend-dev-125
17+
FRONTEND_APP_NAME: app-frontend-dev-125
18+
SQL_SERVER_NAME: sql-dev-125
19+
SQL_DATABASE_NAME: sqldb-dev-125
20+
21+
jobs:
22+
build-backend:
23+
name: Build Backend
24+
runs-on: ubuntu-latest
25+
defaults:
26+
run:
27+
working-directory: backend
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up Java 21
32+
uses: actions/setup-java@v4
33+
with:
34+
distribution: temurin
35+
java-version: "21"
36+
cache: maven
37+
38+
- name: Build with Maven (skip tests — already validated in CI)
39+
run: |
40+
chmod +x ./mvnw
41+
./mvnw -B package -DskipTests
42+
43+
- name: Upload backend artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: backend-artifact
47+
path: backend/target/*.jar
48+
49+
build-frontend:
50+
name: Build Frontend
51+
runs-on: ubuntu-latest
52+
defaults:
53+
run:
54+
working-directory: frontend
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Set up Node 20
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: "20"
62+
cache: npm
63+
cache-dependency-path: frontend/package-lock.json
64+
65+
- name: Install dependencies
66+
run: npm ci
67+
68+
- name: Build for production
69+
run: npm run build
70+
env:
71+
VITE_API_BASE_URL: /api
72+
73+
- name: Upload frontend artifact
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: frontend-artifact
77+
path: frontend/dist
78+
79+
deploy-database:
80+
name: Deploy Database Migrations
81+
runs-on: ubuntu-latest
82+
needs: [build-backend]
83+
environment: dev
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Azure Login
88+
uses: azure/login@v2
89+
with:
90+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
91+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
92+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
93+
94+
- name: Run Flyway migrations
95+
uses: azure/sql-action@v2.3
96+
with:
97+
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
98+
path: database/migrations
99+
action: script
100+
101+
deploy-backend:
102+
name: Deploy Backend API
103+
runs-on: ubuntu-latest
104+
needs: [build-backend, deploy-database]
105+
environment: dev
106+
steps:
107+
- name: Download backend artifact
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: backend-artifact
111+
path: backend-artifact
112+
113+
- name: Azure Login
114+
uses: azure/login@v2
115+
with:
116+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
117+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
118+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
119+
120+
- name: Deploy to Azure App Service
121+
uses: azure/webapps-deploy@v3
122+
with:
123+
app-name: ${{ env.BACKEND_APP_NAME }}
124+
package: backend-artifact
125+
126+
deploy-frontend:
127+
name: Deploy Frontend
128+
runs-on: ubuntu-latest
129+
needs: [build-frontend, deploy-backend]
130+
environment: dev
131+
steps:
132+
- name: Download frontend artifact
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: frontend-artifact
136+
path: frontend-artifact
137+
138+
- name: Azure Login
139+
uses: azure/login@v2
140+
with:
141+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
142+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
143+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
144+
145+
- name: Deploy to Azure App Service
146+
uses: azure/webapps-deploy@v3
147+
with:
148+
app-name: ${{ env.FRONTEND_APP_NAME }}
149+
package: frontend-artifact
150+
151+
smoke-test:
152+
name: Smoke Test
153+
runs-on: ubuntu-latest
154+
needs: [deploy-backend, deploy-frontend]
155+
environment: dev
156+
steps:
157+
- name: Health check — Backend API
158+
run: |
159+
for i in 1 2 3 4 5; do
160+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
161+
"https://${{ env.BACKEND_APP_NAME }}.azurewebsites.net/api/health")
162+
if [ "$STATUS" = "200" ]; then
163+
echo "Backend health check passed"
164+
exit 0
165+
fi
166+
echo "Attempt $i — status $STATUS, retrying in 15s..."
167+
sleep 15
168+
done
169+
echo "Backend health check failed after 5 attempts"
170+
exit 1
171+
172+
- name: Health check — Frontend
173+
run: |
174+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
175+
"https://${{ env.FRONTEND_APP_NAME }}.azurewebsites.net/")
176+
if [ "$STATUS" = "200" ]; then
177+
echo "Frontend health check passed"
178+
else
179+
echo "Frontend health check failed with status $STATUS"
180+
exit 1
181+
fi

0 commit comments

Comments
 (0)