blob: c4bdfda8c713d920d557e51ee9329e083978f7b0 [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
Zack Williams5860f302017-01-20 16:17:16 -070019import org.yaml.snakeyaml.DumperOptions
Andy Bavieradea0fd2016-07-06 05:26:26 -040020
21allprojects {
22 apply plugin: 'base'
23 apply plugin: 'de.gesellix.docker'
24 //apply plugin: 'com.tmiyamon.config'
25
26 docker {
27 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
28 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
29 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
30 // authConfigPlain = [
31 // "username" : "joe",
32 // "password" : "some-pw-as-needed",
33 // "email" : "joe@acme.com",
34 // "serveraddress" : "https://index.docker.io/v1/"
35 // ]
36 }
37}
38
Andy Bavier829bc002017-01-11 14:59:48 -050039def getCordAppVersion = { ->
40 def StdOut = new ByteArrayOutputStream()
41 exec {
42 commandLine "xpath", "-q", "-e", "project/version/text()", "../../onos-apps/apps/pom.xml"
43 standardOutput = StdOut
44 }
45 return StdOut.toString().trim()
46}
47
Andy Bavieradea0fd2016-07-06 05:26:26 -040048ext {
49
50 // Upstream registry to simplify filling out the comps table below
51 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
52
Andy Bavieradea0fd2016-07-06 05:26:26 -040053 // Deployment target config file (yaml format); this can be overwritten from the command line
54 // using the -PdeployConfig=<file-path> syntax.
55 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
56
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080057 println "Using deployment config: $deployConfig"
58 File configFile = new File(deployConfig)
59 def yaml = new Yaml()
60 config = yaml.load(configFile.newReader())
61
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080062 // Target registry to be used to publish docker images needed for deployment
63 targetReg = project.hasProperty('targetReg')
64 ? project.getProperty('targetReg')
65 : config.docker && config.docker.registry
66 ? config.docker.registry
David K. Bainbridge94b24712016-11-15 15:09:42 -080067 : config.seedServer.ip
68 ? config.seedServer.ip + ":5000"
69 : 'localhost:5000'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080070
71 // The tag used to tag the docker images push to the target registry
72 targetTag = project.hasProperty('targetTag')
73 ? project.getProperty('targetTag')
74 : config.docker && config.docker.imageVersion
75 ? config.docker.imageVersion
Andy Bavier12262e72016-12-02 11:36:57 -050076 : 'candidate'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080077
78 println "targetReg = $targetReg, targetTag = $targetTag"
79
Andy Bavier829bc002017-01-11 14:59:48 -050080
81 // Version of the CORD apps to load into ONOS
82 cordAppVersion = project.hasProperty('cordAppVersion')
83 ? project.getProperty('cordAppVersion')
84 : getCordAppVersion()
85
86 println "CORD app version: $cordAppVersion"
87
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080088 // Component table
89 comps = [
90 ]
Andy Bavieradea0fd2016-07-06 05:26:26 -040091}
92
Andy Bavier6dbb1a32016-07-06 07:12:50 -040093task copyAnsibleInventory(type: Copy) {
Zack Williams5860f302017-01-20 16:17:16 -070094 from 'inventory/templates/single-prod'
Andy Bavier6dbb1a32016-07-06 07:12:50 -040095 into 'inventory'
96 expand([
Zack Williams5860f302017-01-20 16:17:16 -070097 prod: config.seedServer.ip,
Andy Bavier6dbb1a32016-07-06 07:12:50 -040098 ])
99}
100
Zack Williams5860f302017-01-20 16:17:16 -0700101task writeYamlConfig {
102 def outvar = config.seedServer
103 def outfilename = "genconfig/deployconf.yml"
104
105 DumperOptions options = new DumperOptions()
106
107 options.setExplicitStart(true);
108 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
109 options.setPrettyFlow(true);
110 options.setIndent(2);
111
112 def yaml = new Yaml(options)
113 Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
114
115 yaml.dump(outvar, outfile)
116
117 outfile.close()
118}
119
Andy Bavieradea0fd2016-07-06 05:26:26 -0400120// ------------- PlaceHolders ----------------
121
Andy Bavieradea0fd2016-07-06 05:26:26 -0400122task prime {
123 // TODO this is a place-holder.
Andy Bavieradea0fd2016-07-06 05:26:26 -0400124}
125
126// ---------------- Useful tasks ----------------
127
alshabibfe09d772016-08-29 16:15:56 -0700128task fetch << {
129 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400130}
131
alshabibfe09d772016-08-29 16:15:56 -0700132task buildImages << {
133 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400134}
135
136task publishImages {
137 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
138}
139
140task publish {
141 dependsOn publishImages
142}
143
144tasks.addRule(new DockerFetchRule(project))
145tasks.addRule(new DockerPublishRule(project))
146tasks.addRule(new DockerTagRule(project))
147tasks.addRule(new GitSubmoduleUpdateRule(project))
148
Andy Bavier12262e72016-12-02 11:36:57 -0500149task prepPlatform(type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400150 dependsOn copyAnsibleInventory
Zack Williams5860f302017-01-20 16:17:16 -0700151 dependsOn writeYamlConfig
Andy Bavieradea0fd2016-07-06 05:26:26 -0400152
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400153 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700154 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-prep-platform.yml"]
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400155}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400156
Andy Bavier12262e72016-12-02 11:36:57 -0500157task deployOpenStack (type: Exec) {
Andy Bavier1b8a5372016-07-07 19:36:21 -0400158 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700159 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-openstack.yml"]
Andy Bavier12262e72016-12-02 11:36:57 -0500160}
161
162task deployONOS (type: Exec) {
163 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700164 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-onos.yml"]
Andy Bavier12262e72016-12-02 11:36:57 -0500165}
166
167task deployXOS (type: Exec) {
Zack Williams5860f302017-01-20 16:17:16 -0700168
Andy Bavier12262e72016-12-02 11:36:57 -0500169 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700170 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-xos.yml"]
Andy Bavier12262e72016-12-02 11:36:57 -0500171}
172
173task setupAutomation (type: Exec) {
Zack Williams5860f302017-01-20 16:17:16 -0700174
Andy Bavier12262e72016-12-02 11:36:57 -0500175 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700176 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-automation.yml"]
Andy Bavier12262e72016-12-02 11:36:57 -0500177}
178
179deployOpenStack.mustRunAfter prepPlatform
180deployONOS.mustRunAfter deployOpenStack
181deployXOS.mustRunAfter deployONOS
182setupAutomation.mustRunAfter deployXOS
183
184task deployPlatform {
185 dependsOn prepPlatform
186 dependsOn deployOpenStack
187 dependsOn deployONOS
188 dependsOn deployXOS
189 dependsOn setupAutomation
Andy Bavier1b8a5372016-07-07 19:36:21 -0400190}
191
Andy Baviera27effe2016-07-18 19:23:26 -0400192task postDeployTests (type: Exec) {
Zack Williams5860f302017-01-20 16:17:16 -0700193
Andy Baviera27effe2016-07-18 19:23:26 -0400194 executable = "ansible-playbook"
Zack Williams5860f302017-01-20 16:17:16 -0700195 args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-post-deploy-playbook.yml"]
Andy Baviera27effe2016-07-18 19:23:26 -0400196}
Zack Williams5860f302017-01-20 16:17:16 -0700197