Skip to content

Commit

Permalink
Add Image Redactor to CI pipeline (microsoft#530)
Browse files Browse the repository at this point in the history
* add image-redactor to pr pipeline
  • Loading branch information
navalev authored Feb 22, 2021
1 parent d3a504c commit 34e371a
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 168 deletions.
299 changes: 169 additions & 130 deletions .pipelines/templates/deploy-stage.yml
Original file line number Diff line number Diff line change
@@ -1,130 +1,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:
RESOURCE_GROUP_NAME:
TAG:
jobs:
- job: DeployAnalyzer
displayName: Deploy Analyzer to ${{ parameters.ENVIRONMNT_NAME }} Environment
pool:
vmImage: 'ubuntu-16.04'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eux # 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-16.04'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eux # 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: TestDeployment
displayName: Smoke and E2E Tests on the deployement
dependsOn:
- DeployAnalyzer
- DeployAnonymizer
variables:
ANALYZER_STAGING_URI: $[ dependencies.DeployAnalyzer.outputs['createStagingSlot.STAGING_URI'] ]
ANONYMIZER_STAGING_URI: $[ dependencies.DeployAnonymizer.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)
echo analyzer status code is $ANALYZER_STATUS_CODE
echo anonymizer status code is $ANONYMIZER_STATUS_CODE
while [ ! $ANALYZER_STATUS_CODE == 200 ] || [ ! $ANONYMIZER_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)
echo analyzer status code is $ANALYZER_STATUS_CODE
echo anonymizer status code is $ANONYMIZER_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 }}
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 }}
# 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-16.04'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eux # 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-16.04'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eux # 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-16.04'
steps:
- checkout: none
- task: AzureCLI@2
displayName: Create staging slot
name: createStagingSlot
inputs:
azureSubscription: ${{ parameters.AZURE_SUBSCRIPTION }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -eux # 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 }}
1 change: 1 addition & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ stages:
AZURE_SUBSCRIPTION: $(DEV_AZURE_SUBSCRIPTION)
ANALYZER_APP_NAME: $(ANALYZER_DEV_APP_NAME)
ANONYMIZER_APP_NAME: $(ANONYMIZER_DEV_APP_NAME)
IMAGE_REDACTOR_APP_NAME: $(IMAGE_REDACTOR_DEV_APP_NAME)
RESOURCE_GROUP_NAME: $(DEV_RESOURCE_GROUP_NAME)
TAG: $(Build.BuildId)
Loading

0 comments on commit 34e371a

Please sign in to comment.