-
Notifications
You must be signed in to change notification settings - Fork 2
190 lines (157 loc) · 5.9 KB
/
application.yml
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
---
name: Application
"on":
push:
branches:
- main
paths:
- .github/workflows/application.yml
- src/**
- tests/**
pull_request:
branches:
- main
paths:
- .github/workflows/application.yml
- src/**
- tests/**
workflow_dispatch:
permissions: {}
jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
CONFIGURATION: Release
permissions:
contents: read
checks: write
id-token: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
- name: Setup .NET
uses: actions/setup-dotnet@v4.2.0
with:
dotnet-version: 9.0.x
- name: .NET Restore
run: dotnet restore
- name: .NET Build
run: dotnet build --no-restore --configuration ${{ env.CONFIGURATION }}
- name: .NET Test
run: dotnet test --no-build --configuration ${{ env.CONFIGURATION }} --logger:"xunit;LogFilePath=TestResult.xml"
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.18.0
if: always()
with:
files: |
**/TestResult.xml
- name: Build Container Image
run: dotnet publish src/MovieApi/ --no-restore --configuration ${{ env.CONFIGURATION }} /t:PublishContainer -p ContainerImageTags="${{ github.sha }}"
- name: Azure Login
uses: azure/login@v2.2.0
with:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Push Image to Azure Container Registry
if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
run: |
az acr login --name ${{ vars.CONTAINER_REGISTRY }}
IMAGE="${{ vars.CONTAINER_REGISTRY }}.azurecr.io/ondfisk-githubdemo"
docker tag "ondfisk-githubdemo:${{ github.sha }}" "$IMAGE:${{ github.sha }}"
docker tag "ondfisk-githubdemo:${{ github.sha }}" "$IMAGE:${{ env.IMAGE_TAG }}"
docker push $IMAGE --all-tags
env:
IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || 'test' }}
- name: Install EF Tool
run: |
echo "/github/home/.dotnet/tools" >> "$GITHUB_PATH"
dotnet tool install --global dotnet-ef --prerelease
- name: Generate EF Migration Script
run: dotnet ef migrations script --idempotent --project src/MovieApi/ --startup-project src/MovieApi/ --no-build --output migrate.sql
- name: Upload EF Migration Script
uses: actions/upload-artifact@v4.6.0
with:
name: migrate.sql
path: migrate.sql
staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
environment: Staging
env:
CONNECTION_STRING:
permissions:
id-token: write
steps:
- name: Download EF Migration Script
uses: actions/download-artifact@v4.1.8
with:
name: migrate.sql
path: .
- name: Azure Login
uses: azure/login@v2.2.0
with:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Get Connection String
uses: azure/cli@v2.1.0
with:
inlineScript: |
CONNECTION_STRING=$(az webapp config appsettings list --resource-group ${{ vars.RESOURCE_GROUP }} --name ${{ vars.WEBAPP }} --slot ${{ vars.DEPLOYMENT_SLOT }} --query "[?name=='AZURE_SQL_CONNECTIONSTRING'].value" --output tsv)
echo "CONNECTION_STRING=${CONNECTION_STRING/Authentication=ActiveDirectoryManagedIdentity/Authentication=\"Active Directory Default\"}" >> "$GITHUB_ENV"
- name: Apply EF migration script
uses: Azure/sql-action@v2.3
with:
connection-string: ${{ env.CONNECTION_STRING }}
path: migrate.sql
- name: Deploy Web App Container
uses: azure/webapps-deploy@v3.0.2
with:
app-name: ${{ vars.WEBAPP }}
slot-name: ${{ vars.DEPLOYMENT_SLOT }}
images: ${{ vars.CONTAINER_REGISTRY }}.azurecr.io/ondfisk-githubdemo:${{ env.IMAGE_TAG }}
env:
IMAGE_TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || 'test' }}
production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: staging
if: github.ref == 'refs/heads/main'
environment: Production
env:
CONNECTION_STRING:
permissions:
id-token: write
steps:
- name: Download EF Migration Script
uses: actions/download-artifact@v4.1.8
with:
name: migrate.sql
path: .
- name: Azure Login
uses: azure/login@v2.2.0
with:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Get Connection String
uses: azure/cli@v2.1.0
with:
inlineScript: |
CONNECTION_STRING=$(az webapp config appsettings list --resource-group ${{ vars.RESOURCE_GROUP }} --name ${{ vars.WEBAPP }} --query "[?name=='AZURE_SQL_CONNECTIONSTRING'].value" --output tsv)
echo "CONNECTION_STRING=${CONNECTION_STRING/Authentication=ActiveDirectoryManagedIdentity/Authentication=\"Active Directory Default\"}" >> "$GITHUB_ENV"
- name: Apply EF migration script
uses: Azure/sql-action@v2.3
with:
connection-string: ${{ env.CONNECTION_STRING }}
path: migrate.sql
- name: Swap Staging With Production
uses: azure/cli@v2.1.0
with:
inlineScript: |
az webapp deployment slot swap --resource-group ${{ vars.RESOURCE_GROUP }} --name ${{ vars.WEBAPP }} --slot ${{ vars.DEPLOYMENT_SLOT }}