-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-bff-pipeline.yml
295 lines (259 loc) · 11.2 KB
/
template-bff-pipeline.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: templateBFF-pipeline-$(Date:yyyyMMdd)$(Rev:.r)
trigger:
branches:
include:
- main
paths:
include:
- Services/Client/*
variables:
- template: vars/vars-global.yml
pool:
vmImage: ubuntu-latest
stages:
- stage: build
displayName: Build
jobs:
- job: build
displayName: Build and Test
steps:
- task: UseDotNet@2
displayName: "Use .NET Core sdk"
inputs:
packageType: "sdk"
version: "6.0.x"
- task: ArtifactoryDotnetCore@1
displayName: Artifactory - Restore
inputs:
command: restore
arguments: /p:Configuration="Release"
artifactoryService: ArtifactoryCloud
targetResolveRepo: $(NugetFeed)
rootPath: $(ToolsRoot)/Bff.sln
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: $(ToolsRoot)/**/*.sln
arguments: --configuration "Release" --no-restore
- task: DotNetCoreCLI@2
displayName: Publish bffTemplate
inputs:
command: publish
projects: $(ToolsRoot)/**/*.sln
publishWebProjects: false
arguments: --configuration Release --output $(Build.ArtifactStagingDirectory)/bffTemplate --no-build --no-restore
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: Emit bffTemplate artifact
inputs:
ArtifactName: bffTemplate
PathtoPublish: $(Build.ArtifactStagingDirectory)/bffTemplate
- ${{ if eq(variables.IsPR, true) }}:
- stage: plan_dev
displayName: Plan Dev
dependsOn: []
variables:
- template: vars/vars-dev.yml
jobs:
- job: tf_plan
displayName: Terraform plan
pool:
vmImage: ubuntu-latest
steps:
- template: /pipelines/terraform-plan.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
ComponentName: BFF Template
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformVersion: ${{ variables.TerraformVersion }}
TerraformRoot: ${{ variables.TerraformRoot }}
- task: CopyFiles@1
displayName: Copy Files to publish
inputs:
TargetFolder: $(build.artifactstagingdirectory)
SourceFolder: ${{ variables.TerraformRoot }}
Contents: |
**/*.tf
**/*.tpl
environments/${{ variables.Environment }}/**/*
tfplan
- task: PublishPipelineArtifact@1
displayName: Publish pipeline artifact
inputs:
targetPath: $(build.artifactstagingdirectory)
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(System.StageAttempt)
- bash: |
echo "##vso[task.setvariable variable=ArtifactIndex;isOutput=true;]$(System.StageAttempt)"
name: ArtifactMemento
- stage: deploy_dev
displayName: Deploy Dev
dependsOn: [build, plan_dev]
variables:
- template: /vars/vars-dev.yml
- name: ArtifactIndex
value: $[ stageDependencies.plan_dev.tf_plan.outputs['ArtifactMemento.ArtifactIndex'] ]
jobs:
- job: before_deploy_${{ variables.Environment }}
displayName: Approve before Apply
pool: server
steps:
- task: ManualValidation@0
timeoutInMinutes: 4320 # 3 days
inputs:
notifyUsers: ""
instructions: "Do you really want to deploy on the ${{ variables.Environment }} environment ?"
onTimeout: reject
- job: tf_apply
displayName: Terraform apply
dependsOn:
- before_deploy_${{ variables.Environment }}
condition: eq(dependencies.before_deploy_${{ variables.Environment }}.result, 'Succeeded')
steps:
- checkout: none
- download: current
displayName: Download terraform artifact
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
- template: /templates/terraform-apply.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformRoot: $(Pipeline.Workspace)/apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
TerraformVersion: ${{ variables.TerraformVersion }}
PlanFilename: tfplan
- job: get_tf_outputs
displayName: Get terraform outputs
dependsOn: tf_apply
steps:
- checkout: none
- download: current
displayName: Download terraform artifact
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
- template: /templates/terraform-output.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformRoot: $(Pipeline.Workspace)/apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
TerraformVersion: ${{ variables.TerraformVersion }}
- job: deploy
displayName: Deploy Template BFF
dependsOn: get_tf_outputs
condition: eq(dependencies.get_tf_outputs.result, 'Succeeded')
variables:
appServiceAppName: $[ dependencies.get_tf_outputs.outputs['tf_output.app_1_name'] ]
steps:
- checkout: none
- download: current
displayName: Download Template BFF artifact
artifact: helperClient
- task: AzureWebApp@1
displayName: Deploy Template BFF
inputs:
azureSubscription: ${{ variables.AzureConnection }}
appType: webApp
appName: $(appServiceAppName)
package: $(Pipeline.Workspace)/bffTemplate/*.zip
- ${{ if eq(variables.IsPR, false) }}:
- stage: plan_inte
displayName: Plan Inte
dependsOn: []
variables:
- template: vars/vars-inte.yml
jobs:
- job: tf_plan
displayName: Terraform plan
pool:
vmImage: ubuntu-latest
steps:
- template: /templates/terraform-plan.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
ComponentName: Template BFF
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformVersion: ${{ variables.TerraformVersion }}
TerraformRoot: ${{ variables.TerraformRoot }}
- task: CopyFiles@1
displayName: Copy Files to publish
inputs:
TargetFolder: $(build.artifactstagingdirectory)
SourceFolder: ${{ variables.TerraformRoot }}
Contents: |
**/*.tf
**/*.tpl
environments/${{ variables.Environment }}/**/*
tfplan
- task: PublishPipelineArtifact@1
displayName: Publish pipeline artifact
inputs:
targetPath: $(build.artifactstagingdirectory)
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(System.StageAttempt)
- bash: |
echo "##vso[task.setvariable variable=ArtifactIndex;isOutput=true;]$(System.StageAttempt)"
name: ArtifactMemento
- stage: deploy_inte
displayName: Deploy Inte
dependsOn: [build, plan_inte]
variables:
- template: /pipelines/vars/vars-inte.yml
- name: ArtifactIndex
value: $[ stageDependencies.plan_inte.tf_plan.outputs['ArtifactMemento.ArtifactIndex'] ]
jobs:
- job: before_deploy_${{ variables.Environment }}
displayName: Approve before Apply
pool: server
steps:
- task: ManualValidation@0
timeoutInMinutes: 4320 # 3 days
inputs:
notifyUsers: ""
instructions: "Do you really want to deploy on the ${{ variables.Environment }} environment ?"
onTimeout: reject
- job: tf_apply
displayName: Terraform apply
dependsOn:
- before_deploy_${{ variables.Environment }}
condition: eq(dependencies.before_deploy_${{ variables.Environment }}.result, 'Succeeded')
steps:
- checkout: none
- download: current
displayName: Download terraform artifact
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
- template: /templates/terraform-apply.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformRoot: $(Pipeline.Workspace)/apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
TerraformVersion: ${{ variables.TerraformVersion }}
PlanFilename: tfplan
- job: get_tf_outputs
displayName: Get terraform outputs
dependsOn: tf_apply
steps:
- checkout: none
- download: current
displayName: Download terraform artifact
artifact: apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
- template: /templates/terraform-output.yml
parameters:
EnvironmentName: ${{ variables.Environment }}
AzureConnectionName: ${{ variables.AzureConnection }}
TerraformRoot: $(Pipeline.Workspace)/apply_actifact_${{ variables.Environment }}_attempt_$(ArtifactIndex)
TerraformVersion: ${{ variables.TerraformVersion }}
- job: deploy
displayName: Deploy Template BFF
dependsOn: get_tf_outputs
condition: eq(dependencies.get_tf_outputs.result, 'Succeeded')
variables:
appServiceAppName: $[ dependencies.get_tf_outputs.outputs['tf_output.app_1_name'] ]
steps:
- checkout: none
- download: current
displayName: Download Template BFF artifact
artifact: templateBFF
- task: AzureWebApp@1
displayName: Deploy Template BFF
inputs:
azureSubscription: ${{ variables.AzureConnection }}
appType: webApp
appName: $(appServiceAppName)
package: $(Pipeline.Workspace)/templateBFF/*.zip