blob: 97259c490b8d0de52da86d2382281856c7dca4d2 [file] [log] [blame]
Andy Bavieradea0fd2016-07-06 05:26:26 -04001/*
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 */
16
17import org.opencord.gradle.rules.*
18import org.yaml.snakeyaml.Yaml
19
20allprojects {
21 apply plugin: 'base'
22 apply plugin: 'de.gesellix.docker'
23 //apply plugin: 'com.tmiyamon.config'
24
25 docker {
26 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
27 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
28 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
29 // authConfigPlain = [
30 // "username" : "joe",
31 // "password" : "some-pw-as-needed",
32 // "email" : "joe@acme.com",
33 // "serveraddress" : "https://index.docker.io/v1/"
34 // ]
35 }
36}
37
Andy Bavier829bc002017-01-11 14:59:48 -050038def getCordAppVersion = { ->
39 def StdOut = new ByteArrayOutputStream()
40 exec {
41 commandLine "xpath", "-q", "-e", "project/version/text()", "../../onos-apps/apps/pom.xml"
42 standardOutput = StdOut
43 }
44 return StdOut.toString().trim()
45}
46
Andy Bavieradea0fd2016-07-06 05:26:26 -040047ext {
48
49 // Upstream registry to simplify filling out the comps table below
50 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
51
Andy Bavieradea0fd2016-07-06 05:26:26 -040052 // Deployment target config file (yaml format); this can be overwritten from the command line
53 // using the -PdeployConfig=<file-path> syntax.
54 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
55
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080056 println "Using deployment config: $deployConfig"
57 File configFile = new File(deployConfig)
58 def yaml = new Yaml()
59 config = yaml.load(configFile.newReader())
60
61
62 // Target registry to be used to publish docker images needed for deployment
63 targetReg = project.hasProperty('targetReg')
64 ? project.getProperty('targetReg')
65 : config.docker && config.docker.registry
66 ? config.docker.registry
David K. Bainbridge94b24712016-11-15 15:09:42 -080067 : config.seedServer.ip
68 ? config.seedServer.ip + ":5000"
69 : 'localhost:5000'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080070
71 // The tag used to tag the docker images push to the target registry
72 targetTag = project.hasProperty('targetTag')
73 ? project.getProperty('targetTag')
74 : config.docker && config.docker.imageVersion
75 ? config.docker.imageVersion
Andy Bavier12262e72016-12-02 11:36:57 -050076 : 'candidate'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080077
78 println "targetReg = $targetReg, targetTag = $targetTag"
79
Andy Bavier829bc002017-01-11 14:59:48 -050080
81 // Version of the CORD apps to load into ONOS
82 cordAppVersion = project.hasProperty('cordAppVersion')
83 ? project.getProperty('cordAppVersion')
84 : getCordAppVersion()
85
86 println "CORD app version: $cordAppVersion"
87
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080088 // Component table
89 comps = [
90 ]
Andy Bavieradea0fd2016-07-06 05:26:26 -040091}
92
Andy Bavier6dbb1a32016-07-06 07:12:50 -040093task copyAnsibleInventory(type: Copy) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -040094 from 'inventory/templates/single-prod'
95 into 'inventory'
96 expand([
97 prod: config.seedServer.ip,
98 ])
99}
100
Andy Bavieradea0fd2016-07-06 05:26:26 -0400101// ------------- PlaceHolders ----------------
102
103task updateDocker (type: Exec) {
104 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
105}
106
107task prime {
108 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400109 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -0400110}
111
112// ---------------- Useful tasks ----------------
113
Andy Bavier1b8a5372016-07-07 19:36:21 -0400114List.metaClass.asParam = { prefix, sep ->
115 if (delegate.size() == 0) {
116 ""
117 }
118 String result = "--" + prefix + "="
119 String p = ""
120 delegate.each {
121 result += p + "${it}"
122 p = sep
123 }
124 result
125}
126
127List.metaClass.p = { value, name ->
128 if (value != null && value != "") {
129 delegate << name + "=" + value
130 } else {
131 delegate
132 }
133}
134
135List.metaClass.p = { spec ->
136 if (spec != null && spec != "") {
137 delegate += spec
138 } else {
139 delegate
140 }
141}
142
alshabibfe09d772016-08-29 16:15:56 -0700143task fetch << {
144 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400145}
146
alshabibfe09d772016-08-29 16:15:56 -0700147task buildImages << {
148 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400149}
150
151task publishImages {
152 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
153}
154
155task publish {
156 dependsOn publishImages
157}
158
159tasks.addRule(new DockerFetchRule(project))
160tasks.addRule(new DockerPublishRule(project))
161tasks.addRule(new DockerTagRule(project))
162tasks.addRule(new GitSubmoduleUpdateRule(project))
163
Andy Bavier12262e72016-12-02 11:36:57 -0500164task prepPlatform(type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400165 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400166
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400167 executable = "ansible-playbook"
168 args = ["-i", "inventory/single-prod"]
169
170 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
171 args = args << "--user=$config.seedServer.user"
172 }
173
174 def extraVars = []
175 if (config.seedServer) {
176 extraVars = extraVars.p(config.seedServer.extraVars)
177 .p(config.seedServer.password, "ansible_ssh_pass")
178 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
179 .p(config.seedServer.fabric_ip, "fabric_ip")
180 .p(config.seedServer.management_ip, "management_ip")
181 .p(config.seedServer.management_network, "management_network")
182 .p(config.seedServer.management_iface, "management_iface")
183 .p(config.seedServer.external_ip, "external_ip")
184 .p(config.seedServer.external_network, "external_network")
185 .p(config.seedServer.external_iface, "external_iface")
186 .p(config.seedServer.fabric_ip, "fabric_ip")
187 .p(config.seedServer.fabric_network, "fabric_network")
188 .p(config.seedServer.fabric_iface, "fabric_iface")
189 .p(config.seedServer.domain, "domain")
190 .p(config.seedServer.virtualbox_support, "virtualbox_support")
191 .p(config.seedServer.power_helper_user, "power_helper_user")
192 .p(config.seedServer.power_helper_host, "power_helper_host")
193 .p(config.seedServer.port, "ansible_ssh_port")
194 }
195
196 if (config.otherServers) {
197 extraVars = extraVars.p(config.otherServers.location, "prov_location")
198 .p(config.otherServers.rolesPath, "prov_role_path")
199 .p(config.otherServers.role, "prov_role")
200 }
201
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800202 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
203 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500204 .p("$cordAppVersion", "cord_app_version")
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400205
206 def skipTags = [].p(config.seedServer.skipTags)
207
Andy Bavier12262e72016-12-02 11:36:57 -0500208 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-prep-platform.yml"
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400209}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400210
Andy Bavier12262e72016-12-02 11:36:57 -0500211task deployOpenStack (type: Exec) {
Andy Bavier1b8a5372016-07-07 19:36:21 -0400212 executable = "ansible-playbook"
213 args = ["-i", "inventory/single-prod"]
214
215 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
216 args = args << "--user=$config.seedServer.user"
217 }
218
219 def extraVars = []
220 if (config.seedServer) {
221 extraVars = extraVars.p(config.seedServer.extraVars)
222 .p(config.seedServer.password, "ansible_ssh_pass")
223 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
224 .p(config.seedServer.fabric_ip, "fabric_ip")
225 .p(config.seedServer.management_ip, "management_ip")
226 .p(config.seedServer.management_network, "management_network")
227 .p(config.seedServer.management_iface, "management_iface")
228 .p(config.seedServer.external_ip, "external_ip")
229 .p(config.seedServer.external_network, "external_network")
230 .p(config.seedServer.external_iface, "external_iface")
231 .p(config.seedServer.fabric_ip, "fabric_ip")
232 .p(config.seedServer.fabric_network, "fabric_network")
233 .p(config.seedServer.fabric_iface, "fabric_iface")
234 .p(config.seedServer.domain, "domain")
235 .p(config.seedServer.virtualbox_support, "virtualbox_support")
236 .p(config.seedServer.power_helper_user, "power_helper_user")
237 .p(config.seedServer.power_helper_host, "power_helper_host")
238 .p(config.seedServer.port, "ansible_ssh_port")
239 }
240
241 if (config.otherServers) {
242 extraVars = extraVars.p(config.otherServers.location, "prov_location")
243 .p(config.otherServers.rolesPath, "prov_role_path")
244 .p(config.otherServers.role, "prov_role")
245 }
246
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800247 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
248 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500249 .p("$cordAppVersion", "cord_app_version")
Andy Bavier1b8a5372016-07-07 19:36:21 -0400250
251 def skipTags = [].p(config.seedServer.skipTags)
252
Andy Bavier12262e72016-12-02 11:36:57 -0500253 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-openstack.yml"
254}
255
256task deployONOS (type: Exec) {
257 executable = "ansible-playbook"
258 args = ["-i", "inventory/single-prod"]
259
260 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
261 args = args << "--user=$config.seedServer.user"
262 }
263
264 def extraVars = []
265 if (config.seedServer) {
266 extraVars = extraVars.p(config.seedServer.extraVars)
267 .p(config.seedServer.password, "ansible_ssh_pass")
268 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
269 .p(config.seedServer.fabric_ip, "fabric_ip")
270 .p(config.seedServer.management_ip, "management_ip")
271 .p(config.seedServer.management_network, "management_network")
272 .p(config.seedServer.management_iface, "management_iface")
273 .p(config.seedServer.external_ip, "external_ip")
274 .p(config.seedServer.external_network, "external_network")
275 .p(config.seedServer.external_iface, "external_iface")
276 .p(config.seedServer.fabric_ip, "fabric_ip")
277 .p(config.seedServer.fabric_network, "fabric_network")
278 .p(config.seedServer.fabric_iface, "fabric_iface")
279 .p(config.seedServer.domain, "domain")
280 .p(config.seedServer.virtualbox_support, "virtualbox_support")
281 .p(config.seedServer.power_helper_user, "power_helper_user")
282 .p(config.seedServer.power_helper_host, "power_helper_host")
283 .p(config.seedServer.port, "ansible_ssh_port")
284 }
285
286 if (config.otherServers) {
287 extraVars = extraVars.p(config.otherServers.location, "prov_location")
288 .p(config.otherServers.rolesPath, "prov_role_path")
289 .p(config.otherServers.role, "prov_role")
290 }
291
292 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
293 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500294 .p("$cordAppVersion", "cord_app_version")
Andy Bavier12262e72016-12-02 11:36:57 -0500295
296 def skipTags = [].p(config.seedServer.skipTags)
297
298 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-onos.yml"
299}
300
301task deployXOS (type: Exec) {
302 executable = "ansible-playbook"
303 args = ["-i", "inventory/single-prod"]
304
305 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
306 args = args << "--user=$config.seedServer.user"
307 }
308
309 def extraVars = []
310 if (config.seedServer) {
311 extraVars = extraVars.p(config.seedServer.extraVars)
312 .p(config.seedServer.password, "ansible_ssh_pass")
313 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
314 .p(config.seedServer.fabric_ip, "fabric_ip")
315 .p(config.seedServer.management_ip, "management_ip")
316 .p(config.seedServer.management_network, "management_network")
317 .p(config.seedServer.management_iface, "management_iface")
318 .p(config.seedServer.external_ip, "external_ip")
319 .p(config.seedServer.external_network, "external_network")
320 .p(config.seedServer.external_iface, "external_iface")
321 .p(config.seedServer.fabric_ip, "fabric_ip")
322 .p(config.seedServer.fabric_network, "fabric_network")
323 .p(config.seedServer.fabric_iface, "fabric_iface")
324 .p(config.seedServer.domain, "domain")
325 .p(config.seedServer.virtualbox_support, "virtualbox_support")
326 .p(config.seedServer.power_helper_user, "power_helper_user")
327 .p(config.seedServer.power_helper_host, "power_helper_host")
328 .p(config.seedServer.port, "ansible_ssh_port")
329 }
330
331 if (config.otherServers) {
332 extraVars = extraVars.p(config.otherServers.location, "prov_location")
333 .p(config.otherServers.rolesPath, "prov_role_path")
334 .p(config.otherServers.role, "prov_role")
335 }
336
337 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
338 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500339 .p("$cordAppVersion", "cord_app_version")
Andy Bavier12262e72016-12-02 11:36:57 -0500340
341 def skipTags = [].p(config.seedServer.skipTags)
342
343 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-xos.yml"
344}
345
346task setupAutomation (type: Exec) {
347 executable = "ansible-playbook"
348 args = ["-i", "inventory/single-prod"]
349
350 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
351 args = args << "--user=$config.seedServer.user"
352 }
353
354 def extraVars = []
355 if (config.seedServer) {
356 extraVars = extraVars.p(config.seedServer.extraVars)
357 .p(config.seedServer.password, "ansible_ssh_pass")
358 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
359 .p(config.seedServer.fabric_ip, "fabric_ip")
360 .p(config.seedServer.management_ip, "management_ip")
361 .p(config.seedServer.management_network, "management_network")
362 .p(config.seedServer.management_iface, "management_iface")
363 .p(config.seedServer.external_ip, "external_ip")
364 .p(config.seedServer.external_network, "external_network")
365 .p(config.seedServer.external_iface, "external_iface")
366 .p(config.seedServer.fabric_ip, "fabric_ip")
367 .p(config.seedServer.fabric_network, "fabric_network")
368 .p(config.seedServer.fabric_iface, "fabric_iface")
369 .p(config.seedServer.domain, "domain")
370 .p(config.seedServer.virtualbox_support, "virtualbox_support")
371 .p(config.seedServer.power_helper_user, "power_helper_user")
372 .p(config.seedServer.power_helper_host, "power_helper_host")
373 .p(config.seedServer.port, "ansible_ssh_port")
374 }
375
376 if (config.otherServers) {
377 extraVars = extraVars.p(config.otherServers.location, "prov_location")
378 .p(config.otherServers.rolesPath, "prov_role_path")
379 .p(config.otherServers.role, "prov_role")
380 }
381
382 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
383 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500384 .p("$cordAppVersion", "cord_app_version")
Andy Bavier12262e72016-12-02 11:36:57 -0500385
386 def skipTags = [].p(config.seedServer.skipTags)
387
388 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-automation.yml"
389}
390
391deployOpenStack.mustRunAfter prepPlatform
392deployONOS.mustRunAfter deployOpenStack
393deployXOS.mustRunAfter deployONOS
394setupAutomation.mustRunAfter deployXOS
395
396task deployPlatform {
397 dependsOn prepPlatform
398 dependsOn deployOpenStack
399 dependsOn deployONOS
400 dependsOn deployXOS
401 dependsOn setupAutomation
Andy Bavier1b8a5372016-07-07 19:36:21 -0400402}
403
Andy Baviera27effe2016-07-18 19:23:26 -0400404task postDeployTests (type: Exec) {
Andy Baviera27effe2016-07-18 19:23:26 -0400405 executable = "ansible-playbook"
406 args = ["-i", "inventory/single-prod"]
407
408 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
409 args = args << "--user=$config.seedServer.user"
410 }
411
412 def extraVars = []
413 if (config.seedServer) {
414 extraVars = extraVars.p(config.seedServer.extraVars)
415 .p(config.seedServer.password, "ansible_ssh_pass")
416 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
417 .p(config.seedServer.fabric_ip, "fabric_ip")
418 .p(config.seedServer.management_ip, "management_ip")
419 .p(config.seedServer.management_network, "management_network")
420 .p(config.seedServer.management_iface, "management_iface")
421 .p(config.seedServer.external_ip, "external_ip")
422 .p(config.seedServer.external_network, "external_network")
423 .p(config.seedServer.external_iface, "external_iface")
424 .p(config.seedServer.fabric_ip, "fabric_ip")
425 .p(config.seedServer.fabric_network, "fabric_network")
426 .p(config.seedServer.fabric_iface, "fabric_iface")
427 .p(config.seedServer.domain, "domain")
428 .p(config.seedServer.virtualbox_support, "virtualbox_support")
429 .p(config.seedServer.power_helper_user, "power_helper_user")
430 .p(config.seedServer.power_helper_host, "power_helper_host")
431 .p(config.seedServer.port, "ansible_ssh_port")
432 }
433
434 if (config.otherServers) {
435 extraVars = extraVars.p(config.otherServers.location, "prov_location")
436 .p(config.otherServers.rolesPath, "prov_role_path")
437 .p(config.otherServers.role, "prov_role")
438 }
439
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800440 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
441 .p("$targetTag", "deploy_docker_tag")
Andy Bavier829bc002017-01-11 14:59:48 -0500442 .p("$cordAppVersion", "cord_app_version")
Andy Baviera27effe2016-07-18 19:23:26 -0400443
444 def skipTags = [].p(config.seedServer.skipTags)
445
446 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
447}