blob: e138cafaa490d8c5794ef074546824834bc867e2 [file] [log] [blame]
Zsolt Harasztiec7df102016-05-05 13:34:18 -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 */
16
Zsolt Haraszti0b790aa2016-05-12 22:33:14 -070017import org.opencord.gradle.rules.*
Zsolt Harasztiec7df102016-05-05 13:34:18 -070018import org.yaml.snakeyaml.Yaml
Zack Williams38d8c7f2017-01-23 07:35:36 -070019import org.yaml.snakeyaml.DumperOptions
Zsolt Harasztiec7df102016-05-05 13:34:18 -070020
alshabib11b8e5c2016-08-29 15:36:36 -070021buildscript {
22 repositories {
23 maven {
24 url "https://plugins.gradle.org/m2/"
25 }
26 }
27 dependencies {
28 classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.2.1"
29 }
30}
31
32apply plugin: "com.dorongold.task-tree"
33
34evaluationDependsOn(':maas')
alshabib11b8e5c2016-08-29 15:36:36 -070035evaluationDependsOn(':onos-apps')
Andy Bavier96df5e62017-03-13 18:19:24 -040036evaluationDependsOn(':orchestration:xos')
alshabib11b8e5c2016-08-29 15:36:36 -070037
Zsolt Harasztiec7df102016-05-05 13:34:18 -070038allprojects {
39 apply plugin: 'base'
40 apply plugin: 'de.gesellix.docker'
41 //apply plugin: 'com.tmiyamon.config'
42
43 docker {
44 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
45 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
46 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
47 // authConfigPlain = [
48 // "username" : "joe",
49 // "password" : "some-pw-as-needed",
50 // "email" : "joe@acme.com",
51 // "serveraddress" : "https://index.docker.io/v1/"
52 // ]
53 }
54}
55
56ext {
57
David K. Bainbridge094508e2016-11-15 17:23:51 -080058 // Deployment target config file (yaml format); this can be overwritten from the command line
59 // using the -PdeployConfig=<file-path> syntax.
alshabib19c61df2017-02-14 11:25:22 -080060 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
David K. Bainbridge094508e2016-11-15 17:23:51 -080061
62 println "Using deployment config: $deployConfig"
63 File configFile = new File(deployConfig)
64 def yaml = new Yaml()
65 config = yaml.load(configFile.newReader())
66
Zsolt Harasztiec7df102016-05-05 13:34:18 -070067 // Upstream registry to simplify filling out the comps table below
Zsolt Harasztia9f72502016-05-12 16:07:03 -070068 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070069
70 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge094508e2016-11-15 17:23:51 -080071 targetReg = project.hasProperty('targetReg')
72 ? project.getProperty('targetReg')
73 : config.docker && config.docker.registry
74 ? config.docker.registry
Zack Williams0620c932017-01-25 14:36:31 -070075 : config.headnode.ip
76 ? config.headnode.ip + ":5000"
David K. Bainbridge094508e2016-11-15 17:23:51 -080077 : 'localhost:5000'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070078
79 // The tag used to tag the docker images push to the target registry
David K. Bainbridge094508e2016-11-15 17:23:51 -080080 targetTag = project.hasProperty('targetTag')
81 ? project.getProperty('targetTag')
82 : config.docker && config.docker.imageVersion
83 ? config.docker.imageVersion
84 : 'candidate'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070085
86 // Component table
87 comps = [
Jonathan Hart92e75ce2017-01-13 17:28:18 -080088 // ONOS 1.8.2 from the opencord Dockerhub
89 'opencord/onos': [
David K. Bainbridged54ca702016-07-13 22:27:12 -070090 'type': 'image',
91 'upstream': upstreamReg,
Jonathan Hart92e75ce2017-01-13 17:28:18 -080092 'name': 'opencord/onos',
93 'digest': 'sha256:935da663c381393316e0c658d49dde10d90a7383e3d7c53271b1223cec31d44c'
David K. Bainbridged54ca702016-07-13 22:27:12 -070094 ],
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -070095 'nginx': [
96 'type': 'image',
97 'upstream': upstreamReg,
98 'name': 'nginx',
99 'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
100 ],
101 'swarm': [
102 'type': 'image',
103 'upstream': upstreamReg,
104 'name': 'swarm',
105 'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
106 ],
Scott Bakera0a0e442016-10-10 20:58:22 -0700107 'xosproject/vsg': [
108 'type': 'image',
109 'upstream': upstreamReg,
110 'name': 'xosproject/vsg',
111 'digest': 'sha256:18d1c6ef9767d8a41c9b51948776052d024d4e3294e5d1d6dde1a49112175d91'
112 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700113 'xosproject/xos-postgres': [
114 'type': 'image',
115 'upstream': upstreamReg,
116 'name': 'xosproject/xos-postgres',
117 'digest': 'sha256:f2d31a50b8af7434ab07b1e54e99c1ff1e10d77d16a46e5d6933d3c0528f4820'
118 ],
Jonathan Hart09dad6c2016-11-14 16:52:56 -0800119 'xosproject/xos-base': [
120 'type': 'image',
121 'upstream': upstreamReg,
122 'name': 'xosproject/xos-base',
Zack Williams1b0e83f2017-02-01 14:35:30 -0700123 'digest': 'sha256:b621a58e8b7f44d9ec12811f76388fe602d8700acfc8b68d0972265e66ab6fee'
Jonathan Hart09dad6c2016-11-14 16:52:56 -0800124 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700125 'redis': [
126 'type': 'image',
127 'upstream': upstreamReg,
128 'name': 'redis',
129 'digest': 'sha256:0fe5a7afa2c2154f37c8ab56a9a6c5023cb0405cc0e85b34d8dcc1de6c3f143e'
130 ],
Scott Baker18ea0c32017-01-19 09:29:57 -0800131 'node': [
132 'type': 'image',
133 'upstream': upstreamReg,
134 'name': 'node',
135 'digest': 'sha256:5757581a8ff7e08041512a54aa3f573d33fecdce81d603e48a759956cd99bdd3'
136 ],
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700137 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700138}
139
alshabib00c4b5d2016-06-17 17:26:10 -0700140// ---------------- Useful tasks ----------------
141
Zack Williams0620c932017-01-25 14:36:31 -0700142task writeInventory(type: Copy) {
143 from 'ansible/cord-inv'
144 into 'genconfig'
Zack Williams38d8c7f2017-01-23 07:35:36 -0700145 expand([
Zack Williams0620c932017-01-25 14:36:31 -0700146 headnode_ip: config.headnode.ip,
147 headnode_user: config.headnode.ansible_user,
148 headnode_pass: config.headnode.ansible_ssh_pass,
149 headnode_port: config.headnode.ansible_ssh_port,
Zack Williams38d8c7f2017-01-23 07:35:36 -0700150 ])
151}
152
153task writeYamlConfig {
Zack Williams0620c932017-01-25 14:36:31 -0700154 def outvar = config.common
Zack Williams38d8c7f2017-01-23 07:35:36 -0700155 def outfilename = "genconfig/config.yml"
156
157 DumperOptions options = new DumperOptions()
158
159 options.setExplicitStart(true);
160 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
161 options.setPrettyFlow(true);
162 options.setIndent(2);
163
164 def yaml = new Yaml(options)
165 Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
166
167 yaml.dump(outvar, outfile)
168 outfile.close()
169}
170
Zack Williams38d8c7f2017-01-23 07:35:36 -0700171
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700172task fetchUpstreamImages {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700173 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
174}
175
alshabib11b8e5c2016-08-29 15:36:36 -0700176task fetch {
177 dependsOn fetchUpstreamImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700178}
179
alshabib11b8e5c2016-08-29 15:36:36 -0700180task buildImages {
181 logger.info "Root project has nothing to build"
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700182}
183
184task publishImages {
Andy Bavier24d21112017-03-13 10:09:31 -0400185 comps.each { name, spec -> if (spec.type == 'image') {
186 dependsOn "publish" + name
187 }
alshabib11b8e5c2016-08-29 15:36:36 -0700188 }
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700189}
190
191task publish {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700192 dependsOn publishImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700193}
194
195tasks.addRule(new DockerFetchRule(project))
alshabib11b8e5c2016-08-29 15:36:36 -0700196tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700197tasks.addRule(new DockerTagRule(project))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700198
Zack Williams38d8c7f2017-01-23 07:35:36 -0700199task CopyCord(type: Exec) {
200 dependsOn writeYamlConfig
Zack Williams0620c932017-01-25 14:36:31 -0700201 dependsOn writeInventory
Zack Williams38d8c7f2017-01-23 07:35:36 -0700202
203 executable = "ansible"
Zack Williams0620c932017-01-25 14:36:31 -0700204 args = [ "-i", "genconfig/cord-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "synchronize", "-a", "src='../../' dest='$config.common.cord_dir'", "head" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700205}
206
207task ChownCord(type: Exec) {
208 dependsOn CopyCord
209
210 executable = "ansible"
Zack Williams0620c932017-01-25 14:36:31 -0700211 args = [ "-i", "genconfig/cord-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "file", "-a", "state='directory' dest='$config.common.cord_dir' recurse='yes' owner='$config.headnode.ansible_user'", "head" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700212}
213
Andy Bavier24d21112017-03-13 10:09:31 -0400214task PIinstallPKI(type: Exec) {
215 workingDir "platform-install"
216 executable = "ansible-playbook"
217 args = [ "-i", "../genconfig/cord-inv",
218 "--extra-vars", "@../genconfig/config.yml",
219 "pki-install-playbook.yml" ]
220}
221
Andy Bavier96df5e62017-03-13 18:19:24 -0400222task PIcreateProfile(type: Exec) {
223 dependsOn PIinstallPKI
224
225 workingDir "platform-install"
226 executable = "ansible-playbook"
227 args = [ "-i", "../genconfig/cord-inv",
228 "--extra-vars", "@../genconfig/config.yml",
229 "--extra-vars", "deploy_docker_tag="+targetTag,
230 "--extra-vars", "deploy_docker_registry=docker-registry:5000/",
231 "cord-profile-playbook.yml" ]
232}
233
Zack Williams38d8c7f2017-01-23 07:35:36 -0700234task PIprepPlatform(type: Exec) {
235 dependsOn CopyCord
236 dependsOn ChownCord
Andy Bavier96df5e62017-03-13 18:19:24 -0400237 dependsOn PIcreateProfile
Zack Williams38d8c7f2017-01-23 07:35:36 -0700238
Zack Williams0620c932017-01-25 14:36:31 -0700239 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml prep-platform-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700240
241 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700242 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700243}
244
245task PIdeployOpenStack (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700246 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml deploy-openstack-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700247
248 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700249 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700250}
251
252task PIdeployONOS (type: Exec) {
Andy Bavier96df5e62017-03-13 18:19:24 -0400253 def extra_vars = "--extra-vars deploy_docker_tag="+targetTag+" --extra-vars deploy_docker_registry=docker-registry:5000/"
254 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml "+extra_vars+" deploy-onos-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700255
256 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700257 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700258}
259
260task PIdeployXOS (type: Exec) {
Andy Bavier96df5e62017-03-13 18:19:24 -0400261 def extra_vars = "--extra-vars deploy_docker_tag="+targetTag+" --extra-vars deploy_docker_registry=docker-registry:5000/"
262 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml "+extra_vars+" launch-xos-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700263
264 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700265 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700266}
267
268task PIsetupAutomation (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700269 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml cord-automation-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700270
271 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700272 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700273}
274
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700275task PIrunDiag (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700276 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 -0700277
278 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700279 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700280}
281
Zack Williams38d8c7f2017-01-23 07:35:36 -0700282task postDeployTests (type: Exec) {
283
Zack Williams0620c932017-01-25 14:36:31 -0700284 def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml pod-test-playbook.yml"
Zack Williams38d8c7f2017-01-23 07:35:36 -0700285
286 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700287 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700288}
289
alshabib11b8e5c2016-08-29 15:36:36 -0700290project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
alshabibc64cf7f2016-09-07 11:47:01 -0700291project(':onos-apps').deploy.dependsOn project(':maas').deployBase
292
Zack Williams38d8c7f2017-01-23 07:35:36 -0700293project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
294project(':onos-apps').deploy.dependsOn project(':maas').deployBase
295
Andy Bavier96df5e62017-03-13 18:19:24 -0400296project(':orchestration:xos').buildImages.dependsOn rootProject."tagxosproject/xos-base"
297
Zack Williams38d8c7f2017-01-23 07:35:36 -0700298task PIdeployPlatform {
299 dependsOn CopyCord
300 dependsOn ChownCord
301 dependsOn project(':onos-apps').deploy
302 dependsOn project(':maas').deployBase
303 dependsOn PIprepPlatform
304 dependsOn PIdeployOpenStack
305 dependsOn PIdeployONOS
306 dependsOn PIdeployXOS
307 dependsOn PIsetupAutomation
308}
309
310ChownCord.mustRunAfter CopyCord
311PIprepPlatform.mustRunAfter ChownCord
312PIdeployOpenStack.mustRunAfter PIprepPlatform
313PIdeployONOS.mustRunAfter PIdeployOpenStack
314PIdeployXOS.mustRunAfter PIdeployONOS
315PIsetupAutomation.mustRunAfter PIdeployXOS
316PIdeployPlatform.mustRunAfter project(':onos-apps').deploy
317PIdeployPlatform.mustRunAfter project(':maas').deployBase
Andy Bavierbeb89c02016-07-07 13:26:55 -0400318
alshabib11b8e5c2016-08-29 15:36:36 -0700319task deploy {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700320 dependsOn PIdeployPlatform
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700321}