-
Notifications
You must be signed in to change notification settings - Fork 220
/
build-images.yml
282 lines (261 loc) · 12.4 KB
/
build-images.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
# The following variables need to be set in Azure Devops:
# Assets drive
# - (optional) assets.azure.fileshare.password
# - (optional) assets.shared.folder.server
# - assets.useDrive
# Image build options
# - build.includeExperimentalImages
# - build.includeJss
# - build.includeSh
# - build.includeSpe
# - build.includeSxa
# - build.includeShortTags
# - build.includeModuleAssets
# - build.linuxImages
# - build.pruneImages
# - build.sitecoreTopology
# - build.sitecoreVersion
# - build.skipExistingImages
# Container registry
# - container.registry.fullname
# - container.registry.password
# - container.registry.username
# Linux
# - (optional) linux.install.source.path
# Sitecore credentials
# - sitecore.password
# - sitecore.username
# Windows:
# - windows.install.source.path
trigger:
batch: true
branches:
include:
- master
stages:
- stage: Build_Windows_Images
jobs:
- job: Build_Images
strategy:
matrix:
windows20H2:
poolName: "docker-20H2-agents"
osVersion: "20H2"
windows2004:
poolName: "docker-2004-agents"
osVersion: "2004"
ltsc2019:
poolName: "docker-ltsc2019-agents"
osVersion: "ltsc2019"
timeoutInMinutes: 720
displayName: "Build Windows Images"
pool:
name: $(poolName)
steps:
- checkout: self
clean: true
- powershell: |
Test-NetConnection -ComputerName "$(assets.shared.folder.server)" -Port 445
Invoke-Expression -Command "cmdkey /add:$(assets.shared.folder.server) /user:Azure\dockerassets /pass:$(assets.azure.fileshare.password)"
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\$(assets.shared.folder.server)\docker-assets" -Persist -ErrorAction SilentlyContinue
condition: eq(variables['assets.useDrive'], 'true')
displayName: "Connect Asset Drive (optional)"
- powershell: |
$sitecoreRegistry = "$(sitecore.container.registry)"
$sitecoreVersion = "$(build.sitecoreVersion)"
if ("$(Build.SourceBranch)" -match "upgrade/(?<version>\d+\.\d+\.\d+)") {
$sitecoreVersion = $matches.version
$sitecoreRegistry = "$(sitecore.internal.container.registry)"
}
az login -u "$(sitecore.container.registry.username)" -p "$(sitecore.container.registry.password)" -t "$(sitecore.container.registry.tenant)"
if ($sitecoreRegistry -ne "scr.sitecore.com"){
az acr login -n "$sitecoreRegistry"
}
az acr login -n "$(container.registry.fullname)"
$topology = "$(build.sitecoreTopology)" -split ","
$buildProps = @{
InstallSourcePath = "$(windows.install.source.path)"
Registry = "$(container.registry.fullname)"
RegistryUserName = "$(container.registry.username)"
RegistryPassword = "$(container.registry.password)"
SitecoreRegistry = "$sitecoreRegistry"
SitecoreVersion = "$sitecoreVersion"
Topology = $topology
OSVersion = "$(osVersion)"
IncludeSpe = [System.Convert]::ToBoolean($(build.includeSpe))
IncludeSxa = [System.Convert]::ToBoolean($(build.includeSxa))
IncludeJss = [System.Convert]::ToBoolean($(build.includeJss))
IncludeSh = [System.Convert]::ToBoolean($(build.includeSh))
IncludeModuleAssets = $true
IncludeExperimental = [System.Convert]::ToBoolean($(build.includeExperimentalImages))
SkipExistingImage = [System.Convert]::ToBoolean($(build.skipExistingImages))
IncludeShortTags = [System.Convert]::ToBoolean($(build.includeShortTags))
}
.\Build.ps1 @buildProps
displayName: "Build Images"
- powershell: |
docker image prune --force
condition: and(succeeded(), eq(variables['build.pruneImages'], 'true'))
displayName: "Prune images (optional)"
- stage: Build_Linux_Images
dependsOn: []
jobs:
- job: Publish_Asset_Images
displayName: "Download and Extract Asset Images"
pool:
name: "docker-20H2-agents"
steps:
- powershell: |
$sitecoreRegistry = "$(sitecore.container.registry)"
$sitecoreVersion = "$(build.sitecoreVersion)"
if ("$(Build.SourceBranch)" -match "upgrade/(?<version>\d+\.\d+\.\d+)") {
$sitecoreVersion = $matches.version
$sitecoreRegistry = "$(sitecore.internal.container.registry)"
}
az login -u "$(sitecore.container.registry.username)" -p "$(sitecore.container.registry.password)" -t "$(sitecore.container.registry.tenant)"
if ($sitecoreRegistry -ne "scr.sitecore.com"){
az acr login -n "$sitecoreRegistry"
}
az acr login -n "$(container.registry.fullname)"
$buildProps = @{
InstallSourcePath = "$(Build.SourcesDirectory)"
SitecoreVersion = "$sitecoreVersion"
OSVersion = "linux"
IncludeSpe = [System.Convert]::ToBoolean($(build.includeSpe))
IncludeSxa = [System.Convert]::ToBoolean($(build.includeSxa))
IncludeJss = [System.Convert]::ToBoolean($(build.includeJss))
IncludeSh = [System.Convert]::ToBoolean($(build.includeSh))
IncludeExperimental = [System.Convert]::ToBoolean($(build.includeExperimentalImages))
IncludeModuleAssets = $true
SitecoreRegistry = "$sitecoreRegistry"
PublishModuleAssetsOnly = $true
LinuxBuildAssetPath = "$(Build.ArtifactStagingDirectory)"
}
.\Build.ps1 @buildProps
displayName: "Download Windows Assets"
- publish: $(Build.ArtifactStagingDirectory)
displayName: "Publish Artifacts"
artifact: "assets"
- job: Build_Linux_Images
dependsOn: [Publish_Asset_Images]
timeoutInMinutes: 720
displayName: "Build Linux Images"
condition: and(eq(variables['build.linuxImages'], 'true'), succeeded('Publish_Asset_Images'))
pool:
name: "docker-linux-agents"
steps:
- checkout: self
clean: true
- task: DownloadPipelineArtifact@2
inputs:
path: "$(Build.SourcesDirectory)"
- task: Bash@3
displayName: "Move assets to build folder"
inputs:
targetType: 'inline'
script: |
sudo rsync -a $(Build.SourcesDirectory)/assets/* $(Build.SourcesDirectory)/build/linux/
- task: Bash@3
displayName: "Connect to asset drive"
condition: eq(variables['assets.useDrive'], 'true')
inputs:
targetType: inline
script: |
if [ -d "$(linux.install.source.path)" ]; then
exit 0
fi
sudo mkdir $(linux.install.source.path)
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir /etc/smbcredentials
fi
if [ ! -f "/etc/smbcredentials/dockerassets.cred" ]; then
sudo bash -c 'echo "username=dockerassets" >> /etc/smbcredentials/dockerassets.cred'
sudo bash -c 'echo "password=$(assets.azure.fileshare.password)" >> /etc/smbcredentials/dockerassets.cred'
fi
sudo chmod 600 /etc/smbcredentials/dockerassets.cred
sudo bash -c 'echo "//$(assets.shared.folder.server)/docker-assets $(linux.install.source.path) cifs nofail,vers=3.0,credentials=/etc/smbcredentials/dockerassets.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
sudo mount -t cifs //$(assets.shared.folder.server)/docker-assets $(linux.install.source.path) -o vers=3.0,credentials=/etc/smbcredentials/dockerassets.cred,dir_mode=0777,file_mode=0777,serverino
- powershell: |
sudo chmod 777 /mnt/dockerassets -R
$sitecoreRegistry = "$(sitecore.container.registry)"
$sitecoreVersion = "$(build.sitecoreVersion)"
if ("$(Build.SourceBranch)" -match "upgrade/(?<version>\d+\.\d+\.\d+)") {
$sitecoreVersion = $matches.version
$sitecoreRegistry = "$(sitecore.internal.container.registry)"
}
az login -u "$(sitecore.container.registry.username)" -p "$(sitecore.container.registry.password)" -t "$(sitecore.container.registry.tenant)"
if ($sitecoreRegistry -ne "scr.sitecore.com"){
az acr login -n "$sitecoreRegistry"
}
az acr login -n "$(container.registry.fullname)"
$topology = "$(build.sitecoreTopology)" -split ","
$buildProps = @{
InstallSourcePath = "$(linux.install.source.path)"
Registry = "$(container.registry.fullname)"
RegistryUserName = "$(container.registry.username)"
RegistryPassword = "$(container.registry.password)"
SitecoreVersion = "$sitecoreVersion"
Topology = $topology
OSVersion = "linux"
IncludeSpe = [System.Convert]::ToBoolean($(build.includeSpe))
IncludeSxa = [System.Convert]::ToBoolean($(build.includeSxa))
IncludeJss = [System.Convert]::ToBoolean($(build.includeJss))
IncludeSh = [System.Convert]::ToBoolean($(build.includeSh))
IncludeExperimental = [System.Convert]::ToBoolean($(build.includeExperimentalImages))
IncludeModuleAssets = $true
SkipExistingImage = [System.Convert]::ToBoolean($(build.skipExistingImages))
SitecoreRegistry = "$(sitecore.container.registry)"
IncludeShortTags = [System.Convert]::ToBoolean($(build.includeShortTags))
}
.\Build.ps1 @buildProps
displayName: "Build Linux Images"
- powershell: |
docker image prune --force
condition: and(succeeded(), eq(variables['build.pruneImages'], 'true'))
- stage: Trigger_Harbor_Push
dependsOn:
- Build_Windows_Images
- Build_Linux_Images
condition: and(succeeded('Build_Windows_Images'), succeeded('Build_Linux_Images'),eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- job: Harbor_Push
displayName: "Harbor Push"
steps:
- task: TriggerBuild@3
displayName: "Trigger Community Modules"
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: "103"
queueBuildForUserThatTriggeredBuild: true
ignoreSslCertificateErrors: false
useSameSourceVersion: false
useCustomSourceVersion: false
useSameBranch: false
branchToUse: "main"
waitForQueuedBuildsToFinish: false
storeInEnvironmentVariable: false
buildParameters: 'namespace: community, groupName: communityModules, tag:""'
authenticationMethod: "Personal Access Token"
password: "$(System.AccessToken)"
enableBuildInQueueCondition: false
dependentOnSuccessfulBuildCondition: false
dependentOnFailedBuildCondition: false
checkbuildsoncurrentbranch: false
failTaskIfConditionsAreNotFulfilled: false
- task: TriggerBuild@3
displayName: "Trigger Community Images"
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: "103"
queueBuildForUserThatTriggeredBuild: true
ignoreSslCertificateErrors: false
useSameSourceVersion: false
useCustomSourceVersion: false
useSameBranch: false
branchToUse: "main"
waitForQueuedBuildsToFinish: false
storeInEnvironmentVariable: false
buildParameters: 'namespace: community, groupName: community, tag:""'
authenticationMethod: "Personal Access Token"
password: "$(System.AccessToken)"
enableBuildInQueueCondition: false