blob: 2a59b501be0740474c2dfe2dd61c40a9583c32b7 [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')
36
Zsolt Harasztiec7df102016-05-05 13:34:18 -070037allprojects {
38 apply plugin: 'base'
39 apply plugin: 'de.gesellix.docker'
40 //apply plugin: 'com.tmiyamon.config'
41
42 docker {
43 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
44 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
45 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
46 // authConfigPlain = [
47 // "username" : "joe",
48 // "password" : "some-pw-as-needed",
49 // "email" : "joe@acme.com",
50 // "serveraddress" : "https://index.docker.io/v1/"
51 // ]
52 }
53}
54
55ext {
56
David K. Bainbridge094508e2016-11-15 17:23:51 -080057 // Deployment target config file (yaml format); this can be overwritten from the command line
58 // using the -PdeployConfig=<file-path> syntax.
59 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
60
61 println "Using deployment config: $deployConfig"
62 File configFile = new File(deployConfig)
63 def yaml = new Yaml()
64 config = yaml.load(configFile.newReader())
65
Zsolt Harasztiec7df102016-05-05 13:34:18 -070066 // Upstream registry to simplify filling out the comps table below
Zsolt Harasztia9f72502016-05-12 16:07:03 -070067 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070068
69 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge094508e2016-11-15 17:23:51 -080070 targetReg = project.hasProperty('targetReg')
71 ? project.getProperty('targetReg')
72 : config.docker && config.docker.registry
73 ? config.docker.registry
74 : config.seedServer.ip
75 ? config.seedServer.ip + ":5000"
76 : 'localhost:5000'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070077
78 // The tag used to tag the docker images push to the target registry
David K. Bainbridge094508e2016-11-15 17:23:51 -080079 targetTag = project.hasProperty('targetTag')
80 ? project.getProperty('targetTag')
81 : config.docker && config.docker.imageVersion
82 ? config.docker.imageVersion
83 : 'candidate'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070084
85 // Component table
86 comps = [
Jonathan Hart92e75ce2017-01-13 17:28:18 -080087 // ONOS 1.8.2 from the opencord Dockerhub
88 'opencord/onos': [
David K. Bainbridged54ca702016-07-13 22:27:12 -070089 'type': 'image',
90 'upstream': upstreamReg,
Jonathan Hart92e75ce2017-01-13 17:28:18 -080091 'name': 'opencord/onos',
92 'digest': 'sha256:935da663c381393316e0c658d49dde10d90a7383e3d7c53271b1223cec31d44c'
David K. Bainbridged54ca702016-07-13 22:27:12 -070093 ],
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -070094 'nginx': [
95 'type': 'image',
96 'upstream': upstreamReg,
97 'name': 'nginx',
98 'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
99 ],
100 'swarm': [
101 'type': 'image',
102 'upstream': upstreamReg,
103 'name': 'swarm',
104 'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
105 ],
Scott Bakera0a0e442016-10-10 20:58:22 -0700106 'xosproject/vsg': [
107 'type': 'image',
108 'upstream': upstreamReg,
109 'name': 'xosproject/vsg',
110 'digest': 'sha256:18d1c6ef9767d8a41c9b51948776052d024d4e3294e5d1d6dde1a49112175d91'
111 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700112 'xosproject/xos-postgres': [
113 'type': 'image',
114 'upstream': upstreamReg,
115 'name': 'xosproject/xos-postgres',
116 'digest': 'sha256:f2d31a50b8af7434ab07b1e54e99c1ff1e10d77d16a46e5d6933d3c0528f4820'
117 ],
118 'xosproject/cord-app-build': [
119 'type': 'image',
120 'upstream': upstreamReg,
121 'name': 'xosproject/cord-app-build',
122 'digest': 'sha256:528c6ac3a87609779035857a7b1cf9fab8e046e7ac259d72cf275f1c46d7416e'
123 ],
Jonathan Hart09dad6c2016-11-14 16:52:56 -0800124 'xosproject/xos-base': [
125 'type': 'image',
126 'upstream': upstreamReg,
127 'name': 'xosproject/xos-base',
Scott Bakere63578f2017-01-12 16:24:58 -0800128 'digest': 'sha256:daecc5fb7d95942c5092d480fa22a41a1588896df87829fc371caa5df2a013a7'
Jonathan Hart09dad6c2016-11-14 16:52:56 -0800129 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700130 'redis': [
131 'type': 'image',
132 'upstream': upstreamReg,
133 'name': 'redis',
134 'digest': 'sha256:0fe5a7afa2c2154f37c8ab56a9a6c5023cb0405cc0e85b34d8dcc1de6c3f143e'
135 ],
Scott Baker18ea0c32017-01-19 09:29:57 -0800136 'node': [
137 'type': 'image',
138 'upstream': upstreamReg,
139 'name': 'node',
140 'digest': 'sha256:5757581a8ff7e08041512a54aa3f573d33fecdce81d603e48a759956cd99bdd3'
141 ],
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700142 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700143}
144
alshabib00c4b5d2016-06-17 17:26:10 -0700145// ---------------- Useful tasks ----------------
146
Zack Williams38d8c7f2017-01-23 07:35:36 -0700147task copyAnsibleInventory(type: Copy) {
148 from 'platform-install/inventory/templates/single-prod'
149 into 'platform-install/inventory'
150 expand([
151 prod: config.seedServer.ip,
152 ])
153}
154
155task writeYamlConfig {
156 def outvar = config.seedServer
157 def outfilename = "genconfig/config.yml"
158
159 DumperOptions options = new DumperOptions()
160
161 options.setExplicitStart(true);
162 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
163 options.setPrettyFlow(true);
164 options.setIndent(2);
165
166 def yaml = new Yaml(options)
167 Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
168
169 yaml.dump(outvar, outfile)
170 outfile.close()
171}
172
173task writeProdInventory(type: Copy) {
174 from 'ansible/prod-inv'
175 into 'genconfig'
176 expand([
177 prod: config.seedServer.ip,
178 ])
179}
180
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700181task fetchUpstreamImages {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700182 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
183}
184
alshabib11b8e5c2016-08-29 15:36:36 -0700185task fetch {
186 dependsOn fetchUpstreamImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700187}
188
alshabib11b8e5c2016-08-29 15:36:36 -0700189task buildImages {
190 logger.info "Root project has nothing to build"
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700191}
192
193task publishImages {
alshabib11b8e5c2016-08-29 15:36:36 -0700194 comps.each { name, spec -> if (spec.type == 'image') {
195 dependsOn "publish" + name
196 }
197 }
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700198}
199
200task publish {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700201 dependsOn publishImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700202}
203
204tasks.addRule(new DockerFetchRule(project))
alshabib11b8e5c2016-08-29 15:36:36 -0700205tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700206tasks.addRule(new DockerTagRule(project))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700207
Zack Williams38d8c7f2017-01-23 07:35:36 -0700208task CopyCord(type: Exec) {
209 dependsOn writeYamlConfig
210 dependsOn writeProdInventory
211
212 executable = "ansible"
Zack Williams932646a2017-01-26 11:08:56 -0700213 args = [ "-i", "genconfig/prod-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "synchronize", "-a", "src='../../' dest='/opt/cord'", "head" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700214}
215
216task ChownCord(type: Exec) {
217 dependsOn CopyCord
218
219 executable = "ansible"
Zack Williams932646a2017-01-26 11:08:56 -0700220 args = [ "-i", "genconfig/prod-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "file", "-a", "state='directory' dest='/opt/cord' recurse='yes' owner='$config.seedServer.ansible_user'", "head" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700221}
222
223task PIprepPlatform(type: Exec) {
224 dependsOn CopyCord
225 dependsOn ChownCord
226
227 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-prep-platform.yml"
228
229 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700230 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700231}
232
233task PIdeployOpenStack (type: Exec) {
234 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-openstack.yml"
235
236 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700237 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700238}
239
240task PIdeployONOS (type: Exec) {
241 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-onos.yml"
242
243 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700244 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700245}
246
247task PIdeployXOS (type: Exec) {
248 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-xos.yml"
249
250 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700251 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700252}
253
254task PIsetupAutomation (type: Exec) {
255 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.yml"
256
257 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700258 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700259}
260
261task postDeployTests (type: Exec) {
262
263 def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-post-deploy-playbook.yml"
264
265 executable = "ssh"
Zack Williams932646a2017-01-26 11:08:56 -0700266 args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700267}
268
alshabib11b8e5c2016-08-29 15:36:36 -0700269project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
alshabibc64cf7f2016-09-07 11:47:01 -0700270project(':onos-apps').deploy.dependsOn project(':maas').deployBase
271
Zack Williams38d8c7f2017-01-23 07:35:36 -0700272project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
273project(':onos-apps').deploy.dependsOn project(':maas').deployBase
274
275task PIdeployPlatform {
276 dependsOn CopyCord
277 dependsOn ChownCord
278 dependsOn project(':onos-apps').deploy
279 dependsOn project(':maas').deployBase
280 dependsOn PIprepPlatform
281 dependsOn PIdeployOpenStack
282 dependsOn PIdeployONOS
283 dependsOn PIdeployXOS
284 dependsOn PIsetupAutomation
285}
286
287ChownCord.mustRunAfter CopyCord
288PIprepPlatform.mustRunAfter ChownCord
289PIdeployOpenStack.mustRunAfter PIprepPlatform
290PIdeployONOS.mustRunAfter PIdeployOpenStack
291PIdeployXOS.mustRunAfter PIdeployONOS
292PIsetupAutomation.mustRunAfter PIdeployXOS
293PIdeployPlatform.mustRunAfter project(':onos-apps').deploy
294PIdeployPlatform.mustRunAfter project(':maas').deployBase
Andy Bavierbeb89c02016-07-07 13:26:55 -0400295
alshabib11b8e5c2016-08-29 15:36:36 -0700296task deploy {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700297 dependsOn PIdeployPlatform
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700298}
alshabibb58aeab2016-06-17 16:47:02 -0700299