blob: 55f76646618542caa10d36b3fb337a830414ae70 [file] [log] [blame]
Zsolt Haraszti2a792f62016-05-12 17:49:02 -07001/*
2 * Copyright 2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
David K. Bainbridge59bdb542016-07-01 11:07:45 -070016import org.opencord.gradle.rules.*
David K. Bainbridge10b0c112016-05-24 13:17:23 -070017import org.yaml.snakeyaml.Yaml
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070018
David K. Bainbridge59bdb542016-07-01 11:07:45 -070019allprojects {
20 apply plugin: 'base'
21 apply plugin: 'de.gesellix.docker'
22 //apply plugin: 'com.tmiyamon.config'
23
24 docker {
25 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
26 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
27 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
28 // authConfigPlain = [
29 // "username" : "joe",
30 // "password" : "some-pw-as-needed",
31 // "email" : "joe@acme.com",
32 // "serveraddress" : "https://index.docker.io/v1/"
33 // ]
34 }
35}
36
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070037ext {
38
David K. Bainbridge59bdb542016-07-01 11:07:45 -070039 // Upstream registry to simplify filling out the comps table below
40 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
41
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070042 // Target registry to be used to publish docker images needed for deployment
43 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
44
45 // The tag used to tag the docker images push to the target registry
46 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
47
David K. Bainbridge10b0c112016-05-24 13:17:23 -070048 // Deployment target config file (yaml format); this can be overwritten from the command line
49 // using the -PdeployConfig=<file-path> syntax.
50 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
David K. Bainbridge19b8d272016-05-26 21:20:43 -070051
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070052 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
David K. Bainbridge59bdb542016-07-01 11:07:45 -070053
54 comps = [
55 'consul': [
56 'type': 'image',
57 'upstream': upstreamReg,
58 'name': 'consul',
59 'digest': 'sha256:0dc990ff3c44d5b5395475bcc5ebdae4fc8b67f69e17942a8b9793b3df74d290'
60 ]
61 ]
62}
63
64task fetchUpstreamImages {
65 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070066}
67
David K. Bainbridge97ee8052016-06-14 00:52:07 -070068// Switch Configuration Image
69
70task buildSwitchqImage(type: Exec) {
71 commandLine "$dockerPath/docker", 'build', '-t', 'cord-maas-switchq', './switchq'
72}
73
74task tagSwitchqImage(type: Exec) {
75 dependsOn buildSwitchqImage
76 commandLine "$dockerPath/docker", 'tag', 'cord-maas-switchq', "$targetReg/cord-maas-switchq:$targetTag"
77}
78
79task publishSwitchqImage(type: Exec) {
80 dependsOn tagSwitchqImage
81 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-switchq:$targetTag"
82}
83
84// Bootstrap Image
85
David K. Bainbridgeb5415042016-05-13 17:06:10 -070086task buildBootstrapImage(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -070087 commandLine "$dockerPath/docker", 'build', '-t', 'cord-maas-bootstrap', './bootstrap'
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070088}
89
David K. Bainbridgeb5415042016-05-13 17:06:10 -070090task tagBootstrapImage(type: Exec) {
91 dependsOn buildBootstrapImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -070092 commandLine "$dockerPath/docker", 'tag', 'cord-maas-bootstrap', "$targetReg/cord-maas-bootstrap:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070093}
94
David K. Bainbridgeb5415042016-05-13 17:06:10 -070095task publishBootstrapImage(type: Exec) {
96 dependsOn tagBootstrapImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -070097 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-bootstrap:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070098}
99
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700100// IP Allocator Image
101
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700102task buildAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -0700103 commandLine "$dockerPath/docker", 'build', '-t', 'cord-ip-allocator', './ip-allocator'
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700104}
105
106task tagAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -0700107 dependsOn buildAllocationImage
108 commandLine "$dockerPath/docker", 'tag', 'cord-ip-allocator', "$targetReg/cord-ip-allocator:$targetTag"
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700109}
110
111task publishAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -0700112 dependsOn tagAllocationImage
113 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-ip-allocator:$targetTag"
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700114}
115
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700116// Provisioner Image
117
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700118task buildProvisionerImage(type: Exec) {
David K. Bainbridged86d96d2016-06-01 17:28:46 -0700119 commandLine "$dockerPath/docker", 'build', '-t', 'cord-provisioner', './provisioner'
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700120}
121
122task tagProvisionerImage(type: Exec) {
123 dependsOn buildProvisionerImage
124 commandLine "$dockerPath/docker", 'tag', 'cord-provisioner', "$targetReg/cord-provisioner:$targetTag"
125}
126
127task publishProvisionerImage(type: Exec) {
128 dependsOn tagProvisionerImage
129 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-provisioner:$targetTag"
130}
131
gunjan5e9bdd1d2016-07-13 14:59:33 -0700132// Config Generator Image
133
134task buildConfigGeneratorImage(type: Exec) {
135 commandLine "$dockerPath/docker", 'build', '-t', 'config-generator', './config-generator'
136}
137
138task tagConfigGeneratorImage(type: Exec) {
139 dependsOn buildConfigGeneratorImage
140 commandLine "$dockerPath/docker", 'tag', 'config-generator', "$targetReg/config-generator:$targetTag"
141}
142
143task publishConfigGeneratorImage(type: Exec) {
144 dependsOn tagConfigGeneratorImage
145 commandLine "$dockerPath/docker", 'push', "$targetReg/config-generator:$targetTag"
146}
147
David K. Bainbridge9d1e02d2016-06-22 09:22:16 -0700148// Automation Image
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700149
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700150task buildAutomationImage(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700151 commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700152}
153
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700154task tagAutomationImage(type: Exec) {
155 dependsOn buildAutomationImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700156 commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation', "$targetReg/cord-maas-automation:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700157}
158
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700159task publishAutomationImage(type: Exec) {
160 dependsOn tagAutomationImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700161 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700162}
163
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700164// DHCP Harvester Images
165
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700166task buildHarvesterImage(type: Exec) {
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700167 commandLine "$dockerPath/docker", 'build', '-t', "cord-dhcp-harvester", "./harvester"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700168}
169
170task tagHarvesterImage(type: Exec) {
171 dependsOn buildHarvesterImage
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700172 commandLine "$dockerPath/docker", 'tag', 'cord-dhcp-harvester', "$targetReg/cord-dhcp-harvester:$targetTag"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700173}
174
175task publishHarvesterImage(type: Exec) {
176 dependsOn tagHarvesterImage
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700177 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-dhcp-harvester:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700178}
179
180// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
181
alshabib462f6252016-08-29 16:15:28 -0700182task updateDocker (type: Exec) {
David K. Bainbridge59bdb542016-07-01 11:07:45 -0700183 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
184}
185
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700186// To be used to fetch upstream binaries, clone repos, etc.
187task fetch(type: Exec) {
188 // this is where we fetch upstream artifacts that we do not need internet for the build phase"
189 // Placeholdr example:
David K. Bainbridge59bdb542016-07-01 11:07:45 -0700190 dependsOn fetchUpstreamImages
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700191 commandLine "$dockerPath/docker", "pull", "golang:alpine"
192 commandLine "$dockerPath/docker", "pull", "python:2.7-alpine"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700193}
194
195// To be used to generate all needed binaries that need to be present on the target
196// as docker images in the local docker runner.
197task buildImages {
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700198 dependsOn buildBootstrapImage
199 dependsOn buildHarvesterImage
David K. Bainbridge9d1e02d2016-06-22 09:22:16 -0700200 dependsOn buildAutomationImage
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700201 dependsOn buildAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700202 dependsOn buildProvisionerImage
gunjan5e9bdd1d2016-07-13 14:59:33 -0700203 dependsOn buildConfigGeneratorImage
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700204 dependsOn buildSwitchqImage
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700205}
206
207task tagImages {
208 dependsOn tagBootstrapImage
209 dependsOn tagHarvesterImage
David K. Bainbridge9d1e02d2016-06-22 09:22:16 -0700210 dependsOn tagAutomationImage
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700211 dependsOn tagAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700212 dependsOn tagProvisionerImage
gunjan5e9bdd1d2016-07-13 14:59:33 -0700213 dependsOn tagConfigGeneratorImage
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700214 dependsOn tagSwitchqImage
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700215}
216
217task publish {
alshabib462f6252016-08-29 16:15:28 -0700218 //FIXME: This works because the upstream project primes the nodes before running this.
David K. Bainbridge59bdb542016-07-01 11:07:45 -0700219 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700220 dependsOn publishBootstrapImage
221 dependsOn publishHarvesterImage
David K. Bainbridge9d1e02d2016-06-22 09:22:16 -0700222 dependsOn publishAutomationImage
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700223 dependsOn publishAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700224 dependsOn publishProvisionerImage
gunjan5e9bdd1d2016-07-13 14:59:33 -0700225 dependsOn publishConfigGeneratorImage
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700226 dependsOn publishSwitchqImage
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700227}
228
David K. Bainbridge59bdb542016-07-01 11:07:45 -0700229
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700230// ~~~~~~~~~~~~~~~~~~~ Deployment / Test Tasks ~~~~~~~~~~~~~~~~~~~~~~~
231
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700232List.metaClass.asParam = { prefix, sep ->
233 if (delegate.size() == 0) {
234 ""
235 }
236 String result = "--" + prefix + "="
237 String p = ""
238 delegate.each {
239 result += p + "${it}"
240 p = sep
241 }
242 result
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700243}
244
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700245List.metaClass.p = { value, name ->
246 if (value != null && value != "") {
247 delegate << name + "=" + value
248 } else {
249 delegate
250 }
251}
252
253List.metaClass.p = { spec ->
254 if (spec != null && spec != "") {
255 delegate += spec
256 } else {
257 delegate
258 }
259}
260
alshabib462f6252016-08-29 16:15:28 -0700261task prime (type: Exec) {
David K. Bainbridgef4181702016-06-17 14:44:03 -0700262 println "Using deployment config: $deployConfig"
263 File configFile = new File(deployConfig)
264 def yaml = new Yaml()
265 def config = yaml.load(configFile.newReader())
266
267 executable = "ansible-playbook"
268 args = ["-i", config.seedServer.ip + ',']
269
270 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
271 args = args << "--user=$config.seedServer.user"
272 }
273
David K. Bainbridge5ba01a92016-08-16 14:58:31 -0700274 if ( config.debug ) {
275 args = args << "-vvvv"
276 }
277
David K. Bainbridgef4181702016-06-17 14:44:03 -0700278 def extraVars = []
279 if (config.seedServer) {
280 extraVars = extraVars.p(config.seedServer.extraVars)
281 .p(config.seedServer.password, "ansible_ssh_pass")
282 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
283 .p(config.seedServer.fabric_ip, "fabric_ip")
284 .p(config.seedServer.management_ip, "management_ip")
David K. Bainbridgee80fd392016-08-19 15:46:19 -0700285 .p(config.seedServer.management_gw, "management_gw")
David K. Bainbridgef4181702016-06-17 14:44:03 -0700286 .p(config.seedServer.management_network, "management_network")
287 .p(config.seedServer.management_iface, "management_iface")
288 .p(config.seedServer.external_ip, "external_ip")
David K. Bainbridgee80fd392016-08-19 15:46:19 -0700289 .p(config.seedServer.external_gw, "external_gw")
David K. Bainbridgef4181702016-06-17 14:44:03 -0700290 .p(config.seedServer.external_network, "external_network")
291 .p(config.seedServer.external_iface, "external_iface")
292 .p(config.seedServer.fabric_ip, "fabric_ip")
293 .p(config.seedServer.fabric_network, "fabric_network")
294 .p(config.seedServer.fabric_iface, "fabric_iface")
David K. Bainbridgede51ce52016-08-22 13:54:24 -0700295 .p(config.seedServer.fabric_iface_spec, "fabric_iface_spec")
David K. Bainbridgef4181702016-06-17 14:44:03 -0700296 .p(config.seedServer.domain, "domain")
David K. Bainbridgebe58a0d2016-06-22 15:43:02 -0700297 .p(config.seedServer.virtualbox_support, "virtualbox_support")
298 .p(config.seedServer.power_helper_user, "power_helper_user")
299 .p(config.seedServer.power_helper_host, "power_helper_host")
300 .p(config.seedServer.port, "ansible_ssh_port")
David K. Bainbridgef4181702016-06-17 14:44:03 -0700301 }
302
303 if (config.otherServers) {
304 extraVars = extraVars.p(config.otherServers.location, "prov_location")
305 .p(config.otherServers.rolesPath, "prov_role_path")
306 .p(config.otherServers.role, "prov_role")
307 }
308
309 if (config.docker) {
310 extraVars = extraVars.p(config.docker.registry, "docker_registry")
311 .p(config.docker.imageVersion, "docker_image_version")
312 }
313
314 def skipTags = [].p(config.seedServer.skipTags)
315
316 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "prime-node.yml"
317}
318
alshabib462f6252016-08-29 16:15:28 -0700319task deployBase(type: Exec) {
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700320 println "Using deployment config: $deployConfig"
321 File configFile = new File(deployConfig)
322 def yaml = new Yaml()
323 def config = yaml.load(configFile.newReader())
324
325 executable = "ansible-playbook"
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700326 args = ["-i", config.seedServer.ip + ',']
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700327
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700328 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
329 args = args << "--user=$config.seedServer.user"
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700330 }
331
David K. Bainbridge5ba01a92016-08-16 14:58:31 -0700332
333 if ( config.debug ) {
334 args = args << "-vvvv"
335 }
336
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700337 def extraVars = []
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700338 if (config.seedServer) {
339 extraVars = extraVars.p(config.seedServer.extraVars)
340 .p(config.seedServer.password, "ansible_ssh_pass")
341 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
342 .p(config.seedServer.fabric_ip, "fabric_ip")
343 .p(config.seedServer.management_ip, "management_ip")
David K. Bainbridgee80fd392016-08-19 15:46:19 -0700344 .p(config.seedServer.management_gw, "management_gw")
David K. Bainbridgec82a4462016-06-14 12:39:01 -0700345 .p(config.seedServer.management_network, "management_network")
346 .p(config.seedServer.management_iface, "management_iface")
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700347 .p(config.seedServer.external_ip, "external_ip")
David K. Bainbridgee80fd392016-08-19 15:46:19 -0700348 .p(config.seedServer.external_gw, "external_gw")
David K. Bainbridgec82a4462016-06-14 12:39:01 -0700349 .p(config.seedServer.external_network, "external_network")
350 .p(config.seedServer.external_iface, "external_iface")
351 .p(config.seedServer.fabric_ip, "fabric_ip")
352 .p(config.seedServer.fabric_network, "fabric_network")
353 .p(config.seedServer.fabric_iface, "fabric_iface")
David K. Bainbridgede51ce52016-08-22 13:54:24 -0700354 .p(config.seedServer.fabric_iface_spec, "fabric_iface_spec")
David K. Bainbridgec82a4462016-06-14 12:39:01 -0700355 .p(config.seedServer.domain, "domain")
David K. Bainbridgebe58a0d2016-06-22 15:43:02 -0700356 .p(config.seedServer.virtualbox_support, "virtualbox_support")
David K. Bainbridgec82a4462016-06-14 12:39:01 -0700357 .p(config.seedServer.power_helper_user, "power_helper_user")
358 .p(config.seedServer.power_helper_host, "power_helper_host")
David K. Bainbridgebe58a0d2016-06-22 15:43:02 -0700359 .p(config.seedServer.port, "ansible_ssh_port")
David K. Bainbridge6ea57c12016-06-06 23:29:12 -0700360 }
361
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700362 if (config.otherServers) {
363 extraVars = extraVars.p(config.otherServers.location, "prov_location")
364 .p(config.otherServers.rolesPath, "prov_role_path")
365 .p(config.otherServers.role, "prov_role")
366 }
367
David K. Bainbridge97ee8052016-06-14 00:52:07 -0700368 if (config.docker) {
369 extraVars = extraVars.p(config.docker.registry, "docker_registry")
370 .p(config.docker.imageVersion, "docker_image_version")
371 }
372
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700373 def skipTags = [].p(config.seedServer.skipTags)
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700374
375 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "head-node.yml"
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700376}
alshabib462f6252016-08-29 16:15:28 -0700377
378prime.dependsOn {
379 updateDocker
380}
381
382tasks.addRule(new DockerFetchRule(project))
383tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
384tasks.addRule(new DockerTagRule(project))
385
386