generated from pagopa/io-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-pipelines.yml
165 lines (151 loc) · 5.49 KB
/
deploy-pipelines.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
# Azure DevOps pipeline to release a new version and deploy to production.
variables:
HEALTHCHECK_PATH: '/api/v1/info'
parameters:
- name: 'RELEASE_SEMVER'
displayName: 'When packing a release, define the version bump to apply'
type: string
values:
- major
- minor
- patch
default: minor
# Only manual activations are intended
trigger: none
pr: none
# This pipeline has been implemented to be run on hosted agent pools based both
# on 'windows' and 'ubuntu' virtual machine images and using the scripts defined
# in the package.json file. Since we are deploying on Azure functions on Windows
# runtime, the pipeline is currently configured to use a Windows hosted image for
# the build and deploy.
pool:
vmImage: 'windows-2019'
resources:
repositories:
- repository: pagopaCommons
type: github
name: pagopa/azure-pipeline-templates
ref: refs/tags/v18
endpoint: 'io-azure-devops-github-ro'
stages:
# Create a relase
# Activated when ONE OF these are met:
# - is on branch master
# - is a tag in the form v{version}-RELEASE
- stage: Release
condition:
and(
succeeded(),
or(
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
and(
startsWith(variables['Build.SourceBranch'], 'refs/tags'),
endsWith(variables['Build.SourceBranch'], '-RELEASE')
)
)
)
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: make_release
steps:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
- template: templates/node-job-setup/template.yaml@pagopaCommons
parameters:
persistCredentials: true
- template: templates/node-github-release/template.yaml@pagopaCommons
parameters:
semver: '${{ parameters.RELEASE_SEMVER }}'
gitEmail: $(GIT_EMAIL)
gitUsername: $(GIT_USERNAME)
gitHubConnection: $(GITHUB_CONNECTION)
- ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/master') }}:
- script: |
echo "We assume this reference to be a valid release: $(Build.SourceBranch). Therefore, there is no need to bundle a new release."
displayName: 'Skip release bundle'
# Prepare Artifact
- stage: Deploy_staging
dependsOn:
- Release
jobs:
- job: 'prepare_artifact_and_deploy'
steps:
# Build application
- template: templates/node-job-setup/template.yaml@pagopaCommons
parameters:
# On the assumption that this stage is executed only when Relase stage is,
# with this parameter we set the reference the deploy script must pull changes from.
# The branch/tag name is calculated from the source branch
# ex: Build.SourceBranch=refs/heads/master --> master
# ex: Build.SourceBranch=refs/tags/v1.2.3-RELEASE --> v1.2.3-RELEASE
gitReference: ${{ replace(replace(variables['Build.SourceBranch'], 'refs/tags/', ''), 'refs/heads/', '') }}
- script: |
yarn predeploy
displayName: 'Build'
# Install functions extensions
- task: DotNetCoreCLI@2
inputs:
command: "build"
arguments: "-o bin"
# Copy application to
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
Contents: |
**/*
!.git/**/*
!**/*.js.map
!**/*.ts
!.vscode/**/*
!azure-templates/**/*
!azure-pipelines.yml
!.prettierrc
!.gitignore
!README.md
!jest.config.js
!local.settings.json
!test
!tsconfig.json
displayName: 'Copy deploy files'
- task: AzureFunctionApp@1
inputs:
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)'
resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)'
appType: 'functionApp'
appName: '$(PRODUCTION_APP_NAME)'
package: '$(Build.ArtifactStagingDirectory)/'
deploymentMethod: 'auto'
deployToSlotOrASE: true
slotName: 'staging'
displayName: Deploy to staging slot
# Check that the staging instance is healthy
- stage: Healthcheck
pool:
name: $(AGENT_POOL)
dependsOn:
- Deploy_staging
jobs:
- job: 'do_healthcheck'
steps:
- checkout: none
- script: |
# fails if response status is not 2xx
curl -f 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/$(HEALTHCHECK_PATH)'
displayName: 'Healthcheck'
# Promote the staging instance to production
- stage: Deploy_production
dependsOn:
- Healthcheck
- Deploy_staging
jobs:
- job: 'do_deploy'
steps:
- task: AzureAppServiceManage@0
inputs:
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)'
resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)'
webAppName: '$(PRODUCTION_APP_NAME)'
sourceSlot: staging
swapWithProduction: true
displayName: Swap with production slot