This repository was archived by the owner on Jan 15, 2025. It is now read-only.
generated from pagopa/io-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-pipelines.yml
190 lines (176 loc) · 6.51 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# Azure DevOps pipeline to release a new version and deploy to production.
parameters:
- name: 'RELEASE_SEMVER'
displayName: 'When packing a release, define the version bump to apply'
type: string
values:
- major
- minor
- patch
default: minor
- name: environment
displayName: Target Environment
type: string
default: uat
values:
- uat
- prod
# Only manual activations are intended
trigger: none
pr: none
# variables setted on azdevops to avoid circular dependency warning
# $(DEFAULT_BRANCH)
# $(HEALTHCHECK_CONTAINER_SUBNET)
variables:
${{ if eq(parameters['environment'], 'uat') }}:
DEPLOY_TYPE: $[variables['UAT_DEPLOY_TYPE']]
MAKE_RELEASE: true
AZURE_SUBSCRIPTION: $(UAT_AZURE_SUBSCRIPTION)
WEB_APP_NAME: $(UAT_WEB_APP_NAME)
WEB_APP_RESOURCE_GROUP_NAME: $(UAT_WEB_APP_RESOURCE_GROUP_NAME)
HEALTHCHECK_ENDPOINT: $(UAT_HEALTHCHECK_ENDPOINT)
HEALTHCHECK_CONTAINER_RESOURCE_GROUP_NAME: $(UAT_HEALTHCHECK_CONTAINER_RESOURCE_GROUP_NAME)
HEALTHCHECK_CONTAINER_VNET: $(UAT_HEALTHCHECK_CONTAINER_VNET)
${{ if eq(parameters['environment'], 'prod') }}:
DEPLOY_TYPE: $[variables['PROD_DEPLOY_TYPE']]
MAKE_RELEASE: false
AZURE_SUBSCRIPTION: $(PROD_AZURE_SUBSCRIPTION)
WEB_APP_NAME: $(PROD_WEB_APP_NAME)
WEB_APP_RESOURCE_GROUP_NAME: $(PROD_WEB_APP_RESOURCE_GROUP_NAME)
HEALTHCHECK_ENDPOINT: $(PROD_HEALTHCHECK_ENDPOINT)
HEALTHCHECK_CONTAINER_RESOURCE_GROUP_NAME: $(PROD_HEALTHCHECK_CONTAINER_RESOURCE_GROUP_NAME)
HEALTHCHECK_CONTAINER_VNET: $(PROD_HEALTHCHECK_CONTAINER_VNET)
# 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/v19
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
condition:
and(
eq(variables['Build.SourceBranch'], format('refs/heads/{0}', variables.DEFAULT_BRANCH)),
eq(variables.MAKE_RELEASE, true)
)
steps:
- 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)
- job: skip_release
condition: ne(variables['Build.SourceBranch'], format('refs/heads/{0}', variables.DEFAULT_BRANCH))
steps:
- 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: Prepare_artifact
condition:
and(
succeeded(),
or(
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
and(
startsWith(variables['Build.SourceBranch'], 'refs/tags'),
endsWith(variables['Build.SourceBranch'], '-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: '$(System.DefaultWorkingDirectory)/bundle'
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'
- publish: $(System.DefaultWorkingDirectory)/bundle
artifact: Bundle
# Deploy
- stage: 'Deploy_to_${{ parameters.environment }}'
dependsOn:
- Prepare_artifact
jobs:
- job: 'do_deploy_production_slot'
condition: eq(variables.DEPLOY_TYPE, 'production_slot')
steps:
- checkout: none
- download: current
artifact: Bundle
- task: AzureFunctionApp@1
inputs:
azureSubscription: '$(AZURE_SUBSCRIPTION)'
resourceGroupName: '$(WEB_APP_RESOURCE_GROUP_NAME)'
appType: 'functionApp'
appName: '$(WEB_APP_NAME)'
package: '$(Pipeline.Workspace)/Bundle'
deploymentMethod: 'auto'
deployToSlotOrASE: true
slotName: 'production'
displayName: 'Deploy to production slot'