blob: 9c462dab1521db2ad8c140e7b6c4ed354b15ff96 [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
38ext {
39
40 // Upstream registry to simplify filling out the comps table below
41 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
42
Andy Bavieradea0fd2016-07-06 05:26:26 -040043 // Deployment target config file (yaml format); this can be overwritten from the command line
44 // using the -PdeployConfig=<file-path> syntax.
45 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
46
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080047 println "Using deployment config: $deployConfig"
48 File configFile = new File(deployConfig)
49 def yaml = new Yaml()
50 config = yaml.load(configFile.newReader())
51
52
53 // Target registry to be used to publish docker images needed for deployment
54 targetReg = project.hasProperty('targetReg')
55 ? project.getProperty('targetReg')
56 : config.docker && config.docker.registry
57 ? config.docker.registry
David K. Bainbridge94b24712016-11-15 15:09:42 -080058 : config.seedServer.ip
59 ? config.seedServer.ip + ":5000"
60 : 'localhost:5000'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080061
62 // The tag used to tag the docker images push to the target registry
63 targetTag = project.hasProperty('targetTag')
64 ? project.getProperty('targetTag')
65 : config.docker && config.docker.imageVersion
66 ? config.docker.imageVersion
Andy Bavier12262e72016-12-02 11:36:57 -050067 : 'candidate'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080068
69 println "targetReg = $targetReg, targetTag = $targetTag"
70
71 // Component table
72 comps = [
73 ]
Andy Bavieradea0fd2016-07-06 05:26:26 -040074}
75
Andy Bavier6dbb1a32016-07-06 07:12:50 -040076task copyAnsibleInventory(type: Copy) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -040077 from 'inventory/templates/single-prod'
78 into 'inventory'
79 expand([
80 prod: config.seedServer.ip,
81 ])
82}
83
Andy Bavieradea0fd2016-07-06 05:26:26 -040084// ------------- PlaceHolders ----------------
85
86task updateDocker (type: Exec) {
87 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
88}
89
90task prime {
91 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -040092 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -040093}
94
95// ---------------- Useful tasks ----------------
96
Andy Bavier1b8a5372016-07-07 19:36:21 -040097List.metaClass.asParam = { prefix, sep ->
98 if (delegate.size() == 0) {
99 ""
100 }
101 String result = "--" + prefix + "="
102 String p = ""
103 delegate.each {
104 result += p + "${it}"
105 p = sep
106 }
107 result
108}
109
110List.metaClass.p = { value, name ->
111 if (value != null && value != "") {
112 delegate << name + "=" + value
113 } else {
114 delegate
115 }
116}
117
118List.metaClass.p = { spec ->
119 if (spec != null && spec != "") {
120 delegate += spec
121 } else {
122 delegate
123 }
124}
125
alshabibfe09d772016-08-29 16:15:56 -0700126task fetch << {
127 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400128}
129
alshabibfe09d772016-08-29 16:15:56 -0700130task buildImages << {
131 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400132}
133
134task publishImages {
135 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
136}
137
138task publish {
139 dependsOn publishImages
140}
141
142tasks.addRule(new DockerFetchRule(project))
143tasks.addRule(new DockerPublishRule(project))
144tasks.addRule(new DockerTagRule(project))
145tasks.addRule(new GitSubmoduleUpdateRule(project))
146
Andy Bavier12262e72016-12-02 11:36:57 -0500147task prepPlatform(type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400148 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400149
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400150 executable = "ansible-playbook"
151 args = ["-i", "inventory/single-prod"]
152
153 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
154 args = args << "--user=$config.seedServer.user"
155 }
156
157 def extraVars = []
158 if (config.seedServer) {
159 extraVars = extraVars.p(config.seedServer.extraVars)
160 .p(config.seedServer.password, "ansible_ssh_pass")
161 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
162 .p(config.seedServer.fabric_ip, "fabric_ip")
163 .p(config.seedServer.management_ip, "management_ip")
164 .p(config.seedServer.management_network, "management_network")
165 .p(config.seedServer.management_iface, "management_iface")
166 .p(config.seedServer.external_ip, "external_ip")
167 .p(config.seedServer.external_network, "external_network")
168 .p(config.seedServer.external_iface, "external_iface")
169 .p(config.seedServer.fabric_ip, "fabric_ip")
170 .p(config.seedServer.fabric_network, "fabric_network")
171 .p(config.seedServer.fabric_iface, "fabric_iface")
172 .p(config.seedServer.domain, "domain")
173 .p(config.seedServer.virtualbox_support, "virtualbox_support")
174 .p(config.seedServer.power_helper_user, "power_helper_user")
175 .p(config.seedServer.power_helper_host, "power_helper_host")
176 .p(config.seedServer.port, "ansible_ssh_port")
177 }
178
179 if (config.otherServers) {
180 extraVars = extraVars.p(config.otherServers.location, "prov_location")
181 .p(config.otherServers.rolesPath, "prov_role_path")
182 .p(config.otherServers.role, "prov_role")
183 }
184
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800185 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
186 .p("$targetTag", "deploy_docker_tag")
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400187
188 def skipTags = [].p(config.seedServer.skipTags)
189
Andy Bavier12262e72016-12-02 11:36:57 -0500190 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-prep-platform.yml"
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400191}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400192
Andy Bavier12262e72016-12-02 11:36:57 -0500193task deployOpenStack (type: Exec) {
Andy Bavier1b8a5372016-07-07 19:36:21 -0400194 executable = "ansible-playbook"
195 args = ["-i", "inventory/single-prod"]
196
197 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
198 args = args << "--user=$config.seedServer.user"
199 }
200
201 def extraVars = []
202 if (config.seedServer) {
203 extraVars = extraVars.p(config.seedServer.extraVars)
204 .p(config.seedServer.password, "ansible_ssh_pass")
205 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
206 .p(config.seedServer.fabric_ip, "fabric_ip")
207 .p(config.seedServer.management_ip, "management_ip")
208 .p(config.seedServer.management_network, "management_network")
209 .p(config.seedServer.management_iface, "management_iface")
210 .p(config.seedServer.external_ip, "external_ip")
211 .p(config.seedServer.external_network, "external_network")
212 .p(config.seedServer.external_iface, "external_iface")
213 .p(config.seedServer.fabric_ip, "fabric_ip")
214 .p(config.seedServer.fabric_network, "fabric_network")
215 .p(config.seedServer.fabric_iface, "fabric_iface")
216 .p(config.seedServer.domain, "domain")
217 .p(config.seedServer.virtualbox_support, "virtualbox_support")
218 .p(config.seedServer.power_helper_user, "power_helper_user")
219 .p(config.seedServer.power_helper_host, "power_helper_host")
220 .p(config.seedServer.port, "ansible_ssh_port")
221 }
222
223 if (config.otherServers) {
224 extraVars = extraVars.p(config.otherServers.location, "prov_location")
225 .p(config.otherServers.rolesPath, "prov_role_path")
226 .p(config.otherServers.role, "prov_role")
227 }
228
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800229 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
230 .p("$targetTag", "deploy_docker_tag")
Andy Bavier1b8a5372016-07-07 19:36:21 -0400231
232 def skipTags = [].p(config.seedServer.skipTags)
233
Andy Bavier12262e72016-12-02 11:36:57 -0500234 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-openstack.yml"
235}
236
237task deployONOS (type: Exec) {
238 executable = "ansible-playbook"
239 args = ["-i", "inventory/single-prod"]
240
241 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
242 args = args << "--user=$config.seedServer.user"
243 }
244
245 def extraVars = []
246 if (config.seedServer) {
247 extraVars = extraVars.p(config.seedServer.extraVars)
248 .p(config.seedServer.password, "ansible_ssh_pass")
249 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
250 .p(config.seedServer.fabric_ip, "fabric_ip")
251 .p(config.seedServer.management_ip, "management_ip")
252 .p(config.seedServer.management_network, "management_network")
253 .p(config.seedServer.management_iface, "management_iface")
254 .p(config.seedServer.external_ip, "external_ip")
255 .p(config.seedServer.external_network, "external_network")
256 .p(config.seedServer.external_iface, "external_iface")
257 .p(config.seedServer.fabric_ip, "fabric_ip")
258 .p(config.seedServer.fabric_network, "fabric_network")
259 .p(config.seedServer.fabric_iface, "fabric_iface")
260 .p(config.seedServer.domain, "domain")
261 .p(config.seedServer.virtualbox_support, "virtualbox_support")
262 .p(config.seedServer.power_helper_user, "power_helper_user")
263 .p(config.seedServer.power_helper_host, "power_helper_host")
264 .p(config.seedServer.port, "ansible_ssh_port")
265 }
266
267 if (config.otherServers) {
268 extraVars = extraVars.p(config.otherServers.location, "prov_location")
269 .p(config.otherServers.rolesPath, "prov_role_path")
270 .p(config.otherServers.role, "prov_role")
271 }
272
273 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
274 .p("$targetTag", "deploy_docker_tag")
275
276 def skipTags = [].p(config.seedServer.skipTags)
277
278 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-onos.yml"
279}
280
281task deployXOS (type: Exec) {
282 executable = "ansible-playbook"
283 args = ["-i", "inventory/single-prod"]
284
285 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
286 args = args << "--user=$config.seedServer.user"
287 }
288
289 def extraVars = []
290 if (config.seedServer) {
291 extraVars = extraVars.p(config.seedServer.extraVars)
292 .p(config.seedServer.password, "ansible_ssh_pass")
293 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
294 .p(config.seedServer.fabric_ip, "fabric_ip")
295 .p(config.seedServer.management_ip, "management_ip")
296 .p(config.seedServer.management_network, "management_network")
297 .p(config.seedServer.management_iface, "management_iface")
298 .p(config.seedServer.external_ip, "external_ip")
299 .p(config.seedServer.external_network, "external_network")
300 .p(config.seedServer.external_iface, "external_iface")
301 .p(config.seedServer.fabric_ip, "fabric_ip")
302 .p(config.seedServer.fabric_network, "fabric_network")
303 .p(config.seedServer.fabric_iface, "fabric_iface")
304 .p(config.seedServer.domain, "domain")
305 .p(config.seedServer.virtualbox_support, "virtualbox_support")
306 .p(config.seedServer.power_helper_user, "power_helper_user")
307 .p(config.seedServer.power_helper_host, "power_helper_host")
308 .p(config.seedServer.port, "ansible_ssh_port")
309 }
310
311 if (config.otherServers) {
312 extraVars = extraVars.p(config.otherServers.location, "prov_location")
313 .p(config.otherServers.rolesPath, "prov_role_path")
314 .p(config.otherServers.role, "prov_role")
315 }
316
317 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
318 .p("$targetTag", "deploy_docker_tag")
319
320 def skipTags = [].p(config.seedServer.skipTags)
321
322 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-xos.yml"
323}
324
325task setupAutomation (type: Exec) {
326 executable = "ansible-playbook"
327 args = ["-i", "inventory/single-prod"]
328
329 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
330 args = args << "--user=$config.seedServer.user"
331 }
332
333 def extraVars = []
334 if (config.seedServer) {
335 extraVars = extraVars.p(config.seedServer.extraVars)
336 .p(config.seedServer.password, "ansible_ssh_pass")
337 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
338 .p(config.seedServer.fabric_ip, "fabric_ip")
339 .p(config.seedServer.management_ip, "management_ip")
340 .p(config.seedServer.management_network, "management_network")
341 .p(config.seedServer.management_iface, "management_iface")
342 .p(config.seedServer.external_ip, "external_ip")
343 .p(config.seedServer.external_network, "external_network")
344 .p(config.seedServer.external_iface, "external_iface")
345 .p(config.seedServer.fabric_ip, "fabric_ip")
346 .p(config.seedServer.fabric_network, "fabric_network")
347 .p(config.seedServer.fabric_iface, "fabric_iface")
348 .p(config.seedServer.domain, "domain")
349 .p(config.seedServer.virtualbox_support, "virtualbox_support")
350 .p(config.seedServer.power_helper_user, "power_helper_user")
351 .p(config.seedServer.power_helper_host, "power_helper_host")
352 .p(config.seedServer.port, "ansible_ssh_port")
353 }
354
355 if (config.otherServers) {
356 extraVars = extraVars.p(config.otherServers.location, "prov_location")
357 .p(config.otherServers.rolesPath, "prov_role_path")
358 .p(config.otherServers.role, "prov_role")
359 }
360
361 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
362 .p("$targetTag", "deploy_docker_tag")
363
364 def skipTags = [].p(config.seedServer.skipTags)
365
366 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-automation.yml"
367}
368
369deployOpenStack.mustRunAfter prepPlatform
370deployONOS.mustRunAfter deployOpenStack
371deployXOS.mustRunAfter deployONOS
372setupAutomation.mustRunAfter deployXOS
373
374task deployPlatform {
375 dependsOn prepPlatform
376 dependsOn deployOpenStack
377 dependsOn deployONOS
378 dependsOn deployXOS
379 dependsOn setupAutomation
Andy Bavier1b8a5372016-07-07 19:36:21 -0400380}
381
Andy Baviera27effe2016-07-18 19:23:26 -0400382task postDeployTests (type: Exec) {
Andy Baviera27effe2016-07-18 19:23:26 -0400383 executable = "ansible-playbook"
384 args = ["-i", "inventory/single-prod"]
385
386 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
387 args = args << "--user=$config.seedServer.user"
388 }
389
390 def extraVars = []
391 if (config.seedServer) {
392 extraVars = extraVars.p(config.seedServer.extraVars)
393 .p(config.seedServer.password, "ansible_ssh_pass")
394 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
395 .p(config.seedServer.fabric_ip, "fabric_ip")
396 .p(config.seedServer.management_ip, "management_ip")
397 .p(config.seedServer.management_network, "management_network")
398 .p(config.seedServer.management_iface, "management_iface")
399 .p(config.seedServer.external_ip, "external_ip")
400 .p(config.seedServer.external_network, "external_network")
401 .p(config.seedServer.external_iface, "external_iface")
402 .p(config.seedServer.fabric_ip, "fabric_ip")
403 .p(config.seedServer.fabric_network, "fabric_network")
404 .p(config.seedServer.fabric_iface, "fabric_iface")
405 .p(config.seedServer.domain, "domain")
406 .p(config.seedServer.virtualbox_support, "virtualbox_support")
407 .p(config.seedServer.power_helper_user, "power_helper_user")
408 .p(config.seedServer.power_helper_host, "power_helper_host")
409 .p(config.seedServer.port, "ansible_ssh_port")
410 }
411
412 if (config.otherServers) {
413 extraVars = extraVars.p(config.otherServers.location, "prov_location")
414 .p(config.otherServers.rolesPath, "prov_role_path")
415 .p(config.otherServers.role, "prov_role")
416 }
417
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800418 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
419 .p("$targetTag", "deploy_docker_tag")
Andy Baviera27effe2016-07-18 19:23:26 -0400420
421 def skipTags = [].p(config.seedServer.skipTags)
422
423 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
424}