This repository has been archived by the owner on Dec 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
azure-pipelines.yml
350 lines (339 loc) · 13.6 KB
/
azure-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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
branches:
include:
- main
resources:
- repo: self
clean: true
stages:
- stage: Build
displayName: Build Images + Push to ACR
jobs:
- job: Build
displayName: Build
pool: $(AGENT_POOL_NAME)
steps:
- task: CmdLine@2
displayName: Create .env file
inputs:
script: ren .env.template .env
- task: DockerCompose@0
displayName: "Build Images"
inputs:
containerregistrytype: 'Container Registry'
dockerRegistryEndpoint: 'MVPSiteV2'
dockerComposeFile: '**/docker-compose.yml'
additionalDockerComposeFiles: 'docker-compose.override.yml'
dockerComposeFileArgs: '$(DOCKER_COMPOSE_ARGS)'
qualifyImageNames: false
action: 'Build services'
additionalImageTags: '$(Build.BuildNumber)-$(Build.SourceBranchName)'
includeLatestTag: true
- task: DockerCompose@0
displayName: "Push Images with Latest Tag"
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: '$(AZURE_SUBSCRIPTION)'
azureContainerRegistry: '$(AZURE_CONTAINER_REGISTRY)'
dockerComposeFile: '**/docker-compose.yml'
additionalDockerComposeFiles: 'docker-compose.override.yml'
dockerComposeFileArgs: '$(DOCKER_COMPOSE_ARGS)'
action: 'Push services'
additionalImageTags: '$(Build.BuildNumber)-$(Build.SourceBranchName)'
includeLatestTag: true
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
- task: CopyFiles@2
displayName: "Copy K8s specifications to staging directory"
inputs:
SourceFolder: 'k8s/specs'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)/k8s-specs'
CleanTargetFolder: true
- task: CopyFiles@2
displayName: "Copy Serialisation assets to staging directory"
inputs:
SourceFolder: './'
Contents: |
sitecore.json
src/**/*.module.json
src/**/items/**
.config/dotnet-tools.json
TargetFolder: '$(Build.ArtifactStagingDirectory)/serialization'
CleanTargetFolder: true
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(System.ArtifactsDirectory)'
artifact: 'Sitecore.MVP-$(Build.BuildNumber)'
- stage: Staging
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
dependsOn: Build
displayName: Deploy to Staging
jobs:
- deployment: 'Deploy_Specs_to_Staging_AKS'
pool: $(AGENT_POOL_NAME)
environment: Staging
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
displayName: "Download Build Artifact"
inputs:
artifact: Sitecore.MVP-$(Build.BuildNumber)
targetPath: '$(System.ArtifactsDirectory)'
- task: Kubernetes@1
displayName: Create MVP-Staging Namespace
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: '$(AKS_SERVICE_ENDPOINT)'
command: 'apply'
useConfigurationFile: true
configuration: '$(System.ArtifactsDirectory)/k8s-specs/staging/namespaces/namespace-staging.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
versionSpec: '1.22.2'
outputFormat: ''
- task: replacetokens@3
displayName: "Replace Tokens in Secrets & Specs"
inputs:
rootDirectory: '$(System.ArtifactsDirectory)/k8s-specs/staging'
targetFiles: |
**/*.txt
**/*.crt
**/*.key
**/*.yaml
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: true
tokenPrefix: '$('
tokenSuffix: ')'
useLegacyPattern: false
enableTelemetry: false
- task: KubernetesManifest@0
displayName: Bake Secrets
name: 'bake_secrets'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/staging/secrets/'
- task: KubernetesManifest@0
displayName: Deploy Secrets
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-staging'
manifests: '$(bake_secrets.manifestsBundle)'
- task: KubernetesManifest@0
displayName: Bake Ingress Specifications
name: 'bake_ingress'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/staging/ingress-nginx/'
- task: KubernetesManifest@0
displayName: Deploy Ingress Specifications
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-staging'
manifests: '$(bake_ingress.manifestsBundle)'
- task: KubernetesManifest@0
displayName: Bake External Specifications
name: 'bake_external'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/staging/external/'
- task: KubernetesManifest@0
displayName: Deploy External Specifications
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-staging'
manifests: '$(bake_external.manifestsBundle)'
# - task: KubernetesManifest@0
# displayName: Bake Init Specifications
# name: 'bake_init'
# inputs:
# action: 'bake'
# renderType: 'kustomize'
# kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/staging/init/'
# - task: KubernetesManifest@0
# displayName: Deploy Init Specifications
# inputs:
# action: 'deploy'
# kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
# namespace: 'mvp-staging'
# manifests: '$(bake_init.manifestsBundle)'
- task: KubernetesManifest@0
displayName: Bake Application Specifications
name: 'bake_application'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/staging'
- task: KubernetesManifest@0
displayName: Deploy Application Specifications
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-staging'
manifests: '$(bake_application.manifestsBundle)'
rolloutStatusTimeout: '1200'
- deployment: 'Deserialize_Content_to_Staging'
dependsOn: 'Deploy_Specs_to_Staging_AKS'
pool: $(AGENT_POOL_NAME)
environment: Staging
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
displayName: "Download Build Artifact"
inputs:
artifact: Sitecore.MVP-$(Build.BuildNumber)
targetPath: '$(System.ArtifactsDirectory)'
- task: PowerShell@2
displayName: Deserialize Content
inputs:
targetType: 'inline'
script: |
# Add nuget source & install Sitecore CLI
Write-Host "Installing Sitecore CLI"
dotnet nuget add source $(SITECORE_PUBLIC_NUGET_FEED) --name "Sitecore-Public-Nuget-Feed"
dotnet tool restore
# Login to ID Server
Write-Host "Logging into ID Server"
dotnet sitecore login --client-credentials true --auth $(STAGING_ID_SERVER_URL) --cm $(STAGING_CLI_URL) --allow-write true --client-id "MVP_Automation" --client-secret "$(STAGING_IDENTITY_SECRET_MVP)"
# Deserialize Content
Write-Host "Push Content"
dotnet sitecore ser push
# Publish Database
Write-Host "Publish Database"
dotnet sitecore publish
workingDirectory: '$(System.ArtifactsDirectory)/serialization'
- stage: Production
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
dependsOn: Staging
displayName: Deploy to Production
jobs:
- deployment: 'Deploy_Specs_to_Production_AKS'
pool: $(AGENT_POOL_NAME)
environment: Production
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
displayName: "Download Build Artifact"
inputs:
artifact: Sitecore.MVP-$(Build.BuildNumber)
targetPath: '$(System.ArtifactsDirectory)'
- task: Kubernetes@1
displayName: Create MVP-Production Namespace
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: '$(AKS_SERVICE_ENDPOINT)'
command: 'apply'
useConfigurationFile: true
configuration: '$(System.ArtifactsDirectory)/k8s-specs/prod/namespaces/namespace-prod.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
versionSpec: '1.22.2'
outputFormat: ''
- task: replacetokens@3
displayName: "Replace Tokens in Secrets & Specs"
inputs:
rootDirectory: '$(System.ArtifactsDirectory)/k8s-specs/prod'
targetFiles: |
**/*.txt
**/*.crt
**/*.key
**/*.yaml
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: true
tokenPrefix: '$('
tokenSuffix: ')'
useLegacyPattern: false
enableTelemetry: false
- task: KubernetesManifest@0
displayName: Bake Secrets
name: 'bake_secrets'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/prod/secrets/'
- task: KubernetesManifest@0
displayName: Deploy Secrets
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-prod'
manifests: '$(bake_secrets.manifestsBundle)'
- task: KubernetesManifest@0
displayName: Bake Ingress Specifications
name: 'bake_ingress'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/prod/ingress-nginx/'
- task: KubernetesManifest@0
displayName: Deploy Ingress Specifications
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-prod'
manifests: '$(bake_ingress.manifestsBundle)'
- task: KubernetesManifest@0
displayName: Bake Application Specifications
name: 'bake_application'
inputs:
action: 'bake'
renderType: 'kustomize'
kustomizationPath: '$(System.ArtifactsDirectory)/k8s-specs/prod'
- task: KubernetesManifest@0
displayName: Deploy Application Specifications
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(AKS_SERVICE_ENDPOINT)'
namespace: 'mvp-prod'
manifests: '$(bake_application.manifestsBundle)'
rolloutStatusTimeout: '1200'
- deployment: 'Deserialize_Content_to_Production'
dependsOn: 'Deploy_Specs_to_Production_AKS'
pool: $(AGENT_POOL_NAME)
environment: Production
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
displayName: "Download Build Artifact"
inputs:
artifact: Sitecore.MVP-$(Build.BuildNumber)
targetPath: '$(System.ArtifactsDirectory)'
- task: PowerShell@2
displayName: Deserialize Content
inputs:
targetType: 'inline'
script: |
# Add nuget source & install Sitecore CLI
Write-Host "Installing Sitecore CLI"
dotnet nuget add source $(SITECORE_PUBLIC_NUGET_FEED) --name "Sitecore-Public-Nuget-Feed"
dotnet tool restore
# Login to ID Server
Write-Host "Logging into ID Server"
dotnet sitecore login --client-credentials true --auth $(PROD_ID_SERVER_URL) --cm $(PROD_CLI_URL) --allow-write true --client-id "MVP_Automation" --client-secret "$(PROD_IDENTITY_SECRET_MVP)"
# Deserialize Content
Write-Host "Push Content"
dotnet sitecore ser push
# Publish Database
Write-Host "Publish Database"
dotnet sitecore publish
workingDirectory: '$(System.ArtifactsDirectory)/serialization'