-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (87 loc) · 3.1 KB
/
deploy.yml
File metadata and controls
101 lines (87 loc) · 3.1 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
name: deploy
on:
workflow_dispatch:
inputs:
environment:
description: Deployment environment.
required: true
default: dev
type: choice
options:
- dev
- prod
resourceGroup:
description: Existing Azure resource group.
required: true
type: string
location:
description: Azure region for resource group creation fallback.
required: true
default: eastus2
type: string
permissions:
contents: read
id-token: write
env:
DOTNET_VERSION: 10.0.x
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Ensure resource group
run: az group create --name "${{ inputs.resourceGroup }}" --location "${{ inputs.location }}"
- name: Bicep what-if
env:
SQL_ADMIN_PASSWORD: ${{ secrets.SQL_ADMIN_PASSWORD }}
run: |
az deployment group what-if \
--resource-group "${{ inputs.resourceGroup }}" \
--template-file infra/main.bicep \
--parameters infra/environments/${{ inputs.environment }}.bicepparam
- name: Deploy infrastructure
id: infra
env:
SQL_ADMIN_PASSWORD: ${{ secrets.SQL_ADMIN_PASSWORD }}
run: |
az deployment group create \
--resource-group "${{ inputs.resourceGroup }}" \
--template-file infra/main.bicep \
--parameters infra/environments/${{ inputs.environment }}.bicepparam \
--query properties.outputs \
--output json > deployment-outputs.json
echo "webAppName=$(jq -r '.webAppName.value' deployment-outputs.json)" >> "$GITHUB_OUTPUT"
echo "stagingUrl=$(jq -r '.stagingUrl.value' deployment-outputs.json)" >> "$GITHUB_OUTPUT"
- name: Publish API
run: dotnet publish src/Devosmos.ApiStarter.Api/Devosmos.ApiStarter.Api.csproj --configuration Release --output artifacts/publish
- name: Package API
run: |
cd artifacts/publish
zip -r ../api.zip .
- name: Deploy to staging slot
uses: azure/webapps-deploy@v3
with:
app-name: ${{ steps.infra.outputs.webAppName }}
slot-name: staging
package: artifacts/api.zip
- name: Smoke test staging
run: curl --fail --retry 12 --retry-delay 10 "${{ steps.infra.outputs.stagingUrl }}/health/live"
- name: Swap staging to production
run: |
az webapp deployment slot swap \
--resource-group "${{ inputs.resourceGroup }}" \
--name "${{ steps.infra.outputs.webAppName }}" \
--slot staging \
--target-slot production