blob: 834ccd832a2128e320a91acdb1bf5489d43b8afd [file] [log] [blame]
Denis Egorenko8c606552016-12-07 14:22:50 +04001package com.mirantis.mcp
2
Artem Panchenkobc13d262017-01-20 12:40:58 +02003
Denis Egorenko8c606552016-12-07 14:22:50 +04004/**
Artem Panchenkobc13d262017-01-20 12:40:58 +02005 * Checkout Calico repository stage
Denis Egorenko8c606552016-12-07 14:22:50 +04006 *
Artem Panchenkobc13d262017-01-20 12:40:58 +02007 * @param config LinkedHashMap
8 * config includes next parameters:
9 * - project_name String, Calico project to clone
10 * - projectNamespace String, gerrit namespace (optional)
11 * - commit String, Git commit to checkout
12 * - credentialsId String, gerrit credentials ID (optional)
13 * - host String, gerrit host
14 *
15 * Usage example:
16 *
17 * def calico = new com.mirantis.mcp.Calico()
18 * calico.checkoutCalico([
19 * project_name : 'cni-plugin',
20 * commit : 'mcp',
21 * host : 'gerrit.mcp.mirantis.net',
22 * ])
23 *
24 */
25def checkoutCalico(LinkedHashMap config) {
26
27 def git = new com.mirantis.mcp.Git()
28
29 def project_name = config.get('project_name')
30 def projectNamespace = config.get('projectNamespace', 'projectcalico')
31 def commit = config.get('commit')
32 def host = config.get('host')
Artem Panchenkod10610b2017-01-27 18:09:52 +020033 def credentialsId = config.get('credentialsId', 'mcp-ci-gerrit')
Artem Panchenkobc13d262017-01-20 12:40:58 +020034
35 if (!project_name) {
36 throw new RuntimeException("Parameter 'project_name' must be set for checkoutCalico() !")
37 }
38 if (!commit) {
39 throw new RuntimeException("Parameter 'commit' must be set for checkoutCalico() !")
40 }
41
42 stage ("Checkout ${project_name}"){
43 git.gitSSHCheckout([
44 credentialsId : credentialsId,
45 branch : commit,
46 host : host,
47 project : "${projectNamespace}/${project_name}",
48 withWipeOut : true,
49 ])
50 }
51}
52
53
54/**
55 * Build bird binaries stage
56 *
57 * Usage example:
58 *
59 * def calico = new com.mirantis.mcp.Calico()
60 * calico.buildCalicoBird()
61 *
62 */
63def buildCalicoBird() {
64 stage ('Build bird binaries'){
65 sh "/bin/sh -x build.sh"
66 }
67}
68
69
70/**
71 * Publish bird binaries stage
72 *
73 * @param config LinkedHashMap
74 * config includes next parameters:
75 * - artifactoryServerName String, artifactory server name
76 * - binaryRepo String, repository (artifactory) for binary files
77 * - projectNamespace String, artifactory server namespace (optional)
78 * - publishInfo Boolean, whether publish a build-info object to Artifactory (optional)
79 *
80 * Usage example:
81 *
82 * def calico = new com.mirantis.mcp.Calico()
83 * calico.publishCalicoBird([
84 * artifactoryServerName : 'mcp-ci',
85 * binaryRepo : 'sandbox-binary-dev-local',
86 * ])
87 *
88 */
89def publishCalicoBird(LinkedHashMap config) {
90
91 def common = new com.mirantis.mcp.Common()
92 def git = new com.mirantis.mcp.Git()
93 def artifactory = new com.mirantis.mcp.MCPArtifactory()
94
95 def artifactoryServerName = config.get('artifactoryServerName')
96 def binaryRepo = config.get('binaryRepo')
97 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
98 def publishInfo = config.get('publishInfo', true)
99
100 if (!artifactoryServerName) {
101 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for publishCalicoBird() !")
102 }
103 if (!binaryRepo) {
104 throw new RuntimeException("Parameter 'binaryRepo' must be set for publishCalicoBird() !")
105 }
106
107 def artifactoryServer = Artifactory.server(artifactoryServerName)
108 def buildInfo = Artifactory.newBuildInfo()
109
110 stage('Publishing bird artifacts') {
111 dir("artifacts"){
112 // define tag for bird
113 binaryTag = git.getGitDescribe(true) + "-" + common.getDatetime()
114 sh """
115 cp ../dist/bird bird-${binaryTag}
116 cp ../dist/bird6 bird6-${binaryTag}
117 cp ../dist/birdcl birdcl-${binaryTag}
118 """
119 writeFile file: "latest", text: "${binaryTag}"
120 // define mandatory properties for binary artifacts
121 // and some additional
122 def properties = artifactory.getBinaryBuildProperties([
123 "tag=${binaryTag}",
124 "project=bird"
125 ])
126
127 def uploadSpec = """{
128 "files": [
129 {
130 "pattern": "**",
131 "target": "${binaryRepo}/${projectNamespace}/bird/",
132 "props": "${properties}"
133 }
134 ]
135 }"""
136
137 // Upload to Artifactory.
138 artifactory.uploadBinariesToArtifactory(artifactoryServer, buildInfo, uploadSpec, publishInfo)
139 }// dir
140 }
141 return binaryTag
142}
143
144
145/**
146 * Test confd stage
147 *
148 *
149 * Usage example:
150 *
151 * def calico = new com.mirantis.mcp.Calico()
152 * calico.testCalicoConfd()
153 *
154 */
155def testCalicoConfd() {
156 stage ('Run unittest for confd'){
157 sh """
158 docker run --rm \
159 -v \$(pwd):/usr/src/confd \
160 -w /usr/src/confd \
161 golang:1.7 \
162 bash -c \
163 \"go get github.com/constabulary/gb/...; gb test -v\"
164 """
165 }
166}
167
168
169/**
170 * Build confd binaries stage
171 *
172 *
173 * Usage example:
174 *
175 * def calico = new com.mirantis.mcp.Calico()
176 * calico.buildCalicoConfd()
177 *
178 */
179def buildCalicoConfd() {
180 def container_src_dir = "/usr/src/confd"
181 def src_suffix = "src/github.com/kelseyhightower/confd"
182 def container_workdir = "${container_src_dir}/${src_suffix}"
183 def container_gopath = "${container_src_dir}/vendor:${container_src_dir}"
184
185 stage ('Build confd binary'){
186 sh """
187 docker run --rm \
188 -v \$(pwd):${container_src_dir} \
189 -w ${container_workdir} \
190 -e GOPATH=${container_gopath} \
191 golang:1.7 \
192 bash -c \
193 \"go build -a -installsuffix cgo -ldflags '-extld ld -extldflags -static' -a -x .\"
194 """
195 }
196}
197
198
199/**
200 * Publish confd binaries stage
201 *
202 * @param config LinkedHashMap
203 * config includes next parameters:
204 * - artifactoryServerName String, artifactory server name
205 * - binaryRepo String, repository (artifactory) for binary files
206 * - projectNamespace String, artifactory server namespace (optional)
207 * - publishInfo Boolean, whether publish a build-info object to Artifactory (optional)
208 *
209 * Usage example:
210 *
211 * def calico = new com.mirantis.mcp.Calico()
212 * calico.publishCalicoConfd([
213 * artifactoryServerName : 'mcp-ci',
214 * binaryRepo : 'sandbox-binary-dev-local',
215 * ])
216 *
217 */
218def publishCalicoConfd(LinkedHashMap config) {
219
220 def common = new com.mirantis.mcp.Common()
221 def git = new com.mirantis.mcp.Git()
222 def artifactory = new com.mirantis.mcp.MCPArtifactory()
223
224 def artifactoryServerName = config.get('artifactoryServerName')
225 def binaryRepo = config.get('binaryRepo')
226 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
227 def publishInfo = config.get('publishInfo', true)
228 def src_suffix = "src/github.com/kelseyhightower/confd"
229
230 if (!artifactoryServerName) {
231 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for publishCalicoConfd() !")
232 }
233 if (!binaryRepo) {
234 throw new RuntimeException("Parameter 'binaryRepo' must be set for publishCalicoConfd() !")
235 }
236
237 def artifactoryServer = Artifactory.server(artifactoryServerName)
238 def buildInfo = Artifactory.newBuildInfo()
239
240 stage('Publishing confd artifacts') {
241
242 dir("artifacts"){
243 // define tag for confd
244 binaryTag = git.getGitDescribe(true) + "-" + common.getDatetime()
245 // create two files confd and confd+tag
246 sh "cp ../${src_suffix}/confd confd-${binaryTag}"
247 writeFile file: "latest", text: "${binaryTag}"
248
249 // define mandatory properties for binary artifacts
250 // and some additional
251 def properties = artifactory.getBinaryBuildProperties([
252 "tag=${binaryTag}",
253 "project=confd"
254 ])
255
256 def uploadSpec = """{
257 "files": [
258 {
259 "pattern": "**",
260 "target": "${binaryRepo}/${projectNamespace}/confd/",
261 "props": "${properties}"
262 }
263 ]
264 }"""
265
266 // Upload to Artifactory.
267 artifactory.uploadBinariesToArtifactory(artifactoryServer, buildInfo, uploadSpec, publishInfo)
268 }// dir
269 }
270 return binaryTag
271}
272
273
274/**
275 * Test libcalico stage
276 *
277 * Usage example:
278 *
279 * def calico = new com.mirantis.mcp.Calico()
280 * calico.testLibcalico()
281 *
282 */
283def testLibcalico() {
284 stage ('Run libcalico unittests'){
285 sh "make test"
286 }
287}
288
289
290/**
291 * Build calico/build image stage
292 *
293 * @param config LinkedHashMap
294 * config includes next parameters:
295 * - dockerRegistry String, Docker registry host to push image to (optional)
296 * - projectNamespace String, artifactory server namespace (optional)
297 * - buildImageTag String, calico/build image name (optional)
298 * - imageTag String, tag of docker image (optional)
299 *
300 * Usage example:
301 *
302 * def calicoFunc = new com.mirantis.mcp.Calico()
303 * calicoFunc.buildLibcalico([
304 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
305 * ])
306 *
307 */
308def buildLibcalico(LinkedHashMap config) {
309
310 def common = new com.mirantis.mcp.Common()
311 def docker = new com.mirantis.mcp.Docker()
312 def git = new com.mirantis.mcp.Git()
313
314 def dockerRegistry = config.get('dockerRegistry')
315 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
316
317 def buildImage = config.get('buildImage', "calico/build")
318 def buildImageTag = config.get('buildImageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
319
320 def buildContainerName = dockerRegistry ? "${dockerRegistry}/${projectNamespace}/${buildImage}:${buildImageTag}" : "${buildImage}:${buildImageTag}"
321
322 stage ('Build calico/build image') {
323 docker.setDockerfileLabels("./Dockerfile", ["docker.imgTag=${buildImageTag}"])
324 sh """
325 make calico/build BUILD_CONTAINER_NAME=${buildContainerName}
326 """
327 }
328 return [buildImage : buildImage,
329 buildImageTag : buildImageTag]
330}
331
332
333/**
334 * Switch Calico to use dowstream libcalico-go repository stage
335 *
336 * @param libCalicoGoCommit String, libcalico-go repository commit to checkout to
337 * @param host String, gerrit host
338 * @param glideLockFilePath String, relative path to glide.lock file
339 *
340 * Usage example:
341 *
342 * def calico = new com.mirantis.mcp.Calico()
343 * // Checkout calico code using calico.checkoutCalico() and then call this method from the same dir
344 * calico.switchCalicoToDownstreamLibcalicoGo('mcp', 'gerrit.mcp.mirantis.net', './glide.lock')
345 *
346 */
347def switchCalicoToDownstreamLibcalicoGo(String libCalicoGoCommit, String host, String glideLockFilePath) {
Sergey Reshetnyak70b1fe62017-01-31 22:27:06 +0300348 def common = new com.mirantis.mcp.Common()
Artem Panchenkobc13d262017-01-20 12:40:58 +0200349 def git = new com.mirantis.mcp.Git()
350
351 stage ('Switch to downstream libcalico-go') {
352 def libcalicogo_path = "${env.WORKSPACE}/tmp_libcalico-go"
353
354 git.gitSSHCheckout([
Artem Panchenkod10610b2017-01-27 18:09:52 +0200355 credentialsId : "mcp-ci-gerrit",
Artem Panchenkobc13d262017-01-20 12:40:58 +0200356 branch : libCalicoGoCommit,
357 host : host,
358 project : "projectcalico/libcalico-go",
359 targetDir : libcalicogo_path,
360 withWipeOut : true,
361 ])
362
363 sh "cp ${glideLockFilePath} ${glideLockFilePath}.bak"
364 def glideLockFileContent = readFile file: glideLockFilePath
Sergey Reshetnyak70b1fe62017-01-31 22:27:06 +0300365 def glideMap = common.loadYAML(glideLockFileContent)
Artem Panchenkobc13d262017-01-20 12:40:58 +0200366
367 for (goImport in glideMap['imports']) {
368 if (goImport['name'].contains('libcalico-go')) {
369 goImport['repo'] = 'file:///go/src/github.com/projectcalico/libcalico-go'
370 goImport['vcs'] = 'git'
371 }
372 }
373
Sergey Reshetnyak70b1fe62017-01-31 22:27:06 +0300374 writeFile file: glideLockFilePath, text: common.dumpYAML(glideMap)
Artem Panchenkobc13d262017-01-20 12:40:58 +0200375
376 sh "LIBCALICOGO_PATH=${libcalicogo_path} make vendor"
377 }
378}
379
380
381/**
382 * Test Felix stage
383 *
384 * Usage example:
385 *
386 * def calico = new com.mirantis.mcp.Calico()
387 * calico.testFelix()
388 *
389 */
390def testFelix() {
391 stage ('Run felix unittests'){
392 // inject COMPARE_BRANCH variable for felix tests coverage (python code) check
393 def COMPARE_BRANCH = env.GERRIT_BRANCH ? "gerrit/${env.GERRIT_BRANCH}" : "origin/mcp"
394 sh "make ut UT_COMPARE_BRANCH=${COMPARE_BRANCH}"
395 }
396}
397
398
399/**
400 * Build calico/felix image stage
401 *
402 * @param config LinkedHashMap
403 * config includes next parameters:
404 * - dockerRegistry String, Docker registry host to push image to (optional)
405 * - projectNamespace String, artifactory server namespace (optional)
406 * - felixImage String, calico/felix image name (optional)
407 * - felixImageTag String, tag of docker image (optional)
408 *
409 * Usage example:
410 *
411 * def calicoFunc = new com.mirantis.mcp.Calico()
412 * calicoFunc.buildFelix([
413 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
414 * ])
415 *
416 */
417def buildFelix(LinkedHashMap config) {
418
419 def common = new com.mirantis.mcp.Common()
420 def docker = new com.mirantis.mcp.Docker()
421 def git = new com.mirantis.mcp.Git()
422
423 def dockerRegistry = config.get('dockerRegistry')
424 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
425
426 def felixImage = config.get('felixImage', "calico/felix")
427 def felixImageTag = config.get('felixImageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
428
429 def felixContainerName = dockerRegistry ? "${dockerRegistry}/${projectNamespace}/${felixImage}:${felixImageTag}" : "${felixImage}:${felixImageTag}"
430
431 stage ('Build calico/felix image') {
432 docker.setDockerfileLabels("./Dockerfile", ["docker.imgTag=${felixImageTag}"])
433 sh """
434 make calico/felix
435 docker tag calico/felix ${felixContainerName}
436 """
437 }
438 return [felixImage : felixImage,
439 felixImageTag : felixImageTag]
440}
441
442/**
443 * Test Calicoctl stage
444 *
445 * Usage example:
446 *
447 * def calico = new com.mirantis.mcp.Calico()
448 * calico.testCalicoctl()
449 *
450 */
451def testCalicoctl() {
452 stage ('Run calicoctl unittests'){
453 sh "make test-containerized"
454 }
455}
456
457
458/**
459 * Build Calico containers stages
460 *
461 * @param config LinkedHashMap
462 * config includes next parameters:
463 * - dockerRegistry String, repo with docker images
464 * - projectNamespace String, artifactory server namespace
465 * - artifactoryURL String, URL to repo with calico-binaries
Denis Egorenko8c606552016-12-07 14:22:50 +0400466 * - imageTag String, tag of images
467 * - nodeImage String, Calico Node image name
468 * - ctlImage String, Calico CTL image name
469 * - buildImage String, Calico Build image name
470 * - felixImage String, Calico Felix image name
471 * - confdBuildId String, Version of Calico Confd
472 * - confdUrl String, URL to Calico Confd
473 * - birdUrl, URL to Calico Bird
474 * - birdBuildId, Version of Calico Bird
475 * - bird6Url, URL to Calico Bird6
476 * - birdclUrl, URL to Calico BirdCL
477 *
478 * Usage example:
479 *
480 * def calicoFunc = new com.mirantis.mcp.Calico()
Artem Panchenkobc13d262017-01-20 12:40:58 +0200481 * calicoFunc.buildCalicoContainers([
482 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
483 * artifactoryURL : 'https://artifactory.mcp.mirantis.net/artifactory/sandbox',
484 * ])
Denis Egorenko8c606552016-12-07 14:22:50 +0400485 *
486 */
Artem Panchenkobc13d262017-01-20 12:40:58 +0200487def buildCalicoContainers(LinkedHashMap config) {
Denis Egorenko8c606552016-12-07 14:22:50 +0400488
Artem Panchenkobc13d262017-01-20 12:40:58 +0200489 def common = new com.mirantis.mcp.Common()
490 def docker = new com.mirantis.mcp.Docker()
491 def git = new com.mirantis.mcp.Git()
Denis Egorenko8c606552016-12-07 14:22:50 +0400492
Artem Panchenkobc13d262017-01-20 12:40:58 +0200493 def dockerRegistry = config.get('dockerRegistry')
494 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
495 def artifactoryURL = config.get('artifactoryURL')
Denis Egorenko8c606552016-12-07 14:22:50 +0400496
Artem Panchenkobc13d262017-01-20 12:40:58 +0200497 if (! dockerRegistry ) {
498 error('dockerRegistry parameter has to be set.')
Denis Egorenko8c606552016-12-07 14:22:50 +0400499 }
500
Artem Panchenkobc13d262017-01-20 12:40:58 +0200501 if (! artifactoryURL ) {
502 error('artifactoryURL parameter has to be set.')
Denis Egorenko8c606552016-12-07 14:22:50 +0400503 }
504
Artem Panchenkobc13d262017-01-20 12:40:58 +0200505 def imgTag = config.get('imageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
Denis Egorenko8c606552016-12-07 14:22:50 +0400506
Artem Panchenkobc13d262017-01-20 12:40:58 +0200507 def nodeImage = config.get('nodeImage', "calico/node")
508 def nodeRepo = "${dockerRegistry}/${projectNamespace}/${nodeImage}"
509 def nodeName = "${nodeRepo}:${imgTag}"
Denis Egorenko8c606552016-12-07 14:22:50 +0400510
Artem Panchenkobc13d262017-01-20 12:40:58 +0200511 def ctlImage = config.get('ctlImage', "calico/ctl")
512 def ctlRepo = "${dockerRegistry}/${projectNamespace}/${ctlImage}"
513 def ctlName = "${ctlRepo}:${imgTag}"
Denis Egorenko8c606552016-12-07 14:22:50 +0400514
515 // calico/build goes from libcalico
Artem Panchenkobc13d262017-01-20 12:40:58 +0200516 def buildImage = config.get('buildImage',"${dockerRegistry}/${projectNamespace}/calico/build:latest")
Denis Egorenko8c606552016-12-07 14:22:50 +0400517 // calico/felix goes from felix
Artem Panchenkobc13d262017-01-20 12:40:58 +0200518 def felixImage = config.get('felixImage', "${dockerRegistry}/${projectNamespace}/calico/felix:latest")
Denis Egorenko8c606552016-12-07 14:22:50 +0400519
Artem Panchenkobc13d262017-01-20 12:40:58 +0200520 def confdBuildId = config.get('confdBuildId', "${artifactoryURL}/${projectNamespace}/confd/latest".toURL().text.trim())
521 def confdUrl = config.get('confdUrl', "${artifactoryURL}/${projectNamespace}/confd/confd-${confdBuildId}")
Denis Egorenko8c606552016-12-07 14:22:50 +0400522
Artem Panchenkobc13d262017-01-20 12:40:58 +0200523 def birdBuildId = config.get('birdBuildId', "${artifactoryURL}/${projectNamespace}/bird/latest".toURL().text.trim())
524 def birdUrl = config.get('birdUrl', "${artifactoryURL}/${projectNamespace}/bird/bird-${birdBuildId}")
525 def bird6Url = config.get('bird6Url', "${artifactoryURL}/${projectNamespace}/bird/bird6-${birdBuildId}")
526 def birdclUrl = config.get('birdclUrl', "${artifactoryURL}/${projectNamespace}/bird/birdcl-${birdBuildId}")
Denis Egorenko8c606552016-12-07 14:22:50 +0400527
528 // add LABELs to dockerfiles
Denis Egorenko2bc89172016-12-21 17:31:19 +0400529 docker.setDockerfileLabels("./calicoctl/Dockerfile.calicoctl",
530 ["docker.imgTag=${imgTag}",
531 "calico.buildImage=${buildImage}",
532 "calico.birdclUrl=${birdclUrl}"])
Denis Egorenko8c606552016-12-07 14:22:50 +0400533
Denis Egorenko2bc89172016-12-21 17:31:19 +0400534 docker.setDockerfileLabels("./calico_node/Dockerfile",
535 ["docker.imgTag=${imgTag}",
536 "calico.buildImage=${buildImage}",
537 "calico.felixImage=${felixImage}",
538 "calico.confdUrl=${confdUrl}",
539 "calico.birdUrl=${birdUrl}",
540 "calico.bird6Url=${bird6Url}",
541 "calico.birdclUrl=${birdclUrl}"])
Denis Egorenko8c606552016-12-07 14:22:50 +0400542
543 // Start build section
544 stage ('Build calico/ctl image'){
545 sh """
546 make calico/ctl \
547 CTL_CONTAINER_NAME=${ctlName} \
548 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
549 BIRDCL_URL=${birdclUrl}
550 """
551 }
552
553
554 stage('Build calico/node'){
555 sh """
556 make calico/node \
557 NODE_CONTAINER_NAME=${nodeName} \
558 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
559 FELIX_CONTAINER_NAME=${felixImage} \
560 CONFD_URL=${confdUrl} \
561 BIRD_URL=${birdUrl} \
562 BIRD6_URL=${bird6Url} \
563 BIRDCL_URL=${birdclUrl}
564 """
565 }
566
567
568 return [
Artem Panchenkobc13d262017-01-20 12:40:58 +0200569 CTL_CONTAINER_NAME:"${ctlImage}",
570 NODE_CONTAINER_NAME:"${nodeImage}",
571 CALICO_NODE_IMAGE_REPO:"${nodeRepo}",
572 CALICOCTL_IMAGE_REPO:"${ctlRepo}",
Denis Egorenko8c606552016-12-07 14:22:50 +0400573 CALICO_VERSION: "${imgTag}"
574 ]
575
576}
Artem Panchenkobc13d262017-01-20 12:40:58 +0200577
578
579/**
580 * Test Calico CNI plugin stage
581 *
582 * Usage example:
583 *
584 * def calico = new com.mirantis.mcp.Calico()
585 * calico.testCniPlugin()
586 *
587 */
588def testCniPlugin() {
589 stage ('Run cni-plugin unittests'){
590 // 'static-checks-containerized' target is removed from master
591 // and kept here only for backward compatibility
592 sh "make static-checks || make static-checks-containerized"
593 sh "make stop-etcd stop-kubernetes-master"
594 // 'stop-k8s-apiserver' target doesn't exist in Calico v2.0.0,
595 // so do not fail the stage if it's not found
596 sh "make stop-k8s-apiserver || true"
597 sh "make test-containerized"
598 }
599}
600
601
602/**
603 * Build calico/cni image stage
604 *
605 * @param config LinkedHashMap
606 * config includes next parameters:
607 * - dockerRegistry String, Docker registry host to push image to (optional)
608 * - projectNamespace String, artifactory server namespace (optional)
609 * - cniImage String, calico/cni image name (optional)
610 * - cniImageTag String, tag of docker image (optional)
611 *
612 * Usage example:
613 *
614 * def calicoFunc = new com.mirantis.mcp.Calico()
615 * calicoFunc.buildFelix([
616 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
617 * ])
618 *
619 */
620def buildCniPlugin(LinkedHashMap config) {
621
622 def common = new com.mirantis.mcp.Common()
623 def docker = new com.mirantis.mcp.Docker()
624 def git = new com.mirantis.mcp.Git()
625
626 def dockerRegistry = config.get('dockerRegistry')
627 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
628
629 def cniImage = config.get('cniImage', "calico/cni")
630 def cniImageTag = config.get('cniImageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
631
632 def cniContainerName = dockerRegistry ? "${dockerRegistry}/${projectNamespace}/${cniImage}:${cniImageTag}" : "${cniImage}:${cniImageTag}"
633
634 stage ('Build calico/cni image') {
635 docker.setDockerfileLabels("./Dockerfile", ["docker.imgTag=${cniImageTag}"])
636 sh """
637 make docker-image
638 docker tag calico/cni ${cniContainerName}
639 """
640 }
641 return [cniImage : cniImage,
642 cniImageTag : cniImageTag]
643}
644
645
646/**
647 * Publish calico docker image stage
648 *
649 * @param config LinkedHashMap
650 * config includes next parameters:
651 * - artifactoryServerName String, artifactory server name
652 * - dockerRegistry String, Docker registry host to push image to
Sergey Kulanova9e65042017-01-31 14:20:24 +0200653 * - dockerRepo String, repository (artifactory) for docker images, must not be Virtual
Artem Panchenkobc13d262017-01-20 12:40:58 +0200654 * - imageName String, Docker image name
655 * - imageTag String, Docker image tag
656 * - projectNamespace String, artifactory server namespace (optional)
657 * - publishInfo Boolean, whether publish a build-info object to Artifactory (optional)
658 *
659 * Usage example:
660 *
661 * def calico = new com.mirantis.mcp.Calico()
662 * calico.publishCalicoImage([
663 * artifactoryServerName : 'mcp-ci',
664 * dockerRegistry : 'sandbox-docker-dev-local.docker.mirantis.net'
665 * dockerRepo : 'sandbox-docker-dev-local',
666 * imageName : 'calico/node',
667 * imageTag : 'v.1.0.0',
668 * ])
669 *
670 */
Sergey Kulanova9e65042017-01-31 14:20:24 +0200671def publishCalicoImage(LinkedHashMap config) {
Artem Panchenkobc13d262017-01-20 12:40:58 +0200672 def artifactory = new com.mirantis.mcp.MCPArtifactory()
673
674 def artifactoryServerName = config.get('artifactoryServerName')
675 def dockerRegistry = config.get('dockerRegistry')
676 def dockerRepo = config.get('dockerRepo')
677 def imageName = config.get('imageName')
678 def imageTag = config.get('imageTag')
679 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
680 def publishInfo = config.get('publishInfo', true)
681
682 if (!artifactoryServerName) {
683 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for publishCalicoImage() !")
684 }
685 if (!dockerRegistry) {
686 throw new RuntimeException("Parameter 'dockerRegistry' must be set for publishCalicoImage() !")
687 }
688 if (!dockerRepo) {
Sergey Kulanova9e65042017-01-31 14:20:24 +0200689 throw new RuntimeException("Parameter 'dockerRepo' must be set for publishCalicoImage() !")
Artem Panchenkobc13d262017-01-20 12:40:58 +0200690 }
691 if (!imageName) {
692 throw new RuntimeException("Parameter 'imageName' must be set for publishCalicoImage() !")
693 }
694 if (!imageTag) {
695 throw new RuntimeException("Parameter 'imageTag' must be set for publishCalicoImage() !")
696 }
697
698 def artifactoryServer = Artifactory.server(artifactoryServerName)
699 def buildInfo = publishInfo ? Artifactory.newBuildInfo() : null
700
701 stage("Publishing ${imageName}") {
702 artifactory.uploadImageToArtifactory(artifactoryServer,
703 dockerRegistry,
704 "${projectNamespace}/${imageName}",
705 imageTag,
706 dockerRepo,
707 buildInfo)
708 }
709 return "${dockerRegistry}/${projectNamespace}/${imageName}:${imageTag}"
710}
711
712
713/**
714 * Promote calico docker image stage
715 *
716 * @param config LinkedHashMap
717 * config includes next parameters:
718 * - imageProperties Map, docker image search properties in artifactory
719 * - artifactoryServerName String, artifactory server name
720 * - dockerLookupRepo String, docker repository (artifactory) to take image from
721 * - dockerPromoteRepo String, docker repository (artifactory) to promote image to
722 * - imageName String, Docker image name to promote with
723 * - imageTag String, Docker image tag to promote with
724 * - projectNamespace String, artifactory server namespace (optional)
725 * - defineLatest Boolean, promote with latest tag if true, default false (optional)
726 *
727 * Usage example:
728 *
729 * def calico = new com.mirantis.mcp.Calico()
730 * calico.promoteCalicoImage([
731 * imageProperties: [
732 * 'com.mirantis.targetImg': 'mirantis/projectcalico/calico/node',
733 * 'com.mirantis.targetTag': 'v1.0.0-2017010100000',
734 * ]
735 * artifactoryServerName : 'mcp-ci',
736 * dockerLookupRepo : 'sandbox-docker-dev-local',
737 * dockerPromoteRepo: 'sandbox-docker-prod-local',
738 * imageName: 'calico/node',
739 * imageTag: 'v1.0.0',
740 * defineLatest: true
741 * ])
742 *
743 */
744def promoteCalicoImage (LinkedHashMap config) {
745 def common = new com.mirantis.mcp.Common()
746 def git = new com.mirantis.mcp.Git()
747 def artifactory = new com.mirantis.mcp.MCPArtifactory()
748
749 def imageProperties = config.get('imageProperties')
750 def artifactoryServerName = config.get('artifactoryServerName')
751 def dockerLookupRepo = config.get('dockerLookupRepo')
752 def dockerPromoteRepo = config.get('dockerPromoteRepo')
753 def imageName = config.get('imageName')
754 def imageTag = config.get('imageTag')
755 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
756 def defineLatest = config.get('defineLatest', false)
757
758if (!imageProperties) {
759 throw new RuntimeException("Parameter 'imageProperties' must be set for promoteCalicoImage() !")
760 }
761 if (!artifactoryServerName) {
762 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for promoteCalicoImage() !")
763 }
764 if (!dockerLookupRepo) {
765 throw new RuntimeException("Parameter 'dockerLookupRepo' must be set for promoteCalicoImage() !")
766 }
767 if (!dockerPromoteRepo) {
768 throw new RuntimeException("Parameter 'dockerPromoteRepo' must be set for promoteCalicoImage() !")
769 }
770 if (!imageName) {
771 throw new RuntimeException("Parameter 'imageName' must be set for promoteCalicoImage() !")
772 }
773 if (!imageTag) {
774 throw new RuntimeException("Parameter 'imageTag' must be set for promoteCalicoImage() !")
775 }
776
777 def artifactoryServer = Artifactory.server(artifactoryServerName)
778 def artifactURI = artifactory.uriByProperties(artifactoryServer.getUrl(), imageProperties)
779
780 stage("Promote ${imageName}") {
781 if ( artifactURI ) {
782 def buildProperties = artifactory.getPropertiesForArtifact(artifactURI)
783 if (defineLatest) {
784 artifactory.promoteDockerArtifact(
785 artifactoryServer.getUrl(),
786 dockerLookupRepo,
787 dockerPromoteRepo,
788 "${projectNamespace}/${imageName}",
789 buildProperties.get('com.mirantis.targetTag').join(','),
790 'latest',
791 true
792 )
793 }
794 artifactory.promoteDockerArtifact(
795 artifactoryServer.getUrl(),
796 dockerLookupRepo,
797 dockerPromoteRepo,
798 "${projectNamespace}/${imageName}",
799 buildProperties.get('com.mirantis.targetTag').join(','),
800 "${imageTag}",
801 false
802 )
803 }
804 else {
805 throw new RuntimeException("Artifacts were not found, nothing to promote! "
806 +"Given image properties: ${imageProperties}")
807 }
808 }
809}
810
811
812def calicoFixOwnership() {
813 // files created inside container could be owned by root, fixing that
814 sh "sudo chown -R \$(id -u):\$(id -g) ${env.WORKSPACE} ${env.HOME}/.glide || true"
815}