blob: aa79e60cd3f41186d84f4f27227c97c963c269ab [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
8 // we need to use Tools library for getting mandatory binary properties
9 def tools = new ci.mcp.Tools()
10
11 def server = Artifactory.server(config.artifactoryServerId ?: "mcp-ci")
12 def buildInfo = Artifactory.newBuildInfo()
13 buildInfo.env.capture = true
14 buildInfo.env.filter.addInclude("*")
15 buildInfo.env.collect()
16
17 def dockerRepo = config.dockerRepo ?: "artifactory.mcp.mirantis.net:5001"
18 def artifactoryURL = config.artifactoryURL ?: "https://artifactory.mcp.mirantis.net/artifactory/projectcalico"
19
20 def nodeImage = config.nodeImage ?: "calico/node"
21 def nodeImageTag = config.nodeImageTag ?: "v0.20.0"
22 def nodeName = "${dockerRepo}/${nodeImage}:${nodeImageTag}"
23
24 def ctlImage = config.ctlImage ?: "calico/ctl"
25 def ctlImageTag = config.ctlImageTag ?: "v0.20.0"
26 def ctlName = "${dockerRepo}/${ctlImage}:${ctlImageTag}"
27
28 // calico/build goes from {artifactoryURL}/mcp/libcalico/
29 def buildImage = config.buildImage ?: "${artifactoryURL}/mcp/libcalico/lastbuild".toURL().text.trim()
30 // calico/felix goes from {artifactoryURL}/mcp/felix/
31 def felixImage = config.felixImage ?: "${artifactoryURL}/mcp/felix/lastbuild".toURL().text.trim()
32
33 def confdBuildId = config.confdBuildId ?: "${artifactoryURL}/mcp/confd/lastbuild".toURL().text.trim()
34 def confdUrl = config.confdUrl ?: "${artifactoryURL}/mcp/confd/confd-${confdBuildId}"
35
36 def birdBuildId = config.birdBuildId ?: "${artifactoryURL}/mcp/calico-bird/lastbuild".toURL().text.trim()
37 def birdUrl = config.birdUrl ?: "${artifactoryURL}/mcp/calico-bird/bird-${birdBuildId}"
38 def bird6Url = config.bird6Url ?: "${artifactoryURL}/mcp/calico-bird/bird6-${birdBuildId}"
39 def birdclUrl = config.birdclUrl ?: "${artifactoryURL}/mcp/calico-bird/birdcl-${birdBuildId}"
40
41 def gitCommit = sh(returnStdout: true, script: "git -C ${WORKSPACE} rev-parse --short HEAD").trim()
42
43 def build = "${config.containersBuildId}-${gitCommit}"
44
45 // return values
46 def calicoNodeImageRepo="${dockerRepo}/${nodeImage}"
47 def calicoCtlImageRepo="${dockerRepo}/${ctlImage}"
48 def calicoVersion="${nodeImageTag}-${build}"
49
50 // Start build section
51
52 stage ('Build calico/ctl image'){
53 sh """
54 make ctl_image \
55 CTL_CONTAINER_NAME=${ctlName}-${build} \
56 BUILD_CONTAINER_NAME=${buildImage} \
57 BIRDCL_URL=${birdclUrl}
58 """
59 }
60
61
62 stage('Build calico/node'){
63 sh """
64 make node_image \
65 NODE_CONTAINER_NAME=${nodeName}-${build} \
66 BUILD_CONTAINER_NAME=${buildImage} \
67 FELIX_CONTAINER_NAME=${felixImage} \
68 CONFD_URL=${confdUrl} \
69 BIRD_URL=${birdUrl} \
70 BIRD6_URL=${bird6Url} \
71 BIRDCL_URL=${birdclUrl}
72 """
73 }
74
75
76 stage('Publishing containers artifacts'){
77
78 withCredentials([
79 [$class: 'UsernamePasswordMultiBinding',
80 credentialsId: "${config.credentialsId}",
81 passwordVariable: 'ARTIFACTORY_PASSWORD',
82 usernameVariable: 'ARTIFACTORY_LOGIN']
83 ]) {
84 sh """
85 echo 'Pushing images'
86 docker login -u ${ARTIFACTORY_LOGIN} -p ${ARTIFACTORY_PASSWORD} ${dockerRepo}
87 docker push ${nodeName}-${build}
88 docker push ${ctlName}-${build}
89 """
90 }
91
92 dir("artifacts"){
93 // Save the last build ID
94 writeFile file: "lastbuild", text: "${build}"
95 // Create config yaml for Kargo
96 writeFile file: "calico-containers-${build}.yaml",
97 text: """\
98 calico_node_image_repo: ${calicoNodeImageRepo}
99 calicoctl_image_repo: ${calicoCtlImageRepo}
100 calico_version: ${calicoVersion}
101 """.stripIndent()
102 // Create the upload spec.
103 def properties = tools.getBinaryBuildProperties()
104 def uploadSpec = """{
105 "files": [
106 {
107 "pattern": "**",
108 "target": "projectcalico/${config.containersBuildId}/calico-containers/",
109 "props": "${properties}"
110 }
111 ]
112 }"""
113 // Upload to Artifactory.
114 server.upload(uploadSpec, buildInfo)
115 server.publishBuildInfo buildInfo
116
117 } // dir artifacts
118 } //stage
119
120 return [
121 CALICO_NODE_IMAGE_REPO:"${calicoNodeImageRepo}",
122 CALICOCTL_IMAGE_REPO:"${calicoCtlImageRepo}",
123 CALICO_VERSION: "${calicoVersion}"
124 ]
125
126}