-
Notifications
You must be signed in to change notification settings - Fork 0
310 lines (259 loc) · 14.7 KB
/
release-to-production.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: Release to Production
on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: "0 3 * * 3" # Every Wednesday at 3am
permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout
concurrency: # This is required to prevent multiple runs of the same workflow from running at the same time.
group: ${{ github.workflow }}
jobs:
dotnet-web-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/dotnet-web-ci@main
with:
dotnet-project: "repository-webapi"
dotnet-version: 9.0.x
src-folder: "src"
majorMinorVersion: "1.1"
publish-nuget-packages:
environment: NuGet
runs-on: ubuntu-latest
needs: [dotnet-web-ci]
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/publish-nuget-packages@main
with:
artifact-name: "nuget-packages"
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- id: terraform-output
shell: bash
run: |
cd terraform
echo "web_app_name=$(terraform output -raw web_app_name)" >> $GITHUB_OUTPUT
echo "web_app_resource_group=$(terraform output -raw web_app_resource_group)" >> $GITHUB_OUTPUT
echo "workload_public_url=$(terraform output -raw workload_public_url)" >> $GITHUB_OUTPUT
echo "sql_server_fqdn=$(terraform output -raw sql_server_fqdn)" >> $GITHUB_OUTPUT
echo "sql_database_name=$(terraform output -raw sql_database_name)" >> $GITHUB_OUTPUT
echo "key_vault_name=$(terraform output -raw key_vault_name)" >> $GITHUB_OUTPUT
echo "integration_tests_account_name=$(terraform output -raw integration_tests_account_name)" >> $GITHUB_OUTPUT
echo "api_audience=$(terraform output -raw api_audience)" >> $GITHUB_OUTPUT
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_USE_AZUREAD: true
ARM_USE_OIDC: true
outputs:
web_app_name: ${{ steps.terraform-output.outputs.web_app_name }}
web_app_resource_group: ${{ steps.terraform-output.outputs.web_app_resource_group }}
workload_public_url: ${{ steps.terraform-output.outputs.workload_public_url }}
sql_server_fqdn: ${{ steps.terraform-output.outputs.sql_server_fqdn }}
sql_database_name: ${{ steps.terraform-output.outputs.sql_database_name }}
key_vault_name: ${{ steps.terraform-output.outputs.key_vault_name }}
integration_tests_account_name: ${{ steps.terraform-output.outputs.integration_tests_account_name }}
api_audience: ${{ steps.terraform-output.outputs.api_audience }}
deploy-sql-database-dev:
environment: Development
runs-on: ubuntu-latest
needs: [terraform-plan-and-apply-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-sql-database@main
with:
sql-args: /Variables:env=dev /Variables:instance=01
sql-server-fqdn: ${{ needs.terraform-plan-and-apply-dev.outputs.sql_server_fqdn }}
sql-database-name: ${{ needs.terraform-plan-and-apply-dev.outputs.sql_database_name }}
project-folder: "src/database"
project-file: "database.sqlproj"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
app-service-deploy-dev:
environment: Development
runs-on: ubuntu-latest
needs: [dotnet-web-ci, deploy-sql-database-dev, terraform-plan-and-apply-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-app-service@main
with:
web-artifact-name: "repository-webapi"
web-app-name: ${{ needs.terraform-plan-and-apply-dev.outputs.web_app_name }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
run-api-integration-tests-dev:
environment: Development
runs-on: ubuntu-latest
needs: [app-service-deploy-dev, terraform-plan-and-apply-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- name: "Az CLI Login"
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- shell: bash
run: |
client_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-id" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
client_secret=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-secret" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
client_tenant_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-tenant-id" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
api_key=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-api-key-primary" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
echo "::add-mask::$client_id"
echo "::add-mask::$client_secret"
echo "::add-mask::$client_tenant_id"
echo "::add-mask::$api_key"
echo "int_test_client_id=$client_id" >> $GITHUB_ENV
echo "int_test_client_secret=$client_secret" >> $GITHUB_ENV
echo "int_test_client_tenant_id=$client_tenant_id" >> $GITHUB_ENV
echo "int_test_api_key=$api_key" >> $GITHUB_ENV
- uses: frasermolyneux/actions/run-api-integration-tests@main
with:
dotnet-version: 9.0.x
src-folder: "src"
api-base-url: ${{ needs.terraform-plan-and-apply-dev.outputs.workload_public_url }}
api-key: ${{ env.int_test_api_key }}
api-audience: ${{ needs.terraform-plan-and-apply-dev.outputs.api_audience }}
AZURE_CLIENT_ID: ${{ env.int_test_client_id }}
AZURE_CLIENT_SECRET: ${{ env.int_test_client_secret }}
AZURE_TENANT_ID: ${{ env.int_test_client_tenant_id }}
terraform-plan-and-apply-prd:
environment: Production
runs-on: ubuntu-latest
needs: [run-api-integration-tests-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/prd.tfvars"
terraform-backend-file: "backends/prd.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- id: terraform-output
shell: bash
run: |
cd terraform
echo "web_app_name=$(terraform output -raw web_app_name)" >> $GITHUB_OUTPUT
echo "web_app_resource_group=$(terraform output -raw web_app_resource_group)" >> $GITHUB_OUTPUT
echo "workload_public_url=$(terraform output -raw workload_public_url)" >> $GITHUB_OUTPUT
echo "sql_server_fqdn=$(terraform output -raw sql_server_fqdn)" >> $GITHUB_OUTPUT
echo "sql_database_name=$(terraform output -raw sql_database_name)" >> $GITHUB_OUTPUT
echo "key_vault_name=$(terraform output -raw key_vault_name)" >> $GITHUB_OUTPUT
echo "integration_tests_account_name=$(terraform output -raw integration_tests_account_name)" >> $GITHUB_OUTPUT
echo "api_audience=$(terraform output -raw api_audience)" >> $GITHUB_OUTPUT
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_USE_AZUREAD: true
ARM_USE_OIDC: true
outputs:
web_app_name: ${{ steps.terraform-output.outputs.web_app_name }}
web_app_resource_group: ${{ steps.terraform-output.outputs.web_app_resource_group }}
workload_public_url: ${{ steps.terraform-output.outputs.workload_public_url }}
sql_server_fqdn: ${{ steps.terraform-output.outputs.sql_server_fqdn }}
sql_database_name: ${{ steps.terraform-output.outputs.sql_database_name }}
key_vault_name: ${{ steps.terraform-output.outputs.key_vault_name }}
integration_tests_account_name: ${{ steps.terraform-output.outputs.integration_tests_account_name }}
api_audience: ${{ steps.terraform-output.outputs.api_audience }}
deploy-sql-database-prd:
environment: Production
runs-on: ubuntu-latest
needs: [terraform-plan-and-apply-prd]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-sql-database@main
with:
sql-args: /Variables:env=prd /Variables:instance=01
sql-server-fqdn: ${{ needs.terraform-plan-and-apply-prd.outputs.sql_server_fqdn }}
sql-database-name: ${{ needs.terraform-plan-and-apply-prd.outputs.sql_database_name }}
project-folder: "src/database"
project-file: "database.sqlproj"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
app-service-deploy-prd:
environment: Production
runs-on: ubuntu-latest
needs: [dotnet-web-ci, deploy-sql-database-prd, terraform-plan-and-apply-prd]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/deploy-app-service@main
with:
web-artifact-name: "repository-webapi"
web-app-name: ${{ needs.terraform-plan-and-apply-prd.outputs.web_app_name }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
run-api-integration-tests-prd:
environment: Production
runs-on: ubuntu-latest
needs: [app-service-deploy-prd, terraform-plan-and-apply-prd]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- name: "Az CLI Login"
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- shell: bash
run: |
client_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-prd.outputs.integration_tests_account_name }}-client-id" --vault-name "${{ needs.terraform-plan-and-apply-prd.outputs.key_vault_name }}" --query value -o tsv)
client_secret=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-prd.outputs.integration_tests_account_name }}-client-secret" --vault-name "${{ needs.terraform-plan-and-apply-prd.outputs.key_vault_name }}" --query value -o tsv)
client_tenant_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-prd.outputs.integration_tests_account_name }}-client-tenant-id" --vault-name "${{ needs.terraform-plan-and-apply-prd.outputs.key_vault_name }}" --query value -o tsv)
api_key=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-prd.outputs.integration_tests_account_name }}-api-key-primary" --vault-name "${{ needs.terraform-plan-and-apply-prd.outputs.key_vault_name }}" --query value -o tsv)
echo "::add-mask::$client_id"
echo "::add-mask::$client_secret"
echo "::add-mask::$client_tenant_id"
echo "::add-mask::$api_key"
echo "int_test_client_id=$client_id" >> $GITHUB_ENV
echo "int_test_client_secret=$client_secret" >> $GITHUB_ENV
echo "int_test_client_tenant_id=$client_tenant_id" >> $GITHUB_ENV
echo "int_test_api_key=$api_key" >> $GITHUB_ENV
- uses: frasermolyneux/actions/run-api-integration-tests@main
with:
dotnet-version: 9.0.x
src-folder: "src"
api-base-url: ${{ needs.terraform-plan-and-apply-prd.outputs.workload_public_url }}
api-key: ${{ env.int_test_api_key }}
api-audience: ${{ needs.terraform-plan-and-apply-prd.outputs.api_audience }}
AZURE_CLIENT_ID: ${{ env.int_test_client_id }}
AZURE_CLIENT_SECRET: ${{ env.int_test_client_secret }}
AZURE_TENANT_ID: ${{ env.int_test_client_tenant_id }}