blob: 51826c29f9c5b3d7b81a70afc5789605df83645d [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"
Artem Panchenkod79430f2017-02-01 00:34:21 +0200377 // need this to reset glide.lock changes (vendor dir is already compiled)
378 // otherwise binaries will be versioned with '-dirty' suffix
379 sh "git checkout ."
Artem Panchenkobc13d262017-01-20 12:40:58 +0200380 }
381}
382
383
384/**
385 * Test Felix stage
386 *
387 * Usage example:
388 *
389 * def calico = new com.mirantis.mcp.Calico()
390 * calico.testFelix()
391 *
392 */
393def testFelix() {
394 stage ('Run felix unittests'){
395 // inject COMPARE_BRANCH variable for felix tests coverage (python code) check
396 def COMPARE_BRANCH = env.GERRIT_BRANCH ? "gerrit/${env.GERRIT_BRANCH}" : "origin/mcp"
397 sh "make ut UT_COMPARE_BRANCH=${COMPARE_BRANCH}"
398 }
399}
400
401
402/**
403 * Build calico/felix image stage
404 *
405 * @param config LinkedHashMap
406 * config includes next parameters:
407 * - dockerRegistry String, Docker registry host to push image to (optional)
408 * - projectNamespace String, artifactory server namespace (optional)
409 * - felixImage String, calico/felix image name (optional)
410 * - felixImageTag String, tag of docker image (optional)
411 *
412 * Usage example:
413 *
414 * def calicoFunc = new com.mirantis.mcp.Calico()
415 * calicoFunc.buildFelix([
416 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
417 * ])
418 *
419 */
420def buildFelix(LinkedHashMap config) {
421
422 def common = new com.mirantis.mcp.Common()
423 def docker = new com.mirantis.mcp.Docker()
424 def git = new com.mirantis.mcp.Git()
425
426 def dockerRegistry = config.get('dockerRegistry')
427 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
428
429 def felixImage = config.get('felixImage', "calico/felix")
430 def felixImageTag = config.get('felixImageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
431
432 def felixContainerName = dockerRegistry ? "${dockerRegistry}/${projectNamespace}/${felixImage}:${felixImageTag}" : "${felixImage}:${felixImageTag}"
433
434 stage ('Build calico/felix image') {
435 docker.setDockerfileLabels("./Dockerfile", ["docker.imgTag=${felixImageTag}"])
436 sh """
437 make calico/felix
438 docker tag calico/felix ${felixContainerName}
439 """
440 }
441 return [felixImage : felixImage,
442 felixImageTag : felixImageTag]
443}
444
445/**
446 * Test Calicoctl stage
447 *
448 * Usage example:
449 *
450 * def calico = new com.mirantis.mcp.Calico()
451 * calico.testCalicoctl()
452 *
453 */
454def testCalicoctl() {
455 stage ('Run calicoctl unittests'){
456 sh "make test-containerized"
457 }
458}
459
460
461/**
462 * Build Calico containers stages
463 *
464 * @param config LinkedHashMap
465 * config includes next parameters:
466 * - dockerRegistry String, repo with docker images
467 * - projectNamespace String, artifactory server namespace
468 * - artifactoryURL String, URL to repo with calico-binaries
Denis Egorenko8c606552016-12-07 14:22:50 +0400469 * - imageTag String, tag of images
470 * - nodeImage String, Calico Node image name
471 * - ctlImage String, Calico CTL image name
472 * - buildImage String, Calico Build image name
473 * - felixImage String, Calico Felix image name
474 * - confdBuildId String, Version of Calico Confd
475 * - confdUrl String, URL to Calico Confd
476 * - birdUrl, URL to Calico Bird
477 * - birdBuildId, Version of Calico Bird
478 * - bird6Url, URL to Calico Bird6
479 * - birdclUrl, URL to Calico BirdCL
480 *
481 * Usage example:
482 *
483 * def calicoFunc = new com.mirantis.mcp.Calico()
Artem Panchenkobc13d262017-01-20 12:40:58 +0200484 * calicoFunc.buildCalicoContainers([
485 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
486 * artifactoryURL : 'https://artifactory.mcp.mirantis.net/artifactory/sandbox',
487 * ])
Denis Egorenko8c606552016-12-07 14:22:50 +0400488 *
489 */
Artem Panchenkobc13d262017-01-20 12:40:58 +0200490def buildCalicoContainers(LinkedHashMap config) {
Denis Egorenko8c606552016-12-07 14:22:50 +0400491
Artem Panchenkobc13d262017-01-20 12:40:58 +0200492 def common = new com.mirantis.mcp.Common()
493 def docker = new com.mirantis.mcp.Docker()
494 def git = new com.mirantis.mcp.Git()
Denis Egorenko8c606552016-12-07 14:22:50 +0400495
Artem Panchenkobc13d262017-01-20 12:40:58 +0200496 def dockerRegistry = config.get('dockerRegistry')
497 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
498 def artifactoryURL = config.get('artifactoryURL')
Denis Egorenko8c606552016-12-07 14:22:50 +0400499
Artem Panchenkobc13d262017-01-20 12:40:58 +0200500 if (! dockerRegistry ) {
501 error('dockerRegistry parameter has to be set.')
Denis Egorenko8c606552016-12-07 14:22:50 +0400502 }
503
Artem Panchenkobc13d262017-01-20 12:40:58 +0200504 if (! artifactoryURL ) {
505 error('artifactoryURL parameter has to be set.')
Denis Egorenko8c606552016-12-07 14:22:50 +0400506 }
507
Artem Panchenkobc13d262017-01-20 12:40:58 +0200508 def imgTag = config.get('imageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
Denis Egorenko8c606552016-12-07 14:22:50 +0400509
Artem Panchenkobc13d262017-01-20 12:40:58 +0200510 def nodeImage = config.get('nodeImage', "calico/node")
511 def nodeRepo = "${dockerRegistry}/${projectNamespace}/${nodeImage}"
512 def nodeName = "${nodeRepo}:${imgTag}"
Denis Egorenko8c606552016-12-07 14:22:50 +0400513
Artem Panchenkobc13d262017-01-20 12:40:58 +0200514 def ctlImage = config.get('ctlImage', "calico/ctl")
515 def ctlRepo = "${dockerRegistry}/${projectNamespace}/${ctlImage}"
516 def ctlName = "${ctlRepo}:${imgTag}"
Denis Egorenko8c606552016-12-07 14:22:50 +0400517
518 // calico/build goes from libcalico
Artem Panchenkobc13d262017-01-20 12:40:58 +0200519 def buildImage = config.get('buildImage',"${dockerRegistry}/${projectNamespace}/calico/build:latest")
Denis Egorenko8c606552016-12-07 14:22:50 +0400520 // calico/felix goes from felix
Artem Panchenkobc13d262017-01-20 12:40:58 +0200521 def felixImage = config.get('felixImage', "${dockerRegistry}/${projectNamespace}/calico/felix:latest")
Denis Egorenko8c606552016-12-07 14:22:50 +0400522
Artem Panchenkobc13d262017-01-20 12:40:58 +0200523 def confdBuildId = config.get('confdBuildId', "${artifactoryURL}/${projectNamespace}/confd/latest".toURL().text.trim())
524 def confdUrl = config.get('confdUrl', "${artifactoryURL}/${projectNamespace}/confd/confd-${confdBuildId}")
Denis Egorenko8c606552016-12-07 14:22:50 +0400525
Artem Panchenkobc13d262017-01-20 12:40:58 +0200526 def birdBuildId = config.get('birdBuildId', "${artifactoryURL}/${projectNamespace}/bird/latest".toURL().text.trim())
527 def birdUrl = config.get('birdUrl', "${artifactoryURL}/${projectNamespace}/bird/bird-${birdBuildId}")
528 def bird6Url = config.get('bird6Url', "${artifactoryURL}/${projectNamespace}/bird/bird6-${birdBuildId}")
529 def birdclUrl = config.get('birdclUrl', "${artifactoryURL}/${projectNamespace}/bird/birdcl-${birdBuildId}")
Denis Egorenko8c606552016-12-07 14:22:50 +0400530
531 // add LABELs to dockerfiles
Denis Egorenko2bc89172016-12-21 17:31:19 +0400532 docker.setDockerfileLabels("./calicoctl/Dockerfile.calicoctl",
533 ["docker.imgTag=${imgTag}",
534 "calico.buildImage=${buildImage}",
535 "calico.birdclUrl=${birdclUrl}"])
Denis Egorenko8c606552016-12-07 14:22:50 +0400536
Denis Egorenko2bc89172016-12-21 17:31:19 +0400537 docker.setDockerfileLabels("./calico_node/Dockerfile",
538 ["docker.imgTag=${imgTag}",
539 "calico.buildImage=${buildImage}",
540 "calico.felixImage=${felixImage}",
541 "calico.confdUrl=${confdUrl}",
542 "calico.birdUrl=${birdUrl}",
543 "calico.bird6Url=${bird6Url}",
544 "calico.birdclUrl=${birdclUrl}"])
Denis Egorenko8c606552016-12-07 14:22:50 +0400545
546 // Start build section
547 stage ('Build calico/ctl image'){
548 sh """
549 make calico/ctl \
550 CTL_CONTAINER_NAME=${ctlName} \
551 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
552 BIRDCL_URL=${birdclUrl}
553 """
554 }
555
556
557 stage('Build calico/node'){
558 sh """
559 make calico/node \
560 NODE_CONTAINER_NAME=${nodeName} \
561 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
562 FELIX_CONTAINER_NAME=${felixImage} \
563 CONFD_URL=${confdUrl} \
564 BIRD_URL=${birdUrl} \
565 BIRD6_URL=${bird6Url} \
566 BIRDCL_URL=${birdclUrl}
567 """
568 }
569
570
571 return [
Artem Panchenkobc13d262017-01-20 12:40:58 +0200572 CTL_CONTAINER_NAME:"${ctlImage}",
573 NODE_CONTAINER_NAME:"${nodeImage}",
574 CALICO_NODE_IMAGE_REPO:"${nodeRepo}",
575 CALICOCTL_IMAGE_REPO:"${ctlRepo}",
Denis Egorenko8c606552016-12-07 14:22:50 +0400576 CALICO_VERSION: "${imgTag}"
577 ]
578
579}
Artem Panchenkobc13d262017-01-20 12:40:58 +0200580
581
582/**
583 * Test Calico CNI plugin stage
584 *
585 * Usage example:
586 *
587 * def calico = new com.mirantis.mcp.Calico()
588 * calico.testCniPlugin()
589 *
590 */
591def testCniPlugin() {
592 stage ('Run cni-plugin unittests'){
593 // 'static-checks-containerized' target is removed from master
594 // and kept here only for backward compatibility
595 sh "make static-checks || make static-checks-containerized"
596 sh "make stop-etcd stop-kubernetes-master"
597 // 'stop-k8s-apiserver' target doesn't exist in Calico v2.0.0,
598 // so do not fail the stage if it's not found
599 sh "make stop-k8s-apiserver || true"
600 sh "make test-containerized"
601 }
602}
603
604
605/**
606 * Build calico/cni image stage
607 *
608 * @param config LinkedHashMap
609 * config includes next parameters:
610 * - dockerRegistry String, Docker registry host to push image to (optional)
611 * - projectNamespace String, artifactory server namespace (optional)
612 * - cniImage String, calico/cni image name (optional)
613 * - cniImageTag String, tag of docker image (optional)
614 *
615 * Usage example:
616 *
617 * def calicoFunc = new com.mirantis.mcp.Calico()
618 * calicoFunc.buildFelix([
619 * dockerRegistry : 'sandbox-docker-dev-virtual.docker.mirantis.net',
620 * ])
621 *
622 */
623def buildCniPlugin(LinkedHashMap config) {
624
625 def common = new com.mirantis.mcp.Common()
626 def docker = new com.mirantis.mcp.Docker()
627 def git = new com.mirantis.mcp.Git()
628
629 def dockerRegistry = config.get('dockerRegistry')
630 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
631
632 def cniImage = config.get('cniImage', "calico/cni")
633 def cniImageTag = config.get('cniImageTag', git.getGitDescribe(true) + "-" + common.getDatetime())
634
635 def cniContainerName = dockerRegistry ? "${dockerRegistry}/${projectNamespace}/${cniImage}:${cniImageTag}" : "${cniImage}:${cniImageTag}"
636
637 stage ('Build calico/cni image') {
638 docker.setDockerfileLabels("./Dockerfile", ["docker.imgTag=${cniImageTag}"])
639 sh """
640 make docker-image
641 docker tag calico/cni ${cniContainerName}
642 """
643 }
644 return [cniImage : cniImage,
645 cniImageTag : cniImageTag]
646}
647
648
649/**
650 * Publish calico docker image stage
651 *
652 * @param config LinkedHashMap
653 * config includes next parameters:
654 * - artifactoryServerName String, artifactory server name
655 * - dockerRegistry String, Docker registry host to push image to
Sergey Kulanova9e65042017-01-31 14:20:24 +0200656 * - dockerRepo String, repository (artifactory) for docker images, must not be Virtual
Artem Panchenkobc13d262017-01-20 12:40:58 +0200657 * - imageName String, Docker image name
658 * - imageTag String, Docker image tag
659 * - projectNamespace String, artifactory server namespace (optional)
660 * - publishInfo Boolean, whether publish a build-info object to Artifactory (optional)
661 *
662 * Usage example:
663 *
664 * def calico = new com.mirantis.mcp.Calico()
665 * calico.publishCalicoImage([
666 * artifactoryServerName : 'mcp-ci',
667 * dockerRegistry : 'sandbox-docker-dev-local.docker.mirantis.net'
668 * dockerRepo : 'sandbox-docker-dev-local',
669 * imageName : 'calico/node',
670 * imageTag : 'v.1.0.0',
671 * ])
672 *
673 */
Sergey Kulanova9e65042017-01-31 14:20:24 +0200674def publishCalicoImage(LinkedHashMap config) {
Artem Panchenkobc13d262017-01-20 12:40:58 +0200675 def artifactory = new com.mirantis.mcp.MCPArtifactory()
676
677 def artifactoryServerName = config.get('artifactoryServerName')
678 def dockerRegistry = config.get('dockerRegistry')
679 def dockerRepo = config.get('dockerRepo')
680 def imageName = config.get('imageName')
681 def imageTag = config.get('imageTag')
682 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
683 def publishInfo = config.get('publishInfo', true)
684
685 if (!artifactoryServerName) {
686 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for publishCalicoImage() !")
687 }
688 if (!dockerRegistry) {
689 throw new RuntimeException("Parameter 'dockerRegistry' must be set for publishCalicoImage() !")
690 }
691 if (!dockerRepo) {
Sergey Kulanova9e65042017-01-31 14:20:24 +0200692 throw new RuntimeException("Parameter 'dockerRepo' must be set for publishCalicoImage() !")
Artem Panchenkobc13d262017-01-20 12:40:58 +0200693 }
694 if (!imageName) {
695 throw new RuntimeException("Parameter 'imageName' must be set for publishCalicoImage() !")
696 }
697 if (!imageTag) {
698 throw new RuntimeException("Parameter 'imageTag' must be set for publishCalicoImage() !")
699 }
700
701 def artifactoryServer = Artifactory.server(artifactoryServerName)
702 def buildInfo = publishInfo ? Artifactory.newBuildInfo() : null
703
704 stage("Publishing ${imageName}") {
705 artifactory.uploadImageToArtifactory(artifactoryServer,
706 dockerRegistry,
707 "${projectNamespace}/${imageName}",
708 imageTag,
709 dockerRepo,
710 buildInfo)
711 }
712 return "${dockerRegistry}/${projectNamespace}/${imageName}:${imageTag}"
713}
714
715
716/**
717 * Promote calico docker image stage
718 *
719 * @param config LinkedHashMap
720 * config includes next parameters:
721 * - imageProperties Map, docker image search properties in artifactory
722 * - artifactoryServerName String, artifactory server name
723 * - dockerLookupRepo String, docker repository (artifactory) to take image from
724 * - dockerPromoteRepo String, docker repository (artifactory) to promote image to
725 * - imageName String, Docker image name to promote with
726 * - imageTag String, Docker image tag to promote with
727 * - projectNamespace String, artifactory server namespace (optional)
728 * - defineLatest Boolean, promote with latest tag if true, default false (optional)
729 *
730 * Usage example:
731 *
732 * def calico = new com.mirantis.mcp.Calico()
733 * calico.promoteCalicoImage([
734 * imageProperties: [
735 * 'com.mirantis.targetImg': 'mirantis/projectcalico/calico/node',
736 * 'com.mirantis.targetTag': 'v1.0.0-2017010100000',
737 * ]
738 * artifactoryServerName : 'mcp-ci',
739 * dockerLookupRepo : 'sandbox-docker-dev-local',
740 * dockerPromoteRepo: 'sandbox-docker-prod-local',
741 * imageName: 'calico/node',
742 * imageTag: 'v1.0.0',
743 * defineLatest: true
744 * ])
745 *
746 */
747def promoteCalicoImage (LinkedHashMap config) {
748 def common = new com.mirantis.mcp.Common()
749 def git = new com.mirantis.mcp.Git()
750 def artifactory = new com.mirantis.mcp.MCPArtifactory()
751
752 def imageProperties = config.get('imageProperties')
753 def artifactoryServerName = config.get('artifactoryServerName')
754 def dockerLookupRepo = config.get('dockerLookupRepo')
755 def dockerPromoteRepo = config.get('dockerPromoteRepo')
756 def imageName = config.get('imageName')
757 def imageTag = config.get('imageTag')
758 def projectNamespace = config.get('projectNamespace', 'mirantis/projectcalico')
759 def defineLatest = config.get('defineLatest', false)
760
761if (!imageProperties) {
762 throw new RuntimeException("Parameter 'imageProperties' must be set for promoteCalicoImage() !")
763 }
764 if (!artifactoryServerName) {
765 throw new RuntimeException("Parameter 'artifactoryServerName' must be set for promoteCalicoImage() !")
766 }
767 if (!dockerLookupRepo) {
768 throw new RuntimeException("Parameter 'dockerLookupRepo' must be set for promoteCalicoImage() !")
769 }
770 if (!dockerPromoteRepo) {
771 throw new RuntimeException("Parameter 'dockerPromoteRepo' must be set for promoteCalicoImage() !")
772 }
773 if (!imageName) {
774 throw new RuntimeException("Parameter 'imageName' must be set for promoteCalicoImage() !")
775 }
776 if (!imageTag) {
777 throw new RuntimeException("Parameter 'imageTag' must be set for promoteCalicoImage() !")
778 }
779
780 def artifactoryServer = Artifactory.server(artifactoryServerName)
781 def artifactURI = artifactory.uriByProperties(artifactoryServer.getUrl(), imageProperties)
782
783 stage("Promote ${imageName}") {
784 if ( artifactURI ) {
785 def buildProperties = artifactory.getPropertiesForArtifact(artifactURI)
786 if (defineLatest) {
787 artifactory.promoteDockerArtifact(
788 artifactoryServer.getUrl(),
789 dockerLookupRepo,
790 dockerPromoteRepo,
791 "${projectNamespace}/${imageName}",
792 buildProperties.get('com.mirantis.targetTag').join(','),
793 'latest',
794 true
795 )
796 }
797 artifactory.promoteDockerArtifact(
798 artifactoryServer.getUrl(),
799 dockerLookupRepo,
800 dockerPromoteRepo,
801 "${projectNamespace}/${imageName}",
802 buildProperties.get('com.mirantis.targetTag').join(','),
803 "${imageTag}",
804 false
805 )
806 }
807 else {
808 throw new RuntimeException("Artifacts were not found, nothing to promote! "
809 +"Given image properties: ${imageProperties}")
810 }
811 }
812}
813
814
815def calicoFixOwnership() {
816 // files created inside container could be owned by root, fixing that
817 sh "sudo chown -R \$(id -u):\$(id -g) ${env.WORKSPACE} ${env.HOME}/.glide || true"
818}