blob: b4fe448d62c83f6b1eccf60d65088b3fbd9497d6 [file] [log] [blame]
Matteo Scandolo60b640f2017-08-08 13:05:22 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Zsolt Harasztiec7df102016-05-05 13:34:18 -070019/*
20 * Copyright 2012 the original author or authors.
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 */
34
Zsolt Haraszti0b790aa2016-05-12 22:33:14 -070035import org.opencord.gradle.rules.*
Zsolt Harasztiec7df102016-05-05 13:34:18 -070036import org.yaml.snakeyaml.Yaml
Zack Williams38d8c7f2017-01-23 07:35:36 -070037import org.yaml.snakeyaml.DumperOptions
Zsolt Harasztiec7df102016-05-05 13:34:18 -070038
alshabib11b8e5c2016-08-29 15:36:36 -070039buildscript {
40 repositories {
41 maven {
42 url "https://plugins.gradle.org/m2/"
43 }
44 }
45 dependencies {
46 classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.2.1"
47 }
48}
49
50apply plugin: "com.dorongold.task-tree"
51
52evaluationDependsOn(':maas')
alshabib11b8e5c2016-08-29 15:36:36 -070053evaluationDependsOn(':onos-apps')
Andy Bavier96df5e62017-03-13 18:19:24 -040054evaluationDependsOn(':orchestration:xos')
Scott Bakera6e5dd12017-04-17 10:08:16 -070055evaluationDependsOn(':platform-install')
alshabib11b8e5c2016-08-29 15:36:36 -070056
Zsolt Harasztiec7df102016-05-05 13:34:18 -070057allprojects {
58 apply plugin: 'base'
59 apply plugin: 'de.gesellix.docker'
60 //apply plugin: 'com.tmiyamon.config'
61
62 docker {
63 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
64 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
65 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
66 // authConfigPlain = [
67 // "username" : "joe",
68 // "password" : "some-pw-as-needed",
69 // "email" : "joe@acme.com",
70 // "serveraddress" : "https://index.docker.io/v1/"
71 // ]
72 }
73}
74
75ext {
76
David K. Bainbridge094508e2016-11-15 17:23:51 -080077 // Deployment target config file (yaml format); this can be overwritten from the command line
78 // using the -PdeployConfig=<file-path> syntax.
alshabib19c61df2017-02-14 11:25:22 -080079 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
David K. Bainbridge094508e2016-11-15 17:23:51 -080080
81 println "Using deployment config: $deployConfig"
82 File configFile = new File(deployConfig)
83 def yaml = new Yaml()
84 config = yaml.load(configFile.newReader())
85
Zsolt Harasztiec7df102016-05-05 13:34:18 -070086 // Upstream registry to simplify filling out the comps table below
Zsolt Harasztia9f72502016-05-12 16:07:03 -070087 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070088
89 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge094508e2016-11-15 17:23:51 -080090 targetReg = project.hasProperty('targetReg')
91 ? project.getProperty('targetReg')
92 : config.docker && config.docker.registry
93 ? config.docker.registry
Zack Williams0620c932017-01-25 14:36:31 -070094 : config.headnode.ip
95 ? config.headnode.ip + ":5000"
David K. Bainbridge094508e2016-11-15 17:23:51 -080096 : 'localhost:5000'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070097
98 // The tag used to tag the docker images push to the target registry
David K. Bainbridge094508e2016-11-15 17:23:51 -080099 targetTag = project.hasProperty('targetTag')
100 ? project.getProperty('targetTag')
101 : config.docker && config.docker.imageVersion
102 ? config.docker.imageVersion
103 : 'candidate'
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700104
105 // Component table
106 comps = [
Andy Bavier0c6bb652017-06-26 13:02:21 -0400107 // ONOS 1.8.9 from DockerHub
Andy Bavierb69496a2017-05-10 14:42:38 -0400108 'onosproject/onos': [
David K. Bainbridged54ca702016-07-13 22:27:12 -0700109 'type': 'image',
110 'upstream': upstreamReg,
Andy Bavierb69496a2017-05-10 14:42:38 -0400111 'name': 'onosproject/onos',
Andy Bavier0c6bb652017-06-26 13:02:21 -0400112 'digest': 'sha256:bfeef75855775038f3b6e9b56b574b40a6f38c93b909d838014370a76902d2fc'
David K. Bainbridged54ca702016-07-13 22:27:12 -0700113 ],
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700114 'nginx': [
115 'type': 'image',
116 'upstream': upstreamReg,
117 'name': 'nginx',
118 'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
119 ],
120 'swarm': [
121 'type': 'image',
122 'upstream': upstreamReg,
123 'name': 'swarm',
124 'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
125 ],
Scott Bakera0a0e442016-10-10 20:58:22 -0700126 'xosproject/vsg': [
127 'type': 'image',
128 'upstream': upstreamReg,
129 'name': 'xosproject/vsg',
130 'digest': 'sha256:18d1c6ef9767d8a41c9b51948776052d024d4e3294e5d1d6dde1a49112175d91'
131 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700132 'redis': [
133 'type': 'image',
134 'upstream': upstreamReg,
135 'name': 'redis',
136 'digest': 'sha256:0fe5a7afa2c2154f37c8ab56a9a6c5023cb0405cc0e85b34d8dcc1de6c3f143e'
137 ],
Andy Bavier35d238e2017-07-24 16:47:22 -0700138 // Node 7.9.0
Scott Baker18ea0c32017-01-19 09:29:57 -0800139 'node': [
140 'type': 'image',
141 'upstream': upstreamReg,
142 'name': 'node',
Andy Bavier35d238e2017-07-24 16:47:22 -0700143 'digest': 'sha256:e64b0d7eeb44034d3f2c301d3050b72c1639e683d5a0fd3b8aae3d6ac4789c7a'
Scott Baker18ea0c32017-01-19 09:29:57 -0800144 ],
Matteo Scandolo951dd5b2017-05-25 07:35:47 -0700145 'gliderlabs/consul-server': [
Matteo Scandolo89576202017-05-18 18:39:43 -0700146 'type': 'image',
147 'upstream': upstreamReg,
148 'name': 'gliderlabs/consul-server',
Matteo Scandoloccd20e82017-05-24 15:13:48 -0700149 'digest': 'sha256:37e194c7c941e37cf20b0cc5080541cfde9d31bf62a874905d0d51b3945f88c9'
Matteo Scandolo89576202017-05-18 18:39:43 -0700150 ],
Matteo Scandolo951dd5b2017-05-25 07:35:47 -0700151 'gliderlabs/registrator': [
Matteo Scandolo89576202017-05-18 18:39:43 -0700152 'type': 'image',
153 'upstream': upstreamReg,
154 'name': 'gliderlabs/registrator',
Matteo Scandoloccd20e82017-05-24 15:13:48 -0700155 'digest': 'sha256:6e708681dd52e28f4f39d048ac75376c9a762c44b3d75b2824173f8364e52c10'
Matteo Scandolo89576202017-05-18 18:39:43 -0700156 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700157 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700158}
159
alshabib00c4b5d2016-06-17 17:26:10 -0700160// ---------------- Useful tasks ----------------
161
Zack Williams0620c932017-01-25 14:36:31 -0700162task writeInventory(type: Copy) {
163 from 'ansible/cord-inv'
164 into 'genconfig'
Zack Williams38d8c7f2017-01-23 07:35:36 -0700165 expand([
Zack Williams0620c932017-01-25 14:36:31 -0700166 headnode_ip: config.headnode.ip,
167 headnode_user: config.headnode.ansible_user,
168 headnode_pass: config.headnode.ansible_ssh_pass,
169 headnode_port: config.headnode.ansible_ssh_port,
Zack Williams38d8c7f2017-01-23 07:35:36 -0700170 ])
171}
172
173task writeYamlConfig {
Zack Williams0620c932017-01-25 14:36:31 -0700174 def outvar = config.common
Zack Williams38d8c7f2017-01-23 07:35:36 -0700175 def outfilename = "genconfig/config.yml"
176
177 DumperOptions options = new DumperOptions()
178
179 options.setExplicitStart(true);
180 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
181 options.setPrettyFlow(true);
182 options.setIndent(2);
183
184 def yaml = new Yaml(options)
185 Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
186
187 yaml.dump(outvar, outfile)
188 outfile.close()
189}
190
Zack Williams38d8c7f2017-01-23 07:35:36 -0700191
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700192task fetchUpstreamImages {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700193 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
194}
195
alshabib11b8e5c2016-08-29 15:36:36 -0700196task fetch {
197 dependsOn fetchUpstreamImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700198}
199
alshabib11b8e5c2016-08-29 15:36:36 -0700200task buildImages {
201 logger.info "Root project has nothing to build"
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700202}
203
204task publishImages {
Andy Bavier24d21112017-03-13 10:09:31 -0400205 comps.each { name, spec -> if (spec.type == 'image') {
206 dependsOn "publish" + name
207 }
alshabib11b8e5c2016-08-29 15:36:36 -0700208 }
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700209}
210
211task publish {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700212 dependsOn publishImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700213}
214
215tasks.addRule(new DockerFetchRule(project))
alshabib11b8e5c2016-08-29 15:36:36 -0700216tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700217tasks.addRule(new DockerTagRule(project))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700218
Zack Williams83a94ce2017-05-20 13:36:09 -0700219task PIcreateConfig(type: Exec) {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700220 dependsOn writeYamlConfig
Zack Williams0620c932017-01-25 14:36:31 -0700221 dependsOn writeInventory
Zack Williams38d8c7f2017-01-23 07:35:36 -0700222
Andy Bavier96df5e62017-03-13 18:19:24 -0400223 workingDir "platform-install"
224 executable = "ansible-playbook"
225 args = [ "-i", "../genconfig/cord-inv",
226 "--extra-vars", "@../genconfig/config.yml",
Andy Bavier66ceea42017-07-26 09:06:00 -0700227 "--extra-vars", "pull_docker_tag="+targetTag,
228 "--extra-vars", "pull_docker_registry=docker-registry:5000/",
Zack Williams83a94ce2017-05-20 13:36:09 -0700229 "cord-config-playbook.yml" ]
230}
231
232task PIcopyCord(type: Exec) {
233 dependsOn PIcreateConfig
234
235 workingDir "platform-install"
236 executable = "ansible-playbook"
237 args = [ "-i", "../genconfig/cord-inv",
238 "--extra-vars", "@../genconfig/config.yml",
239 "copy-cord-playbook.yml" ]
240}
241
242task PIcopyProfile(type: Exec) {
243 dependsOn PIcreateConfig
244
245 workingDir "platform-install"
246 executable = "ansible-playbook"
247 args = [ "-i", "../genconfig/cord-inv",
248 "--extra-vars", "@../genconfig/config.yml",
249 "copy-profile-playbook.yml" ]
Andy Bavier96df5e62017-03-13 18:19:24 -0400250}
251
Zack Williams38d8c7f2017-01-23 07:35:36 -0700252task PIprepPlatform(type: Exec) {
Zack Williams83a94ce2017-05-20 13:36:09 -0700253 dependsOn PIcreateConfig
254 dependsOn PIcopyCord
255 dependsOn PIcopyProfile
Zack Williams38d8c7f2017-01-23 07:35:36 -0700256
Zack Williams83a94ce2017-05-20 13:36:09 -0700257 workingDir "platform-install"
258 executable = "ansible-playbook"
259 args = [ "-i", "../genconfig/cord-inv",
260 "--extra-vars", "@../genconfig/config.yml",
261 "prep-platform-playbook.yml" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700262}
263
264task PIdeployOpenStack (type: Exec) {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700265
Zack Williams31fbc6b2017-04-21 22:04:44 -0700266 workingDir "platform-install"
267 executable = "ansible-playbook"
268 args = [ "-i", "../genconfig/cord-inv",
269 "--extra-vars", "@../genconfig/config.yml",
Andy Bavier66ceea42017-07-26 09:06:00 -0700270 "--extra-vars", "pull_docker_tag="+targetTag,
271 "--extra-vars", "pull_docker_registry=docker-registry:5000/",
Zack Williams31fbc6b2017-04-21 22:04:44 -0700272 "deploy-openstack-playbook.yml" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700273}
274
275task PIdeployONOS (type: Exec) {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700276
Zack Williams83a94ce2017-05-20 13:36:09 -0700277 workingDir "platform-install"
278 executable = "ansible-playbook"
279 args = [ "-i", "../genconfig/cord-inv",
280 "--extra-vars", "@../genconfig/config.yml",
Andy Bavier66ceea42017-07-26 09:06:00 -0700281 "--extra-vars", "pull_docker_tag="+targetTag,
282 "--extra-vars", "pull_docker_registry=docker-registry:5000/",
Zack Williams83a94ce2017-05-20 13:36:09 -0700283 "deploy-onos-playbook.yml" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700284}
285
286task PIdeployXOS (type: Exec) {
Andy Bavier66ceea42017-07-26 09:06:00 -0700287 def extra_vars = "--extra-vars pull_docker_tag="+targetTag+" --extra-vars pull_docker_registry=docker-registry:5000/"
Zack Williams83a94ce2017-05-20 13:36:09 -0700288 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml "+extra_vars+" launch-xos-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700289
290 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700291 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700292}
293
294task PIsetupAutomation (type: Exec) {
Zack Williams83a94ce2017-05-20 13:36:09 -0700295 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-automation-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700296
297 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700298 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700299}
300
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700301task PIrunDiag (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700302 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml collect-diag-playbook.yml"
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700303
304 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700305 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700306}
307
Zack Williams38d8c7f2017-01-23 07:35:36 -0700308task postDeployTests (type: Exec) {
309
Zack Williams83a94ce2017-05-20 13:36:09 -0700310 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml pod-test-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700311
312 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700313 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700314}
315
Zack Williams03a20ec2017-04-12 17:39:36 -0700316project(':maas').prime.dependsOn writeYamlConfig
317project(':maas').prime.dependsOn writeInventory
318
alshabib11b8e5c2016-08-29 15:36:36 -0700319project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
alshabibc64cf7f2016-09-07 11:47:01 -0700320project(':onos-apps').deploy.dependsOn project(':maas').deployBase
321
Zack Williams38d8c7f2017-01-23 07:35:36 -0700322project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
323project(':onos-apps').deploy.dependsOn project(':maas').deployBase
324
Andy Bavier2f151eb2017-05-04 16:39:13 -0700325// Ensure nginx:candidate exists
Andy Bavier619b6352017-04-26 15:30:23 -0700326project(':orchestration:xos').buildImages.dependsOn rootProject."tagnginx"
Andy Bavier96df5e62017-03-13 18:19:24 -0400327
Zack Williams83a94ce2017-05-20 13:36:09 -0700328// make PI config tasks run before maas deploy
329project(':maas').deployBase.dependsOn PIcopyProfile
330
Andy Bavier2f151eb2017-05-04 16:39:13 -0700331// For corebuilder
Scott Bakera6e5dd12017-04-17 10:08:16 -0700332project(':platform-install').buildImages.dependsOn project(':orchestration:xos').buildImages
333
Zack Williams38d8c7f2017-01-23 07:35:36 -0700334task PIdeployPlatform {
Zack Williams83a94ce2017-05-20 13:36:09 -0700335 dependsOn PIcopyCord
Zack Williams38d8c7f2017-01-23 07:35:36 -0700336 dependsOn project(':onos-apps').deploy
337 dependsOn project(':maas').deployBase
338 dependsOn PIprepPlatform
339 dependsOn PIdeployOpenStack
340 dependsOn PIdeployONOS
341 dependsOn PIdeployXOS
342 dependsOn PIsetupAutomation
343}
344
Zack Williams83a94ce2017-05-20 13:36:09 -0700345PIprepPlatform.mustRunAfter PIcopyCord
Zack Williams38d8c7f2017-01-23 07:35:36 -0700346PIdeployOpenStack.mustRunAfter PIprepPlatform
347PIdeployONOS.mustRunAfter PIdeployOpenStack
348PIdeployXOS.mustRunAfter PIdeployONOS
349PIsetupAutomation.mustRunAfter PIdeployXOS
350PIdeployPlatform.mustRunAfter project(':onos-apps').deploy
351PIdeployPlatform.mustRunAfter project(':maas').deployBase
Andy Bavierbeb89c02016-07-07 13:26:55 -0400352
alshabib11b8e5c2016-08-29 15:36:36 -0700353task deploy {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700354 dependsOn PIdeployPlatform
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700355}