/
deploy-all.yml
107 lines (95 loc) · 4.19 KB
/
deploy-all.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
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
variables:
- group: 'secrets'
- name: solution
value: '**/*.sln'
- name: buildPlatform
value: 'Any CPU'
- name: buildConfiguration
value: 'Release'
stages:
- stage: Database
jobs:
- job: Dacpac
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
displayName: 'Create and configure Azure SQL logical server'
inputs:
azureSubscription: '$(subscription-name)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az sql server create --resource-group $(resource-group-name) --name $(logical-sql-server-name) --admin-user $(sql-admin-login) --admin-password $(sql-password)
az sql server ad-admin create --resource-group $(resource-group-name) --server-name $(logical-sql-server-name) --display-name $(az ad sp show --id $(az account show --query user.name --output tsv) --query appDisplayName --output tsv) --object-id $(az account show --query user.name --output tsv)
az sql server firewall-rule create -g $(resource-group-name) -s $(logical-sql-server-name) -n allow-azure-services --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
- task: AzureCLI@2
displayName: 'Create Azure SQL Elastic Pool and Database'
inputs:
azureSubscription: '$(subscription-name)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az sql elastic-pool create -g $(resource-group-name) -s $(logical-sql-server-name) -n $(elastic-pool-name) -e GeneralPurpose -f Gen4 -c 1
az sql db create --resource-group $(resource-group-name) --server $(logical-sql-server-name) --name $(sql-database-name) --elastic-pool $(elastic-pool-name)
- task: VSBuild@1
displayName: 'Build DACPAC from SQL Database Project'
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts@1
displayName: 'Publish SQL Project output as Azure DevOps artifacts'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/sql'
ArtifactName: 'sqlproj_artifacts_$(System.JobAttempt)'
publishLocation: 'Container'
- task: DownloadBuildArtifacts@0
displayName: 'Download the artifacts'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'sqlproj_artifacts_$(System.JobAttempt)'
downloadPath: '$(System.ArtifactsDirectory)'
- task: SqlAzureDacpacDeployment@1
displayName: 'Deploy Azure SQL DB'
inputs:
azureSubscription: '$(subscription-name)'
AuthenticationType: 'servicePrincipal'
ServerName: '$(logical-sql-server-name).database.windows.net'
DatabaseName: '$(sql-database-name)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: '$(System.ArtifactsDirectory)/sqlproj_artifacts_$(System.JobAttempt)/wwi-dw-ssdt/bin/Release/WideWorldImportersDW.dacpac'
AdditionalArguments: '/v:ETLUserPassword="$(sql-password)" /v:AppUserPassword="$(sql-password)"'
IpDetectionMethod: 'AutoDetect'
DeleteFirewallRule: false
- stage: WebApp
jobs:
- job: WebApp
pool:
vmImage: 'ubuntu-latest'
steps:
- task: AzureStaticWebApp@0
displayName: 'Deploy static web app'
inputs:
app_location: './my-app'
app_build_command: 'node_modules/.bin/vue-cli-service build'
output_location: 'dist'
api_location: './api'
api_build_command: 'node_modules/.bin/tsc'
env:
azure_static_web_apps_api_token: $(swa-deploytoken)
- task: AzureCLI@2
displayName: 'Set static web app DB connection string'
inputs:
azureSubscription: '$(subscription-name)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az staticwebapp appsettings set -n $(swa_name) --setting-names AZURESQL=$(logical-sql-server-name) AZURESQL_DB=$(sql-database-name) AZURESQL_USER=$(sql-admin-login) AZURESQL_PASSWORD=$(sql-password)'