forked from nisalgunawardhana/github-actions-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (149 loc) · 4.73 KB
/
Copy pathdeploy-azure-app-service.yml
File metadata and controls
176 lines (149 loc) · 4.73 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
name: Deploy to Azure App Service
on:
push:
branches: [main]
paths:
- 'sample-app/**'
- '.github/workflows/deploy-azure-app-service.yml'
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production
jobs:
build:
name: Build Application
runs-on: ubuntu-latest
outputs:
artifact-name: ${{ steps.build.outputs.artifact }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: 'sample-app/package-lock.json'
- name: Install dependencies
working-directory: ./sample-app
run: npm ci
- name: Run tests
working-directory: ./sample-app
run: npm test
continue-on-error: true
- name: Build application
working-directory: ./sample-app
run: npm run build
id: build
- name: Create deployment package
run: |
cd sample-app
zip -r ../app.zip . -x "node_modules/*" ".git/*"
cd ..
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: app.zip
retention-days: 5
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
environment: staging
if: github.event_name == 'push' || github.event.inputs.environment == 'staging'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
continue-on-error: true
- name: Deploy to Azure App Service (Staging)
uses: azure/webapps-deploy@v2
with:
app-name: ${{ secrets.AZURE_APP_SERVICE_STAGING }}
package: ./app.zip
continue-on-error: true
- name: Run health check
run: |
for i in {1..10}; do
if curl -f http://${{ secrets.AZURE_APP_SERVICE_STAGING }}.azurewebsites.net/health; then
echo "✅ Health check passed"
exit 0
fi
echo "⏳ Attempt $i - Waiting for app to be ready..."
sleep 5
done
echo "⚠️ Health check endpoint not responding"
continue-on-error: true
- name: Azure logout
run: az logout
if: always()
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, deploy-staging]
environment: production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
continue-on-error: true
- name: Deploy to Azure App Service (Production)
uses: azure/webapps-deploy@v2
with:
app-name: ${{ secrets.AZURE_APP_SERVICE_PRODUCTION }}
package: ./app.zip
continue-on-error: true
- name: Run health check
run: |
for i in {1..10}; do
if curl -f http://${{ secrets.AZURE_APP_SERVICE_PRODUCTION }}.azurewebsites.net/health; then
echo "✅ Health check passed"
exit 0
fi
echo "⏳ Attempt $i - Waiting for app to be ready..."
sleep 5
done
echo "⚠️ Health check endpoint not responding"
continue-on-error: true
- name: Send deployment notification
run: echo "🚀 Production deployment completed!"
if: always()
- name: Azure logout
run: az logout
if: always()
deployment-summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: always()
steps:
- name: Print deployment summary
run: |
echo "📋 Deployment Summary"
echo "===================="
echo "Staging: ${{ needs.deploy-staging.result }}"
echo "Production: ${{ needs.deploy-production.result }}"
echo ""
echo "View deployment logs for more details"