-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (187 loc) · 8.87 KB
/
Copy pathdeploy-management-portal.yml
File metadata and controls
218 lines (187 loc) · 8.87 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Deploy Management Portal to Container Apps
on:
push:
branches: [ main, master ]
paths:
- 'management-portal/**'
pull_request:
branches: [ main, master ]
paths:
- 'management-portal/**'
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'production'
type: choice
options:
- development
- staging
- production
permissions:
id-token: write
contents: read
env:
AZURE_SUBSCRIPTION_ID: 480cb033-9a92-4912-9d30-c6b7bf795a87
RESOURCE_GROUP_NAME: ${{ vars.RESOURCE_GROUP_NAME || 'rg-stamps-mgmt-prod' }}
LOCATION: ${{ vars.LOCATION || 'westus2' }}
ENVIRONMENT_NAME: ${{ vars.ENVIRONMENT_NAME || 'stamps-mgmt' }}
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore management-portal/src/Portal/Portal.csproj
- name: Build application
run: dotnet build management-portal/src/Portal/Portal.csproj --configuration Release --no-restore
# - name: Run tests
# run: dotnet test management-portal/Tests/ --configuration Release --no-build --verbosity normal
# Note: Tests directory does not exist yet, skipping tests for now
deploy-infrastructure:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch'
needs: build-and-test
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment || 'production' }}
outputs:
containerRegistryName: ${{ steps.deploy.outputs.containerRegistryName }}
containerRegistryLoginServer: ${{ steps.deploy.outputs.containerRegistryLoginServer }}
portalUrl: ${{ steps.deploy.outputs.portalUrl }}
dabUrl: ${{ steps.deploy.outputs.dabUrl }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set up dynamic variables
id: vars
run: |
SUFFIX=$(date +%Y%m%d%H%M | cut -c7-12)
echo "CONTAINER_REGISTRY_NAME=cr${{ env.ENVIRONMENT_NAME }}${SUFFIX}" | sed 's/-//g' >> $GITHUB_OUTPUT
echo "COSMOS_ACCOUNT_NAME=cosmos-${{ env.ENVIRONMENT_NAME }}-${SUFFIX}" >> $GITHUB_OUTPUT
echo "CONTAINER_APPS_ENV_NAME=cae-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
echo "LOG_ANALYTICS_NAME=law-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
echo "APP_INSIGHTS_NAME=ai-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
- name: Deploy Azure Infrastructure
id: deploy
uses: azure/arm-deploy@v2
with:
subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ env.RESOURCE_GROUP_NAME }}
template: management-portal/infra/management-portal.bicep
parameters: >
location=${{ env.LOCATION }}
cosmosAccountName=${{ steps.vars.outputs.COSMOS_ACCOUNT_NAME }}
containerAppsEnvironmentName=${{ steps.vars.outputs.CONTAINER_APPS_ENV_NAME }}
containerRegistryName=${{ steps.vars.outputs.CONTAINER_REGISTRY_NAME }}
logAnalyticsWorkspaceName=${{ steps.vars.outputs.LOG_ANALYTICS_NAME }}
appInsightsName=${{ steps.vars.outputs.APP_INSIGHTS_NAME }}
portalImage=temp-image:latest
dabImage=temp-image:latest
- name: Create resource group if needed
run: |
az group create \
--name ${{ env.RESOURCE_GROUP_NAME }} \
--location ${{ env.LOCATION }} \
--output none
build-and-push-images:
needs: deploy-infrastructure
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment || 'production' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Login to Container Registry
run: az acr login --name ${{ needs.deploy-infrastructure.outputs.containerRegistryName }}
- name: Build and push Portal image
run: |
cd management-portal/src/Portal
docker build -t ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-portal:${{ github.sha }} .
docker build -t ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-portal:latest .
docker push ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-portal:${{ github.sha }}
docker push ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-portal:latest
- name: Build and push DAB image
run: |
cd management-portal/dab
docker build -t ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-dab:${{ github.sha }} .
docker build -t ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-dab:latest .
docker push ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-dab:${{ github.sha }}
docker push ${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-dab:latest
update-container-apps:
needs: [deploy-infrastructure, build-and-push-images]
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment || 'production' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Azure Login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set up dynamic variables
id: vars
run: |
SUFFIX=$(date +%Y%m%d%H%M | cut -c7-12)
echo "COSMOS_ACCOUNT_NAME=cosmos-${{ env.ENVIRONMENT_NAME }}-${SUFFIX}" >> $GITHUB_OUTPUT
echo "CONTAINER_APPS_ENV_NAME=cae-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
echo "LOG_ANALYTICS_NAME=law-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
echo "APP_INSIGHTS_NAME=ai-${{ env.ENVIRONMENT_NAME }}" >> $GITHUB_OUTPUT
- name: Update Container Apps with new images
uses: azure/arm-deploy@v2
with:
subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ env.RESOURCE_GROUP_NAME }}
template: management-portal/infra/management-portal.bicep
parameters: >
location=${{ env.LOCATION }}
cosmosAccountName=${{ steps.vars.outputs.COSMOS_ACCOUNT_NAME }}
containerAppsEnvironmentName=${{ steps.vars.outputs.CONTAINER_APPS_ENV_NAME }}
containerRegistryName=${{ needs.deploy-infrastructure.outputs.containerRegistryName }}
logAnalyticsWorkspaceName=${{ steps.vars.outputs.LOG_ANALYTICS_NAME }}
appInsightsName=${{ steps.vars.outputs.APP_INSIGHTS_NAME }}
portalImage=${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-portal:${{ github.sha }}
dabImage=${{ needs.deploy-infrastructure.outputs.containerRegistryLoginServer }}/stamps-dab:${{ github.sha }}
- name: Verify deployment
run: |
echo "🎉 Deployment completed successfully!"
echo "Portal URL: ${{ needs.deploy-infrastructure.outputs.portalUrl }}"
echo "DAB URL: ${{ needs.deploy-infrastructure.outputs.dabUrl }}"
# Health check
sleep 30
curl -f "${{ needs.deploy-infrastructure.outputs.portalUrl }}/health" || echo "Health check failed"
post-deployment:
needs: [deploy-infrastructure, update-container-apps]
runs-on: ubuntu-latest
if: always()
steps:
- name: Post deployment summary
run: |
echo "## Deployment Summary 🚀" >> $GITHUB_STEP_SUMMARY
echo "| Component | URL |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|-----|" >> $GITHUB_STEP_SUMMARY
echo "| Management Portal | ${{ needs.deploy-infrastructure.outputs.portalUrl }} |" >> $GITHUB_STEP_SUMMARY
echo "| Data API Builder | ${{ needs.deploy-infrastructure.outputs.dabUrl }} |" >> $GITHUB_STEP_SUMMARY
echo "| Container Registry | ${{ needs.deploy-infrastructure.outputs.containerRegistryName }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps:" >> $GITHUB_STEP_SUMMARY
echo "1. Configure Azure Entra ID authentication" >> $GITHUB_STEP_SUMMARY
echo "2. Set up custom domain and SSL certificates" >> $GITHUB_STEP_SUMMARY
echo "3. Configure monitoring alerts" >> $GITHUB_STEP_SUMMARY