-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-env.yml
123 lines (109 loc) · 6.43 KB
/
deploy-env.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
steps:
- task: AzureCLI@2
displayName: 'Query and store subscription id for unique resource name'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
SUBSCRIPTION_ID=$(az account show --query id --output tsv)
echo "##vso[task.setvariable variable=SubscriptionId]$SUBSCRIPTION_ID"
- checkout: self
- task: AzureCLI@2
displayName: 'Create resource group'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: az group create --name $(TDDResourceGroup) --location $(AzureLocation)
- task: AzureResourceGroupDeployment@2
displayName: 'Create container app environment'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
resourceGroupName: $(TDDResourceGroup)
location: $(AzureLocation)
csmFile: src/Core/ContainerEnvironmentARM.json
overrideParameters: -location $(AzureLocation) -environment_name $(containerAppEnvironmentName) -appInsightsConnectionString $(AppInsightsConnectionString) -containerAppLogAnalyticsName $(containerAppLogAnalyticsName) -subscriptionId $(SubscriptionId) -ResourceGroupName $(TDDResourceGroup)
- task: PowerShell@2
displayName: 'Generate version integer for database server name'
inputs:
targetType: 'inline'
script: |
[System.Environment]::SetEnvironmentVariable('Version','$(Build.BuildNumber)')
$splitVersion = $env:Version -split "\."
$stringVer = $splitVersion[-1]
$intVer = [int]$stringVer
Write-Host "##vso[task.setvariable variable=IntegerVersion]$intVer"
- task: AzureResourceGroupDeployment@2
displayName: 'Create database resource in Azure'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
resourceGroupName: $(TDDResourceGroup)
location: $(AzureLocation)
csmFile: src/Database/DatabaseARM.json
overrideParameters: -databaseserverName $(databaseName) -databaseLogin $(DatabaseUser) -databaseLoginPassword $(DatabasePassword) -skuCapacity 1 -databaseName onioncleandb-$(Environment) -requestedServiceObjectiveName $(DatabasePerformanceLevel)
- task: PowerShell@2
displayName: 'Create database schema'
inputs:
targetType: filePath
filePath: src/Database/scripts/UpdateAzurePipelineSql.ps1
arguments: -DatabaseServer '$(databaseName).database.windows.net' -DatabaseName 'onioncleandb-$(Environment)' -DatabaseAction '$(DatabaseAction)' -DatabaseUser '$(databaseUser)' -DatabasePassword '$(databasePassword)'
- task: AzureCLI@2
displayName: 'Get database connection string'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
$connstring = az sql db show-connection-string --server $(SubscriptionId)-dotnet8-$(Environment) --name $(DatabaseName) --client ado.net
$connstring = $connstring -replace '<username>', '$(DatabaseUser)' -replace '<password>', '$(DatabasePassword)' -replace '"', ''
Write-Host "##vso[task.setvariable variable=DbConnString]$connstring"
- task: AzureResourceGroupDeployment@2
displayName: 'Create container app environment'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
resourceGroupName: $(TDDResourceGroup)
location: $(AzureLocation)
csmFile: src/Core/ContainerEnvironmentARM.json
overrideParameters: -location $(AzureLocation) -environment_name $(containerAppEnvironmentName)-$(Environment)-cae -appInsightsConnectionString $(appInsightsConnectionString) -containerAppLogAnalyticsName $(containerAppLogAnalyticsName) -subscriptionId $(SubscriptionId) -ResourceGroupName $(TDDResourceGroup)
- task: AzureResourceGroupDeployment@2
displayName: 'Create container app'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
resourceGroupName: $(TDDResourceGroup)
location: $(AzureLocation)
csmFile: src/Core/ContainerARM.json
#overrideParameters: -containerappName "$(ContainerAppName)" -location "$(AzureLocation)" -environment_name "$(ResourceGroupName)-$(Environment)-cae" -container_image "$(RegistryLoginServer)/churchbulletin.ui:$(Build.BuildNumber)" -registry_password "$(ContainerRegistryPassword)" -connection_string "$(DbConnString)" -http_port "$(HttpPort)" -appInsightsConnectionString "$(AppInsightsConnectionString)" -registry_login_server "$(RegistryLoginServer)" -app_id "$(AcrContainerAppId)"
overrideParameters: -app_id "$(containerAdmin)" -aspnetcore_environment "$(AspnetcoreEnvironment)" -appInsightsConnectionString "$(appInsightsConnectionString)" -connection_string "$(DbConnString)" -containerappName "$(ContainerAppName)" -container_image "$(registryLoginServer)/churchbulletin.ui:$(Build.BuildNumber)" -environment_name "$(containerAppEnvironmentName)" -http_port "$(HttpPort)" -location "$(AzureLocation)" -registry_login_server "$(registryLoginServer)" -registry_password "$(containerAdminSecret)" -uamiName "$(uamiName)" -SubscriptionId "$(SubscriptionId)" -uamiRGName "$(uamiRGName)"
- task: AzureCLI@2
displayName: 'Get the Fully Qualified Domain Name for the container app'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
$fqdn = az containerapp show --name $(ContainerAppName) --resource-group $(TDDResourceGroup) --query properties.configuration.ingress.fqdn
$fqdn = $fqdn -replace '"', ''
[System.Environment]::SetEnvironmentVariable("containerAppURL", $fqdn, "User")
Write-Host "##vso[task.setvariable variable=fullyQualifiedDomainName]$fqdn"
echo $fqdn
- task: AzureCLI@2
displayName: 'Add revision to container app'
inputs:
azureSubscription: 'onion8-from-scratch-sc'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: az containerapp update --name $(containerAppName) --resource-group $(TDDResourceGroup) --image $(containerImage) --set-env-vars ConnectionStrings__SqlConnectionString="$(DbConnString)" HTTP_PORT=$(HttpPort)
#- task: PowerShell@2
# displayName: 'Check version of deployed app'
# inputs:
# targetType: 'filePath'
# filePath: src/UI/Server/CheckVersion.ps1
# arguments: -server '$(fullyQualifiedDomainName)' -version '$(Build.BuildNumber)'
#- task: PowerShell@2
# displayName: 'Perform healthcheck for server on container app'
# inputs:
# targetType: 'filePath'
# filePath: src/UI/Server/CallHealthCheckEndpoint.ps1
# arguments: -server '$(fullyQualifiedDomainName)'