blob: 8b08b7693a9b4c9f5610117a175e55e126b51cfd [file] [log] [blame]
Sergey Kulanov247c4e72016-10-17 16:43:29 +03001def call(body) {
2 // evaluate the body block, and collect configuration into the object
3 def config = [:]
4 body.resolveStrategy = Closure.DELEGATE_FIRST
5 body.delegate = config
6 body()
7
Sergey Kulanov247c4e72016-10-17 16:43:29 +03008
9 def dockerRepo = config.dockerRepo ?: "artifactory.mcp.mirantis.net:5001"
Sergey Kulanov2202ad22016-10-18 17:14:12 +030010 def artifactoryUrl = config.artifactoryURL ?: "https://artifactory.mcp.mirantis.net/artifactory/projectcalico"
Sergey Kulanov247c4e72016-10-17 16:43:29 +030011
12 def nodeImage = config.nodeImage ?: "calico/node"
13 def nodeImageTag = config.nodeImageTag ?: "v0.20.0"
14 def nodeName = "${dockerRepo}/${nodeImage}:${nodeImageTag}"
15
16 def ctlImage = config.ctlImage ?: "calico/ctl"
17 def ctlImageTag = config.ctlImageTag ?: "v0.20.0"
18 def ctlName = "${dockerRepo}/${ctlImage}:${ctlImageTag}"
19
Sergey Kulanov2202ad22016-10-18 17:14:12 +030020 // calico/build goes from {artifactoryUrl}/mcp/libcalico/
21 def buildImage = config.buildImage ?: "${artifactoryUrl}/mcp/libcalico/lastbuild".toURL().text.trim()
22 // calico/felix goes from {artifactoryUrl}/mcp/felix/
23 def felixImage = config.felixImage ?: "${artifactoryUrl}/mcp/felix/lastbuild".toURL().text.trim()
Sergey Kulanov247c4e72016-10-17 16:43:29 +030024
Sergey Kulanov2202ad22016-10-18 17:14:12 +030025 def confdBuildId = config.confdBuildId ?: "${artifactoryUrl}/mcp/confd/lastbuild".toURL().text.trim()
26 def confdUrl = config.confdUrl ?: "${artifactoryUrl}/mcp/confd/confd-${confdBuildId}"
Sergey Kulanov247c4e72016-10-17 16:43:29 +030027
Sergey Kulanov2202ad22016-10-18 17:14:12 +030028 def birdBuildId = config.birdBuildId ?: "${artifactoryUrl}/mcp/calico-bird/lastbuild".toURL().text.trim()
29 def birdUrl = config.birdUrl ?: "${artifactoryUrl}/mcp/calico-bird/bird-${birdBuildId}"
30 def bird6Url = config.bird6Url ?: "${artifactoryUrl}/mcp/calico-bird/bird6-${birdBuildId}"
31 def birdclUrl = config.birdclUrl ?: "${artifactoryUrl}/mcp/calico-bird/birdcl-${birdBuildId}"
Sergey Kulanov247c4e72016-10-17 16:43:29 +030032
Sergey Kulanov00d74342016-10-24 15:22:11 +030033 def gitCommit = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim()
Sergey Kulanov247c4e72016-10-17 16:43:29 +030034
35 def build = "${config.containersBuildId}-${gitCommit}"
36
37 // return values
Sergey Kulanov2202ad22016-10-18 17:14:12 +030038 def calicoNodeImageRepo = "${dockerRepo}/${nodeImage}"
39 def calicoCtlImageRepo = "${dockerRepo}/${ctlImage}"
40 def calicoVersion = "${nodeImageTag}-${build}"
41 def ctlContainerName = "${ctlName}-${build}"
42 def nodeContainerName = "${nodeName}-${build}"
Sergey Kulanov247c4e72016-10-17 16:43:29 +030043
44 // Start build section
45
46 stage ('Build calico/ctl image'){
47 sh """
48 make ctl_image \
Sergey Kulanov2202ad22016-10-18 17:14:12 +030049 CTL_CONTAINER_NAME=${ctlContainerName} \
Sergey Kulanov247c4e72016-10-17 16:43:29 +030050 BUILD_CONTAINER_NAME=${buildImage} \
51 BIRDCL_URL=${birdclUrl}
52 """
53 }
54
Sergey Kulanov00a84f62016-10-31 14:36:18 +020055 // libcalico project should be already checkouted to
56 // calico_node/node_share/libcalico
Sergey Kulanov165f3d52016-11-03 16:19:33 +020057
58 // (skulanov): Fix when upstream will be merged
59 // https://github.com/projectcalico/calico-containers/pull/1250
60 // but for now let's use `make calico_node/.calico_node.created`
Sergey Kulanov247c4e72016-10-17 16:43:29 +030061 stage('Build calico/node'){
62 sh """
Sergey Kulanov165f3d52016-11-03 16:19:33 +020063 make calico_node/.calico_node.created \
Sergey Kulanov2202ad22016-10-18 17:14:12 +030064 NODE_CONTAINER_NAME=${nodeContainerName} \
Sergey Kulanov00a84f62016-10-31 14:36:18 +020065 NODE_CONTAINER_BUILD_ARGS='\
66 --build-arg LIBCALICO_REPO=file:///tmp/node_share/libcalico \
67 --build-arg LIBCALICO_VER=mcp' \
Sergey Kulanov247c4e72016-10-17 16:43:29 +030068 BUILD_CONTAINER_NAME=${buildImage} \
69 FELIX_CONTAINER_NAME=${felixImage} \
70 CONFD_URL=${confdUrl} \
71 BIRD_URL=${birdUrl} \
72 BIRD6_URL=${bird6Url} \
73 BIRDCL_URL=${birdclUrl}
74 """
75 }
76
77
Sergey Kulanov2202ad22016-10-18 17:14:12 +030078 dir("artifacts"){
79 // Save the last build ID
80 writeFile file: "lastbuild", text: "${build}"
81 // Create config yaml for Kargo
82 writeFile file: "calico-containers-${build}.yaml",
83 text: """\
84 calico_node_image_repo: ${calicoNodeImageRepo}
85 calicoctl_image_repo: ${calicoCtlImageRepo}
86 calico_version: ${calicoVersion}
87 """.stripIndent()
88 } // dir artifacts
Sergey Kulanov247c4e72016-10-17 16:43:29 +030089
90 return [
Sergey Kulanov2202ad22016-10-18 17:14:12 +030091 CTL_CONTAINER_NAME:"${ctlContainerName}",
92 NODE_CONTAINER_NAME:"${nodeContainerName}",
Sergey Kulanov247c4e72016-10-17 16:43:29 +030093 CALICO_NODE_IMAGE_REPO:"${calicoNodeImageRepo}",
94 CALICOCTL_IMAGE_REPO:"${calicoCtlImageRepo}",
95 CALICO_VERSION: "${calicoVersion}"
96 ]
97
98}