-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild_stack.groovy
More file actions
282 lines (251 loc) · 8.24 KB
/
build_stack.groovy
File metadata and controls
282 lines (251 loc) · 8.24 KB
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
properties([
copyArtifactPermission('/release/*'),
]);
node('jenkins-manager') {
dir('jenkins-dm-jobs') {
checkout([
$class: 'GitSCM',
branches: scm.getBranches(),
userRemoteConfigs: scm.getUserRemoteConfigs(),
changelog: false,
poll: false
])
notify = load 'pipelines/lib/notify.groovy'
util = load 'pipelines/lib/util.groovy'
scipipe = util.scipipeConfig() // needed for side effects
sqre = util.sqreConfig() // needed for side effects
}
}
notify.wrap {
util.requireParams([
'EUPS_TAG',
'NO_PUSH',
'PRODUCTS',
'TIMEOUT',
])
String eupsTag = params.EUPS_TAG
String products = params.PRODUCTS
Boolean noPush = params.NO_PUSH
Integer timelimit = Integer.parseInt(params.TIMEOUT)
String extraDockerTags = params.DOCKER_TAGS
// optional
String manifestId = params.MANIFEST_ID ?: ''
String lsstCompiler = params.LSST_COMPILER ?: ''
def build_stack = scipipe.build_stack
def lsstswConfigs = build_stack.lsstsw_config
def release = scipipe.scipipe_release
def dockerfile = release.dockerfile
def dockerRegistry = release.docker_registry
def newinstall = scipipe.newinstall
def githubRepo = util.githubSlugToUrl(dockerfile.github_repo)
def gitRef = dockerfile.git_ref
def buildDir = dockerfile.dir
def dockerRepo = dockerRegistry.repo
def dockerTag = "7-stack-lsst_distrib-${eupsTag}"
def ghdockerTag = "al9-${eupsTag}"
def timestamp = util.epochMilliToUtc(currentBuild.startTimeInMillis)
def shebangtronUrl = util.shebangtronUrl()
def dockerdigest = []
// should be removed after dropping support for dockerhub
def ghdockerdigest = []
// should be removed after dropping support for dockerhub
def ghdockerRepo = "ghcr.io/lsst/scipipe"
def registryTags = [
dockerTag,
"${dockerTag}-${timestamp}",
]
// should be removed after dropping support for dockerhub
def ghregistryTags = [
ghdockerTag,
"${ghdockerTag}-${timestamp}",
]
if (extraDockerTags) {
// manual constructor is needed "because java"
registryTags += Arrays.asList(extraDockerTags.split())
// should be removed after dropping support for dockerhub
def extraTagList = Arrays.asList(extraDockerTags.split())
ghregistryTags += extraTagList
extraTagList.each { tag ->
registryTags += "7-stack-lsst_distrib-${tag}"
}
}
def newRegistryTags = []
registryTags.each { name ->
fixOSVersion = name.replaceFirst("7", "9")
fixDistribName = fixOSVersion.replace("stack-lsst_distrib", "lsst_sitcom")
newRegistryTags += fixDistribName
}
def matrix = [:]
lsstswConfigs.each{ lsstswConfig ->
def slug = util.lsstswConfigSlug(lsstswConfig)
matrix[slug] ={
def newinstallImage = newinstall.docker_registry.repo
def newinstallTagBase = newinstall.docker_registry.tag
def splenvRef = lsstswConfig.splenv_ref
if (params.SPLENV_REF) {
splenvRef = params.SPLENV_REF
}
def baseImage = "${newinstallImage}:${newinstallTagBase}-${splenvRef}"
def image = null
def repo = null
def run = {
stage('checkout') {
repo = git([
url: githubRepo,
branch: gitRef,
])
}
stage('build') {
def opt = []
// ensure base image is always up to date
opt << '--pull=true'
opt << '--no-cache'
opt << "--build-arg EUPS_PRODUCTS=\"${products}\""
opt << "--build-arg EUPS_TAG=\"${eupsTag}\""
opt << "--build-arg DOCKERFILE_GIT_BRANCH=\"${repo.GIT_BRANCH}\""
opt << "--build-arg DOCKERFILE_GIT_COMMIT=\"${repo.GIT_COMMIT}\""
opt << "--build-arg DOCKERFILE_GIT_URL=\"${repo.GIT_URL}\""
opt << "--build-arg JENKINS_JOB_NAME=\"${env.JOB_NAME}\""
opt << "--build-arg JENKINS_BUILD_ID=\"${env.BUILD_ID}\""
opt << "--build-arg JENKINS_BUILD_URL=\"${env.RUN_DISPLAY_URL}\""
opt << "--build-arg BASE_IMAGE=\"${baseImage}\""
opt << "--build-arg SHEBANGTRON_URL=\"${shebangtronUrl}\""
opt << "--build-arg VERSIONDB_MANIFEST_ID=\"${manifestId}\""
opt << "--build-arg LSST_COMPILER=\"${lsstCompiler}\""
opt << "--build-arg LSST_SPLENV_REF=\"${splenvRef}\""
opt << "--load"
opt << '.'
dir(buildDir) {
image = docker.build("${dockerRepo}", opt.join(' '))
// This is temp til we move away from Dockerhub officially
// ghimage should be dropped and we should move it all to
// work like the others
ghimage = docker.build("${ghdockerRepo}", opt.join(' '))
image2 = docker.build("panda-dev-1a74/${dockerRepo}", opt.join(' '))
}
}
stage('push') {
def digest = null
// Should be removed once we drop dockerhub support
def digest2 = null
def arch = lsstswConfig.display_name.tokenize('-').last()
if (!noPush) {
docker.withRegistry(
'https://index.docker.io/v1/',
'dockerhub-sqreadmin'
) {
registryTags.each { name ->
image.push(name+"_"+arch)
}
}
docker.withRegistry(
'https://ghcr.io',
'rubinobs-dm'
) {
ghregistryTags.each { name ->
ghimage.push(name + "_" + arch)
}
}
docker.withRegistry(
'https://us-central1-docker.pkg.dev/',
'google_archive_registry_sa'
) {
registryTags.each { name ->
image2.push(name+"_"+arch)
}
}
digest = sh(
script: "docker inspect --format='{{index .RepoDigests 0}}' ${dockerRepo}:${dockerTag}_${arch}",
returnStdout: true
).trim()
digest2 = sh(
script: "docker inspect --format='{{index .RepoDigests 0}}' ${ghdockerRepo}:${ghdockerTag}_${arch}",
returnStdout: true
).trim()
}
dockerdigest.add(digest)
ghdockerdigest.add(digest2)
} // push
} // run
util.nodeWrap(lsstswConfig.label) {
try {
timeout(time: timelimit, unit: 'HOURS') {
run()
}
} finally {
stage('archive') {
def resultsFile = 'results.json'
util.dumpJson(resultsFile, [
base_image: baseImage ?: null,
image: "${ghdockerRepo}:${ghdockerTag}",
docker_registry: [
repo: ghdockerRepo,
tag: ghdockerTag
],
])
archiveArtifacts([
artifacts: resultsFile,
fingerprint: true
])
} // stage
} // try
} // util.nodeWrap
}
}
parallel matrix
def merge = {
stage('digest'){
def digest = dockerdigest.join(' ')
// should be removed after dropping support for dockerhub
def ghdigest = ghdockerdigest.join(' ')
docker.withRegistry(
'https://index.docker.io/v1/',
'dockerhub-sqreadmin'
) {
registryTags.each { name ->
sh(script: """ \
docker buildx imagetools create -t $dockerRepo:$name \
$digest
""",
returnStdout: true)
}
newRegistryTags.each { name ->
sh(script: """ \
docker buildx imagetools create -t lsstsqre/almalinux:$name \
$digest
""",
returnStdout: true)
}
}
docker.withRegistry(
'https://ghcr.io',
'rubinobs-dm'
) {
ghregistryTags.each { name ->
sh(script: """ \
docker buildx imagetools create -t $ghdockerRepo:$name \
$ghdigest
""",
returnStdout: true)
}
}
docker.withRegistry(
'https://us-central1-docker.pkg.dev/',
'google_archive_registry_sa'
) {
registryTags.each { name ->
sh(script: """ \
docker buildx imagetools create -t us-central1-docker.pkg.dev/panda-dev-1a74/$dockerRepo:$name \
$digest
""",
returnStdout: true)
}
}
}
} // merge
util.nodeWrap('linux-64') {
timeout(time: timelimit, unit: 'HOURS') {
merge()
}
} // nodeWrap
} // notify.wrap