-
Notifications
You must be signed in to change notification settings - Fork 74
/
azure-pipelines-product-construction-service.yml
277 lines (244 loc) · 9.62 KB
/
azure-pipelines-product-construction-service.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
trigger:
batch: true
branches:
include:
- main
- production
pr:
branches:
include:
- main
variables:
# https://dev.azure.com/dnceng/internal/_library?itemType=VariableGroups&view=VariableGroupView&variableGroupId=189
# Required for MaestroAppClientId, MaestroStagingAppClientId
- group: Publish-Build-Assets
- name: resourceGroupName
value: product-construction-service
- name: containerName
value: product-construction-service.api
- name: diffFolder
value: $(Build.ArtifactStagingDirectory)/diff
- name: _TeamName
value: DotNetCore
- name: _PublishUsingPipelines
value: true
- name: _DotNetArtifactsCategory
value: .NETCore
- name: _SignType
value: test
- ${{ if not(or(startsWith(variables['Build.SourceBranch'], 'refs/heads/production'), startsWith(variables['Build.SourceBranch'], 'refs/heads/production-'), eq(variables['Build.SourceBranch'], 'refs/heads/production'))) }}:
- name: subscriptionId
value: e6b5f9f5-0ca4-4351-879b-014d78400ec2
- name: containerappName
value: product-construction-int
- name: containerjobNames
value: sub-triggerer-twicedaily-int,sub-triggerer-daily-int,sub-triggerer-weekly-int,longest-path-updater-job-int,feed-cleaner-int
- name: containerRegistryName
value: productconstructionint
- name: containerappEnvironmentName
value: product-construction-service-env-int
- name: containerappWorkspaceName
value: product-construction-service-workspace-int
- name: dockerRegistryUrl
value: productconstructionint.azurecr.io
- name: serviceConnectionName
value: ProductConstructionServiceDeploymentInt
- name: authServiceConnection
value: "Darc: Maestro Staging"
- name: MaestroAppId
value: $(MaestroStagingAppClientId)
- name: redisConnectionString
value: "product-construction-service-redis-int.redis.cache.windows.net:6380,ssl=true"
- ${{ else }}:
- name: subscriptionId
value: fbd6122a-9ad3-42e4-976e-bccb82486856
- name: containerappName
value: product-construction-prod
- name: containerjobNames
value: sub-triggerer-twicedaily-prod,sub-triggerer-daily-prod,sub-triggerer-weekly-prod,longest-path-updater-job-prod,feed-cleaner-prod
- name: containerRegistryName
value: productconstructionprod
- name: containerappEnvironmentName
value: product-construction-service-env-prod
- name: containerappWorkspaceName
value: product-construction-service-workspace-prod
- name: dockerRegistryUrl
value: productconstructionprod.azurecr.io
- name: serviceConnectionName
value: ProductConstructionServiceDeploymentProd
- name: authServiceConnection
value: "Darc: Maestro Production"
- name: MaestroAppId
value: $(MaestroAppClientId)
- name: redisConnectionString
value: "product-construction-service-redis-prod.redis.cache.windows.net,ssl=true"
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
- name: devBranchSuffix
value:
- ${{ else }}:
- name: devBranchSuffix
value: -dev
stages:
- stage: Build
displayName: Build
dependsOn: []
jobs:
- job: BuildAndPublish
displayName: Build and Publish Repo
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals 1es-windows-2019
variables:
- name: BuildConfig
value: Release
steps:
- checkout: self
- powershell: |
. .\eng\common\tools.ps1
InitializeDotNetCli -install:$true
.\.dotnet\dotnet workload update --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json
.\.dotnet\dotnet workload install aspire --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json
displayName: Install .NET and Aspire Workload
- powershell: >
.\eng\common\build.ps1
-restore
-pack
-configuration $(BuildConfig)
-projects .\src\Microsoft.DotNet.Darc\Darc\Microsoft.DotNet.Darc.csproj
displayName: Build Darc
- powershell: >
.\eng\common\build.ps1
-restore
-build
-configuration $(BuildConfig)
-projects .\test\ProductConstructionService.ScenarioTests\ProductConstructionService.ScenarioTests.csproj
displayName: Build ScenarioTests
- powershell: >
.\eng\common\build.ps1
-restore
-build
-configuration $(BuildConfig)
-projects .\src\ProductConstructionService\ProductConstructionService.Cli\ProductConstructionService.Cli.csproj
displayName: Build ProductConstructionService.Cli
- publish: $(Build.SourcesDirectory)\artifacts\bin\ProductConstructionService.ScenarioTests\$(BuildConfig)\net8.0\publish
artifact: ProductConstructionService.ScenarioTests
- publish: $(Build.SourcesDirectory)\artifacts\packages\$(BuildConfig)\NonShipping
artifact: PackageArtifacts
- publish: $(Build.SourcesDirectory)\artifacts\bin\ProductConstructionService.Cli\$(BuildConfig)\net8.0
artifact: ProductConstructionService.Cli
- job: BuildAndPublishDocker
displayName: Build And Publish new Docker Image
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals 1es-ubuntu-2004
steps:
- checkout: self
- template: eng/templates/steps/docker-build.yml
parameters:
devBranchSuffix: $(devBranchSuffix)
dockerImageName: $(dockerRegistryUrl)/$(containerName)
- ${{ if notin(variables['Build.Reason'], 'PullRequest') }}:
- stage: DeployPCS
dependsOn:
- Build
displayName: Deploy Product Construction Service
jobs:
- job: Deploy
displayName: Deploy container app
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals 1es-windows-2019
variables:
newDockerImageTag: $[stageDependencies.Build.BuildAndPublishDocker.outputs['DockerTag.newDockerImageTag']]
steps:
- powershell: |
Write-Host $(containerjobNames)
$az = Get-Command az.cmd
"##vso[task.setvariable variable=azCliPath]$($az.Source)"
- powershell: Write-Host $(azCliPath)
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
New-Item -ItemType Directory -Path $(diffFolder)
$before = az containerapp show --name $(containerappName) -g $(resourceGroupName) --output json
Set-Content -Path $(diffFolder)/before.json -Value $before
displayName: Snapshot configuration (before)
- download: current
displayName: Download ProductConstructionService.Cli
artifact: ProductConstructionService.Cli
- task: NuGetToolInstaller@1
displayName: Use NuGet
inputs:
versionSpec: 5.3.x
- powershell: |
. .\eng\common\tools.ps1
InitializeDotNetCli -install:$true
.\.dotnet\dotnet workload install aspire
displayName: Install .NET and Aspire Workload
# We'll need to give this service connection permission to get an auth token for PCS
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: >
$(Pipeline.Workspace)/ProductConstructionService.Cli/ProductConstructionService.Cli.exe
deploy
--subscriptionId $(subscriptionId)
--resourceGroupName $(resourceGroupName)
--containerRegistryName $(containerRegistryName)
--containerAppName $(containerappName)
--workspaceName $(containerappWorkspaceName)
--containerJobNames $(containerjobNames)
--newImageTag $(newDockerImageTag)
--imageName $(containerName)
--azCliPath "$(azCliPath)"
--redisConnectionString $(redisConnectionString)
displayName: Deploy container app
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$after = az containerapp show --name $(containerappName) -g $(resourceGroupName) --output json
Set-Content -Path $(diffFolder)/after.json -Value $after
displayName: Snapshot configuration (after)
# git diff will set the exit code to 1, since the files are different, we have to manually set it back to 0
- powershell: |
$diff = git diff before.json after.json
$LASTEXITCODE = 0
Set-Content -Path diff -Value $diff
displayName: Diff configuration snapshots
workingDirectory: $(diffFolder)
- publish: $(diffFolder)
displayName: Upload snapshot diff
artifact: DeploymentDiff
- stage: TestPCS
displayName: Run E2E Product Construction Service Tests
dependsOn:
- DeployPCS
jobs:
- template: /eng/templates/jobs/e2e-pcs-tests.yml
parameters:
name: scenarioTests_GitHub
displayName: GitHub tests
testFilter: 'TestCategory=GitHub'
- template: /eng/templates/jobs/e2e-pcs-tests.yml
parameters:
name: scenarioTests_AzDO
displayName: AzDO tests
testFilter: 'TestCategory=AzDO'
- template: /eng/templates/jobs/e2e-pcs-tests.yml
parameters:
name: scenarioTests_Other
displayName: Other tests
testFilter: 'TestCategory!=GitHub&TestCategory!=AzDO&TestCategory!=CodeFlow'
- template: /eng/templates/jobs/e2e-pcs-tests.yml
parameters:
name: scenarioTests_CodeFlow
displayName: Code Flow tests
testFilter: 'TestCategory=CodeFlow'