blob: eaa3360eae78bc7056645d1b7207fdeb8d85b620 [file] [log] [blame]
Denis Egorenko8c606552016-12-07 14:22:50 +04001package com.mirantis.mcp
2
3/**
4 * Build Calico containers
5 *
6 * @param body Closure
7 * body includes next parameters:
8 * - dockerRepo String, repo with docker images
9 * - artifactoryUrl String, URL to repo with calico-binaries
10 * - imageTag String, tag of images
11 * - nodeImage String, Calico Node image name
12 * - ctlImage String, Calico CTL image name
13 * - buildImage String, Calico Build image name
14 * - felixImage String, Calico Felix image name
15 * - confdBuildId String, Version of Calico Confd
16 * - confdUrl String, URL to Calico Confd
17 * - birdUrl, URL to Calico Bird
18 * - birdBuildId, Version of Calico Bird
19 * - bird6Url, URL to Calico Bird6
20 * - birdclUrl, URL to Calico BirdCL
21 *
22 * Usage example:
23 *
24 * def calicoFunc = new com.mirantis.mcp.Calico()
25 * calicoFunc.buildCalicoContainers {
26 * dockerRepo = 'mcp-k8s-ci.docker.mirantis.net'
27 * artifactoryURL = 'https://artifactory.mcp.mirantis.net/artifactory/sandbox'
28 * nodeImage = 'mcp-k8s-ci.docker.mirantis.net/calico/node'
29 * ctlImage = 'mcp-k8s-ci.docker.mirantis.net/calico/ctl'
30 * }
31 *
32 */
33def buildCalicoContainers = { body ->
34 // evaluate the body block, and collect configuration into the object
35 def config = [:]
36 body.resolveStrategy = Closure.DELEGATE_FIRST
37 body.delegate = config
38 body()
39
40
41 def dockerRepo = config.dockerRepo
42 def projectNamespace = "mirantis/projectcalico"
43 def artifactoryUrl = config.artifactoryURL
44
45 if (! dockerRepo ) {
46 error('dockerRepo parameter have to be set.')
47 }
48
49 if (! artifactoryUrl ) {
50 error('artifactoryUrl parameter have to be set.')
51 }
52
53 def imgTag = config.imageTag ?: getGitDescribe(true) + "-" + getDatetime()
54
55 def nodeImage = config.nodeImage ?: "${dockerRepo}/${projectNamespace}/calico/node"
56 def nodeName = "${nodeImage}:${imgTag}"
57
58 def ctlImage = config.ctlImage ?: "${dockerRepo}/${projectNamespace}/calico/ctl"
59 def ctlName = "${ctlImage}:${imgTag}"
60
61 // calico/build goes from libcalico
62 def buildImage = config.buildImage ?: "${dockerRepo}/${projectNamespace}/calico/build:latest"
63 // calico/felix goes from felix
64 def felixImage = config.felixImage ?: "${dockerRepo}/${projectNamespace}/calico/felix:latest"
65
66 def confdBuildId = config.confdBuildId ?: "${artifactoryUrl}/${projectNamespace}/confd/latest".toURL().text.trim()
67 def confdUrl = config.confdUrl ?: "${artifactoryUrl}/${projectNamespace}/confd/confd-${confdBuildId}"
68
69 def birdBuildId = config.birdBuildId ?: "${artifactoryUrl}/${projectNamespace}/bird/latest".toURL().text.trim()
70 def birdUrl = config.birdUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/bird-${birdBuildId}"
71 def bird6Url = config.bird6Url ?: "${artifactoryUrl}/${projectNamespace}/bird/bird6-${birdBuildId}"
72 def birdclUrl = config.birdclUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/birdcl-${birdBuildId}"
73
74 // add LABELs to dockerfiles
75 setDockerfileLabels("./calicoctl/Dockerfile.calicoctl",
76 ["docker.imgTag=${imgTag}",
77 "calico.buildImage=${buildImage}",
78 "calico.birdclUrl=${birdclUrl}"])
79
80 setDockerfileLabels("./calico_node/Dockerfile",
81 ["docker.imgTag=${imgTag}",
82 "calico.buildImage=${buildImage}",
83 "calico.felixImage=${felixImage}",
84 "calico.confdUrl=${confdUrl}",
85 "calico.birdUrl=${birdUrl}",
86 "calico.bird6Url=${bird6Url}",
87 "calico.birdclUrl=${birdclUrl}"])
88
89 // Start build section
90 stage ('Build calico/ctl image'){
91 sh """
92 make calico/ctl \
93 CTL_CONTAINER_NAME=${ctlName} \
94 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
95 BIRDCL_URL=${birdclUrl}
96 """
97 }
98
99
100 stage('Build calico/node'){
101 sh """
102 make calico/node \
103 NODE_CONTAINER_NAME=${nodeName} \
104 PYTHON_BUILD_CONTAINER_NAME=${buildImage} \
105 FELIX_CONTAINER_NAME=${felixImage} \
106 CONFD_URL=${confdUrl} \
107 BIRD_URL=${birdUrl} \
108 BIRD6_URL=${bird6Url} \
109 BIRDCL_URL=${birdclUrl}
110 """
111 }
112
113
114 return [
115 CTL_CONTAINER_NAME:"${ctlName}",
116 NODE_CONTAINER_NAME:"${nodeName}",
117 CALICO_NODE_IMAGE_REPO:"${nodeImage}",
118 CALICOCTL_IMAGE_REPO:"${ctlImage}",
119 CALICO_VERSION: "${imgTag}"
120 ]
121
122}