Skip to content

Commit

Permalink
[#175126219] Healthcheck step in pipeline (#117)
Browse files Browse the repository at this point in the history
* [#175126219] add healthcheck step

* [#175126219] default deploy

* Update azure-pipelines.yml

* Update azure-pipelines.yml

Co-authored-by: Danilo Spinelli <gunzip@users.noreply.github.com>
  • Loading branch information
balanza and gunzip authored Nov 27, 2020
1 parent 8ac541f commit 30eafc9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
18 changes: 17 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ parameters:
- name: 'PRODUCTION_DEPLOY_TYPE'
displayName: 'Method to achieve deployment in Production (if enabled):'
type: string
default: deployToStagingSlot
default: deployToStagingSlotAndSwap
values:
- deployToStagingSlot
- deployToProductionSlot
Expand All @@ -90,6 +90,14 @@ trigger:
pool:
vmImage: 'windows-2019'

resources:
repositories:
- repository: pagopaCommons
type: github
name: pagopa/azure-pipeline-templates
ref: refs/tags/v1
endpoint: 'pagopa'

stages:
# A) Build and code validation
- stage: Build
Expand Down Expand Up @@ -200,6 +208,10 @@ stages:
azureSubscription: '$(TEST_AZURE_SUBSCRIPTION)'
resourceGroupName: '$(TEST_RESOURCE_GROUP_NAME)'
appName: '$(TEST_APP_NAME)'
healthcheckEndpoint: 'https://$(TEST_APP_NAME)-staging.azurewebsites.net/api/v1/info'
containerInstanceResourceGroup: 'io-p-rg-common'
containerInstanceVNet: 'io-p-vnet-common'
containerInstanceSubnet: 'azure-devops'


# D) Deploy to PRODUCTION environment if one of the following conditions apply:
Expand Down Expand Up @@ -233,3 +245,7 @@ stages:
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)'
resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)'
appName: '$(PRODUCTION_APP_NAME)'
healthcheckEndpoint: 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/api/v1/info'
containerInstanceResourceGroup: 'io-p-rg-common'
containerInstanceVNet: 'io-p-vnet-common'
containerInstanceSubnet: 'azure-devops'
34 changes: 31 additions & 3 deletions azure-templates/deploy-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ parameters:
- name: 'appName'
type: string
default: ''

# full endpoint to perform healthcheck against,
- name: 'healthcheckEndpoint'
type: string

# the resource group must be the same where vnet is created
- name: 'containerInstanceResourceGroup'
type: string

# attached vnet to the container instance
- name: 'containerInstanceVNet'
type: string

# container instance subnet
- name: 'containerInstanceSubnet'
type: string

steps:
- template: ./make-build-steps.yml
Expand Down Expand Up @@ -87,7 +103,8 @@ steps:

# Option 3: deployment with two slots ('staging' and 'production')
- ${{ if eq(parameters.deployType, 'deployToStagingSlotAndSwap') }}:
- task: AzureFunctionApp@1 # First step: deploy to 'staging' slot
# First step: deploy to 'staging' slot
- task: AzureFunctionApp@1
inputs:
azureSubscription: '${{ parameters.azureSubscription }}'
resourceGroupName: '${{ parameters.resourceGroupName }}'
Expand All @@ -98,8 +115,19 @@ steps:
deployToSlotOrASE: true
slotName: 'staging'
displayName: Deploy to staging slot

- task: AzureAppServiceManage@0 # Second step: swap 'staging' with 'production' slot

# Second step: check the app is working
- template: templates/rest-healthcheck/template.yaml@pagopaCommons
parameters:
azureSubscription: '${{ parameters.azureSubscription }}'
appName: '${{ parameters.appName }}'
endpoint: '${{ parameters.healthcheckEndpoint }}'
containerInstanceResourceGroup: '${{ parameters.containerInstanceResourceGroup }}'
containerInstanceVNet: '${{ parameters.containerInstanceVNet }}'
containerInstanceSubnet: '${{ parameters.containerInstanceSubnet }}'

# Third step: swap 'staging' with 'production' slot
- task: AzureAppServiceManage@0
inputs:
azureSubscription: '${{ parameters.azureSubscription }}'
resourceGroupName: '${{ parameters.resourceGroupName }}'
Expand Down

0 comments on commit 30eafc9

Please sign in to comment.