-
Notifications
You must be signed in to change notification settings - Fork 519
/
deploy-stage.yml
169 lines (161 loc) · 8.87 KB
/
deploy-stage.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
# Blue Green deployment to app service for container of presidio services.
# The template uses a deployment and runs smoke test on health endpoint
# before switching the slots.
parameters:
ENVIRONMNT_NAME:
REGISTRY_NAME:
AZURE_SUBSCRIPTION:
ANALYZER_APP_NAME:
ANONYMIZER_APP_NAME:
IMAGE_REDACTOR_APP_NAME:
RESOURCE_GROUP_NAME:
TAG:
jobs:
- job: DeployAnalyzer
displayName: Deploy Analyzer to ${{ parameters.ENVIRONMNT_NAME }} Environment
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eu # fail on error
az webapp deployment slot create --name ${{ parameters.ANALYZER_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --configuration-source ${{ parameters.ANALYZER_APP_NAME }} --slot staging
URI=https://$(az webapp config hostname list --webapp-name ${{ parameters.ANALYZER_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --slot staging --query '[0].name' -o tsv)
echo $URI
echo "##vso[task.setvariable variable=STAGING_URI;isOutput=true]$URI"
- task: AzureWebAppContainer@1
displayName: Deploy to staging slot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
deployToSlotOrASE: true
resourceGroupName: ${{ parameters.RESOURCE_GROUP_NAME }}
appName: ${{ parameters.ANALYZER_APP_NAME }}
slotName: staging
imageName: ${{ parameters.REGISTRY_NAME }}presidio-analyzer:${{ parameters.TAG }}
- job: DeployAnonymizer
displayName: Deploy Anonymizer to ${{ parameters.ENVIRONMNT_NAME }} Environment
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eu # fail on error
az webapp deployment slot create --name ${{ parameters.ANONYMIZER_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --configuration-source ${{ parameters.ANONYMIZER_APP_NAME }} --slot staging
URI=https://$(az webapp config hostname list --webapp-name ${{ parameters.ANONYMIZER_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --slot staging --query '[0].name' -o tsv)
echo $URI
echo "##vso[task.setvariable variable=STAGING_URI;isOutput=true]$URI"
- task: AzureWebAppContainer@1
displayName: Deploy to staging slot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
deployToSlotOrASE: true
resourceGroupName: ${{ parameters.RESOURCE_GROUP_NAME }}
appName: ${{ parameters.ANONYMIZER_APP_NAME }}
slotName: staging
imageName: ${{ parameters.REGISTRY_NAME }}presidio-anonymizer:${{ parameters.TAG }}
- job: DeployImageRedactor
displayName: Deploy Image Redactor to ${{ parameters.ENVIRONMNT_NAME }} Environment
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eu # fail on error
az webapp deployment slot create --name ${{ parameters.IMAGE_REDACTOR_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --configuration-source ${{ parameters.IMAGE_REDACTOR_APP_NAME }} --slot staging
URI=https://$(az webapp config hostname list --webapp-name ${{ parameters.IMAGE_REDACTOR_APP_NAME }} --resource-group ${{ parameters.RESOURCE_GROUP_NAME }} --slot staging --query '[0].name' -o tsv)
echo $URI
echo "##vso[task.setvariable variable=STAGING_URI;isOutput=true]$URI"
- task: AzureWebAppContainer@1
displayName: Deploy to staging slot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
deployToSlotOrASE: true
resourceGroupName: ${{ parameters.RESOURCE_GROUP_NAME }}
appName: ${{ parameters.IMAGE_REDACTOR_APP_NAME }}
slotName: staging
imageName: ${{ parameters.REGISTRY_NAME }}presidio-image-redactor:${{ parameters.TAG }}
- job: TestDeployment
displayName: Smoke and E2E Tests on the deployement
dependsOn:
- DeployAnalyzer
- DeployAnonymizer
- DeployImageRedactor
variables:
ANALYZER_STAGING_URI: $[ dependencies.DeployAnalyzer.outputs['createStagingSlot.STAGING_URI'] ]
ANONYMIZER_STAGING_URI: $[ dependencies.DeployAnonymizer.outputs['createStagingSlot.STAGING_URI'] ]
IMAGE_REDACTOR_STAGING_URI: $[ dependencies.DeployImageRedactor.outputs['createStagingSlot.STAGING_URI'] ]
steps:
- task: Bash@3
displayName: 'Wait and Smoke test'
timeoutInMinutes: 10
inputs:
targetType: 'inline'
script: |
set -ux # do not fail on error
ANALYZER_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $ANALYZER_STAGING_URI/health)
ANONYMIZER_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $ANONYMIZER_STAGING_URI/health)
IMAGE_REDACTOR_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $IMAGE_REDACTOR_STAGING_URI/health)
echo analyzer status code is $ANALYZER_STATUS_CODE
echo anonymizer status code is $ANONYMIZER_STATUS_CODE
echo image redactor status code is $IMAGE_REDACTOR_STATUS_CODE
while [ ! $ANALYZER_STATUS_CODE == 200 ] || [ ! $ANONYMIZER_STATUS_CODE == 200 ] || [ ! $IMAGE_REDACTOR_STATUS_CODE == 200 ]
do
sleep 30
ANALYZER_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $ANALYZER_STAGING_URI/health)
ANONYMIZER_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $ANONYMIZER_STAGING_URI/health)
IMAGE_REDACTOR_STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 --max-time 10 $IMAGE_REDACTOR_STAGING_URI/health)
echo analyzer status code is $ANALYZER_STATUS_CODE
echo anonymizer status code is $ANONYMIZER_STATUS_CODE
echo image redactor status code is $IMAGE_REDACTOR_STATUS_CODE
done
- template: ./e2e-tests.yml
parameters:
test_suite: 'integration'
analyzer_base_url: $(ANALYZER_STAGING_URI)
anonymizer_base_url: $(ANONYMIZER_STAGING_URI)
- job: SwapBothSlots
condition: eq(dependencies.TestDeployment.result, 'Succeeded')
strategy:
matrix:
Analyzer:
Name: 'Analyzer'
AppServiceName: ${{ parameters.ANALYZER_APP_NAME }}
Anonymizer:
Name: 'Anonymizer'
AppServiceName: ${{ parameters.ANONYMIZER_APP_NAME }}
ImageRedactor:
Name: 'ImageRedactor'
AppServiceName: ${{ parameters.IMAGE_REDACTOR_APP_NAME }}
displayName: Swap slots from staging to production
dependsOn: TestDeployment
steps:
- checkout: none
- task: AzureAppServiceManage@0
displayName: Swap $(Name) slot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
action: Swap Slots
webAppName: $(AppServiceName)
sourceSlot: staging
resourceGroupName: ${{ parameters.RESOURCE_GROUP_NAME }}