blob: 48094700518031ea751142766f662f4b0a3bef78 [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')
Scott Bakera6e5dd12017-04-17 10:08:16 -070037evaluationDependsOn(':platform-install')
alshabib11b8e5c2016-08-29 15:36:36 -070038
Zsolt Harasztiec7df102016-05-05 13:34:18 -070039allprojects {
40 apply plugin: 'base'
41 apply plugin: 'de.gesellix.docker'
42 //apply plugin: 'com.tmiyamon.config'
43
44 docker {
45 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
46 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
47 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
48 // authConfigPlain = [
49 // "username" : "joe",
50 // "password" : "some-pw-as-needed",
51 // "email" : "joe@acme.com",
52 // "serveraddress" : "https://index.docker.io/v1/"
53 // ]
54 }
55}
56
57ext {
58
David K. Bainbridge094508e2016-11-15 17:23:51 -080059 // Deployment target config file (yaml format); this can be overwritten from the command line
60 // using the -PdeployConfig=<file-path> syntax.
alshabib19c61df2017-02-14 11:25:22 -080061 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
David K. Bainbridge094508e2016-11-15 17:23:51 -080062
63 println "Using deployment config: $deployConfig"
64 File configFile = new File(deployConfig)
65 def yaml = new Yaml()
66 config = yaml.load(configFile.newReader())
67
Zsolt Harasztiec7df102016-05-05 13:34:18 -070068 // Upstream registry to simplify filling out the comps table below
Zsolt Harasztia9f72502016-05-12 16:07:03 -070069 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070070
71 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge094508e2016-11-15 17:23:51 -080072 targetReg = project.hasProperty('targetReg')
73 ? project.getProperty('targetReg')
74 : config.docker && config.docker.registry
75 ? config.docker.registry
Zack Williams0620c932017-01-25 14:36:31 -070076 : config.headnode.ip
77 ? config.headnode.ip + ":5000"
David K. Bainbridge094508e2016-11-15 17:23:51 -080078 : 'localhost:5000'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070079
80 // The tag used to tag the docker images push to the target registry
David K. Bainbridge094508e2016-11-15 17:23:51 -080081 targetTag = project.hasProperty('targetTag')
82 ? project.getProperty('targetTag')
83 : config.docker && config.docker.imageVersion
84 ? config.docker.imageVersion
85 : 'candidate'
Zsolt Harasztiec7df102016-05-05 13:34:18 -070086
87 // Component table
88 comps = [
Andy Bavier693b9062017-05-16 10:09:53 -040089 // ONOS 1.8.7 from DockerHub
Andy Bavierb69496a2017-05-10 14:42:38 -040090 'onosproject/onos': [
David K. Bainbridged54ca702016-07-13 22:27:12 -070091 'type': 'image',
92 'upstream': upstreamReg,
Andy Bavierb69496a2017-05-10 14:42:38 -040093 'name': 'onosproject/onos',
Andy Bavier693b9062017-05-16 10:09:53 -040094 'digest': 'sha256:7e6e79e8cc41419901ee6f9022abaf2be52098795e70cab0e1964126dae56f87'
David K. Bainbridged54ca702016-07-13 22:27:12 -070095 ],
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -070096 'nginx': [
97 'type': 'image',
98 'upstream': upstreamReg,
99 'name': 'nginx',
100 'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
101 ],
102 'swarm': [
103 'type': 'image',
104 'upstream': upstreamReg,
105 'name': 'swarm',
106 'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
107 ],
Scott Bakera0a0e442016-10-10 20:58:22 -0700108 'xosproject/vsg': [
109 'type': 'image',
110 'upstream': upstreamReg,
111 'name': 'xosproject/vsg',
112 'digest': 'sha256:18d1c6ef9767d8a41c9b51948776052d024d4e3294e5d1d6dde1a49112175d91'
113 ],
Scott Bakerbceca9c2016-11-05 18:59:25 -0700114 'redis': [
115 'type': 'image',
116 'upstream': upstreamReg,
117 'name': 'redis',
118 'digest': 'sha256:0fe5a7afa2c2154f37c8ab56a9a6c5023cb0405cc0e85b34d8dcc1de6c3f143e'
119 ],
Scott Baker18ea0c32017-01-19 09:29:57 -0800120 'node': [
121 'type': 'image',
122 'upstream': upstreamReg,
123 'name': 'node',
124 'digest': 'sha256:5757581a8ff7e08041512a54aa3f573d33fecdce81d603e48a759956cd99bdd3'
125 ],
Matteo Scandolo951dd5b2017-05-25 07:35:47 -0700126 'gliderlabs/consul-server': [
Matteo Scandolo89576202017-05-18 18:39:43 -0700127 'type': 'image',
128 'upstream': upstreamReg,
129 'name': 'gliderlabs/consul-server',
Matteo Scandoloccd20e82017-05-24 15:13:48 -0700130 'digest': 'sha256:37e194c7c941e37cf20b0cc5080541cfde9d31bf62a874905d0d51b3945f88c9'
Matteo Scandolo89576202017-05-18 18:39:43 -0700131 ],
Matteo Scandolo951dd5b2017-05-25 07:35:47 -0700132 'gliderlabs/registrator': [
Matteo Scandolo89576202017-05-18 18:39:43 -0700133 'type': 'image',
134 'upstream': upstreamReg,
135 'name': 'gliderlabs/registrator',
Matteo Scandoloccd20e82017-05-24 15:13:48 -0700136 'digest': 'sha256:6e708681dd52e28f4f39d048ac75376c9a762c44b3d75b2824173f8364e52c10'
Matteo Scandolo89576202017-05-18 18:39:43 -0700137 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700138 ]
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700139}
140
alshabib00c4b5d2016-06-17 17:26:10 -0700141// ---------------- Useful tasks ----------------
142
Zack Williams0620c932017-01-25 14:36:31 -0700143task writeInventory(type: Copy) {
144 from 'ansible/cord-inv'
145 into 'genconfig'
Zack Williams38d8c7f2017-01-23 07:35:36 -0700146 expand([
Zack Williams0620c932017-01-25 14:36:31 -0700147 headnode_ip: config.headnode.ip,
148 headnode_user: config.headnode.ansible_user,
149 headnode_pass: config.headnode.ansible_ssh_pass,
150 headnode_port: config.headnode.ansible_ssh_port,
Zack Williams38d8c7f2017-01-23 07:35:36 -0700151 ])
152}
153
154task writeYamlConfig {
Zack Williams0620c932017-01-25 14:36:31 -0700155 def outvar = config.common
Zack Williams38d8c7f2017-01-23 07:35:36 -0700156 def outfilename = "genconfig/config.yml"
157
158 DumperOptions options = new DumperOptions()
159
160 options.setExplicitStart(true);
161 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
162 options.setPrettyFlow(true);
163 options.setIndent(2);
164
165 def yaml = new Yaml(options)
166 Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
167
168 yaml.dump(outvar, outfile)
169 outfile.close()
170}
171
Zack Williams38d8c7f2017-01-23 07:35:36 -0700172
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700173task fetchUpstreamImages {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700174 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
175}
176
alshabib11b8e5c2016-08-29 15:36:36 -0700177task fetch {
178 dependsOn fetchUpstreamImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700179}
180
alshabib11b8e5c2016-08-29 15:36:36 -0700181task buildImages {
182 logger.info "Root project has nothing to build"
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700183}
184
185task publishImages {
Andy Bavier24d21112017-03-13 10:09:31 -0400186 comps.each { name, spec -> if (spec.type == 'image') {
187 dependsOn "publish" + name
188 }
alshabib11b8e5c2016-08-29 15:36:36 -0700189 }
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700190}
191
192task publish {
Zsolt Haraszti3dbe6162016-05-12 12:25:56 -0700193 dependsOn publishImages
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700194}
195
196tasks.addRule(new DockerFetchRule(project))
alshabib11b8e5c2016-08-29 15:36:36 -0700197tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700198tasks.addRule(new DockerTagRule(project))
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700199
Zack Williams38d8c7f2017-01-23 07:35:36 -0700200task CopyCord(type: Exec) {
201 dependsOn writeYamlConfig
Zack Williams0620c932017-01-25 14:36:31 -0700202 dependsOn writeInventory
Zack Williams38d8c7f2017-01-23 07:35:36 -0700203
204 executable = "ansible"
Zack Williams0620c932017-01-25 14:36:31 -0700205 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 -0700206}
207
208task ChownCord(type: Exec) {
209 dependsOn CopyCord
210
211 executable = "ansible"
Zack Williams0620c932017-01-25 14:36:31 -0700212 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 -0700213}
214
Andy Bavier24d21112017-03-13 10:09:31 -0400215task PIinstallPKI(type: Exec) {
216 workingDir "platform-install"
217 executable = "ansible-playbook"
218 args = [ "-i", "../genconfig/cord-inv",
219 "--extra-vars", "@../genconfig/config.yml",
220 "pki-install-playbook.yml" ]
221}
222
Andy Bavier96df5e62017-03-13 18:19:24 -0400223task PIcreateProfile(type: Exec) {
224 dependsOn PIinstallPKI
225
226 workingDir "platform-install"
227 executable = "ansible-playbook"
228 args = [ "-i", "../genconfig/cord-inv",
229 "--extra-vars", "@../genconfig/config.yml",
230 "--extra-vars", "deploy_docker_tag="+targetTag,
231 "--extra-vars", "deploy_docker_registry=docker-registry:5000/",
232 "cord-profile-playbook.yml" ]
233}
234
Zack Williams38d8c7f2017-01-23 07:35:36 -0700235task PIprepPlatform(type: Exec) {
236 dependsOn CopyCord
237 dependsOn ChownCord
Andy Bavier96df5e62017-03-13 18:19:24 -0400238 dependsOn PIcreateProfile
Zack Williams38d8c7f2017-01-23 07:35:36 -0700239
Zack Williams0620c932017-01-25 14:36:31 -0700240 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 -0700241
242 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700243 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700244}
245
246task PIdeployOpenStack (type: Exec) {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700247
Zack Williams31fbc6b2017-04-21 22:04:44 -0700248 workingDir "platform-install"
249 executable = "ansible-playbook"
250 args = [ "-i", "../genconfig/cord-inv",
251 "--extra-vars", "@../genconfig/config.yml",
252 "--extra-vars", "deploy_docker_tag="+targetTag,
253 "--extra-vars", "deploy_docker_registry=docker-registry:5000/",
254 "deploy-openstack-playbook.yml" ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700255}
256
257task PIdeployONOS (type: Exec) {
Andy Bavier96df5e62017-03-13 18:19:24 -0400258 def extra_vars = "--extra-vars deploy_docker_tag="+targetTag+" --extra-vars deploy_docker_registry=docker-registry:5000/"
259 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 -0700260
261 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700262 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700263}
264
265task PIdeployXOS (type: Exec) {
Andy Bavier96df5e62017-03-13 18:19:24 -0400266 def extra_vars = "--extra-vars deploy_docker_tag="+targetTag+" --extra-vars deploy_docker_registry=docker-registry:5000/"
267 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 -0700268
269 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700270 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700271}
272
273task PIsetupAutomation (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700274 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 -0700275
276 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700277 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700278}
279
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700280task PIrunDiag (type: Exec) {
Zack Williams0620c932017-01-25 14:36:31 -0700281 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 -0700282
283 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700284 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700285}
286
Zack Williams38d8c7f2017-01-23 07:35:36 -0700287task postDeployTests (type: Exec) {
288
Zack Williams0620c932017-01-25 14:36:31 -0700289 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 -0700290
291 executable = "ssh"
Zack Williams0620c932017-01-25 14:36:31 -0700292 args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
Zack Williams38d8c7f2017-01-23 07:35:36 -0700293}
294
Zack Williams03a20ec2017-04-12 17:39:36 -0700295
296
297project(':maas').prime.dependsOn writeYamlConfig
298project(':maas').prime.dependsOn writeInventory
299
alshabib11b8e5c2016-08-29 15:36:36 -0700300project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
alshabibc64cf7f2016-09-07 11:47:01 -0700301project(':onos-apps').deploy.dependsOn project(':maas').deployBase
302
Zack Williams38d8c7f2017-01-23 07:35:36 -0700303project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
304project(':onos-apps').deploy.dependsOn project(':maas').deployBase
305
Andy Bavier2f151eb2017-05-04 16:39:13 -0700306// Ensure nginx:candidate exists
Andy Bavier619b6352017-04-26 15:30:23 -0700307project(':orchestration:xos').buildImages.dependsOn rootProject."tagnginx"
Andy Bavier96df5e62017-03-13 18:19:24 -0400308
Andy Bavier2f151eb2017-05-04 16:39:13 -0700309// For corebuilder
Scott Bakera6e5dd12017-04-17 10:08:16 -0700310project(':platform-install').buildImages.dependsOn project(':orchestration:xos').buildImages
311
Zack Williams38d8c7f2017-01-23 07:35:36 -0700312task PIdeployPlatform {
313 dependsOn CopyCord
314 dependsOn ChownCord
315 dependsOn project(':onos-apps').deploy
316 dependsOn project(':maas').deployBase
317 dependsOn PIprepPlatform
318 dependsOn PIdeployOpenStack
319 dependsOn PIdeployONOS
320 dependsOn PIdeployXOS
321 dependsOn PIsetupAutomation
322}
323
324ChownCord.mustRunAfter CopyCord
325PIprepPlatform.mustRunAfter ChownCord
326PIdeployOpenStack.mustRunAfter PIprepPlatform
327PIdeployONOS.mustRunAfter PIdeployOpenStack
328PIdeployXOS.mustRunAfter PIdeployONOS
329PIsetupAutomation.mustRunAfter PIdeployXOS
330PIdeployPlatform.mustRunAfter project(':onos-apps').deploy
331PIdeployPlatform.mustRunAfter project(':maas').deployBase
Andy Bavierbeb89c02016-07-07 13:26:55 -0400332
alshabib11b8e5c2016-08-29 15:36:36 -0700333task deploy {
Zack Williams38d8c7f2017-01-23 07:35:36 -0700334 dependsOn PIdeployPlatform
Zsolt Harasztiec7df102016-05-05 13:34:18 -0700335}