blob: db86e6d415d0c2a14e8fbb67675547d766a60413 [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
19
20allprojects {
21 apply plugin: 'base'
22 apply plugin: 'de.gesellix.docker'
23 //apply plugin: 'com.tmiyamon.config'
24
25 docker {
26 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
27 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
28 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
29 // authConfigPlain = [
30 // "username" : "joe",
31 // "password" : "some-pw-as-needed",
32 // "email" : "joe@acme.com",
33 // "serveraddress" : "https://index.docker.io/v1/"
34 // ]
35 }
36}
37
38ext {
39
40 // Upstream registry to simplify filling out the comps table below
41 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
42
43 // Target registry to be used to publish docker images needed for deployment
44 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
45
46 // The tag used to tag the docker images push to the target registry
47 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
48
49 // Component table
50 comps = [
51 ]
52
53 // 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
57}
58
Andy Bavier6dbb1a32016-07-06 07:12:50 -040059task copyAnsibleInventory(type: Copy) {
Andy Baviere003c892016-10-06 10:03:58 -040060 inputs.file deployConfig
61
Andy Bavier6dbb1a32016-07-06 07:12:50 -040062 File configFile = new File(deployConfig)
63 def yaml = new Yaml()
64 def config = yaml.load(configFile.newReader())
65
66 from 'inventory/templates/single-prod'
67 into 'inventory'
68 expand([
69 prod: config.seedServer.ip,
70 ])
71}
72
Andy Bavieradea0fd2016-07-06 05:26:26 -040073// ------------- PlaceHolders ----------------
74
75task updateDocker (type: Exec) {
76 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
77}
78
79task prime {
80 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -040081 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -040082 doFirst {
83 println "Using deployment config: $deployConfig"
84 File configFile = new File(deployConfig)
85 def yaml = new Yaml()
86 def config = yaml.load(configFile.newReader())
87 println "Config: $config"
88 println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
89 }
90}
91
92// ---------------- Useful tasks ----------------
93
Andy Bavier1b8a5372016-07-07 19:36:21 -040094List.metaClass.asParam = { prefix, sep ->
95 if (delegate.size() == 0) {
96 ""
97 }
98 String result = "--" + prefix + "="
99 String p = ""
100 delegate.each {
101 result += p + "${it}"
102 p = sep
103 }
104 result
105}
106
107List.metaClass.p = { value, name ->
108 if (value != null && value != "") {
109 delegate << name + "=" + value
110 } else {
111 delegate
112 }
113}
114
115List.metaClass.p = { spec ->
116 if (spec != null && spec != "") {
117 delegate += spec
118 } else {
119 delegate
120 }
121}
122
alshabibfe09d772016-08-29 16:15:56 -0700123task fetch << {
124 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400125}
126
alshabibfe09d772016-08-29 16:15:56 -0700127task buildImages << {
128 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400129}
130
131task publishImages {
132 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
133}
134
135task publish {
136 dependsOn publishImages
137}
138
139tasks.addRule(new DockerFetchRule(project))
140tasks.addRule(new DockerPublishRule(project))
141tasks.addRule(new DockerTagRule(project))
142tasks.addRule(new GitSubmoduleUpdateRule(project))
143
Andy Bavierc27a2aa2016-07-06 19:20:04 -0400144task deployPlatform (type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400145 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400146
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400147 println "Using deployment config: $deployConfig"
148 File configFile = new File(deployConfig)
149 def yaml = new Yaml()
150 def config = yaml.load(configFile.newReader())
151
152 executable = "ansible-playbook"
153 args = ["-i", "inventory/single-prod"]
154
155 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
156 args = args << "--user=$config.seedServer.user"
157 }
158
159 def extraVars = []
160 if (config.seedServer) {
161 extraVars = extraVars.p(config.seedServer.extraVars)
162 .p(config.seedServer.password, "ansible_ssh_pass")
163 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
164 .p(config.seedServer.fabric_ip, "fabric_ip")
165 .p(config.seedServer.management_ip, "management_ip")
166 .p(config.seedServer.management_network, "management_network")
167 .p(config.seedServer.management_iface, "management_iface")
168 .p(config.seedServer.external_ip, "external_ip")
169 .p(config.seedServer.external_network, "external_network")
170 .p(config.seedServer.external_iface, "external_iface")
171 .p(config.seedServer.fabric_ip, "fabric_ip")
172 .p(config.seedServer.fabric_network, "fabric_network")
173 .p(config.seedServer.fabric_iface, "fabric_iface")
174 .p(config.seedServer.domain, "domain")
175 .p(config.seedServer.virtualbox_support, "virtualbox_support")
176 .p(config.seedServer.power_helper_user, "power_helper_user")
177 .p(config.seedServer.power_helper_host, "power_helper_host")
178 .p(config.seedServer.port, "ansible_ssh_port")
179 }
180
181 if (config.otherServers) {
182 extraVars = extraVars.p(config.otherServers.location, "prov_location")
183 .p(config.otherServers.rolesPath, "prov_role_path")
184 .p(config.otherServers.role, "prov_role")
185 }
186
187 if (config.docker) {
188 extraVars = extraVars.p(config.docker.registry, "docker_registry")
189 .p(config.docker.imageVersion, "docker_image_version")
190 }
191
192 def skipTags = [].p(config.seedServer.skipTags)
193
194 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml"
195}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400196
197task deploySingle (type: Exec) {
198 dependsOn copyAnsibleInventory
199
200 println "Using deployment config: $deployConfig"
201 File configFile = new File(deployConfig)
202 def yaml = new Yaml()
203 def config = yaml.load(configFile.newReader())
204
205 executable = "ansible-playbook"
206 args = ["-i", "inventory/single-prod"]
207
208 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
209 args = args << "--user=$config.seedServer.user"
210 }
211
212 def extraVars = []
213 if (config.seedServer) {
214 extraVars = extraVars.p(config.seedServer.extraVars)
215 .p(config.seedServer.password, "ansible_ssh_pass")
216 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
217 .p(config.seedServer.fabric_ip, "fabric_ip")
218 .p(config.seedServer.management_ip, "management_ip")
219 .p(config.seedServer.management_network, "management_network")
220 .p(config.seedServer.management_iface, "management_iface")
221 .p(config.seedServer.external_ip, "external_ip")
222 .p(config.seedServer.external_network, "external_network")
223 .p(config.seedServer.external_iface, "external_iface")
224 .p(config.seedServer.fabric_ip, "fabric_ip")
225 .p(config.seedServer.fabric_network, "fabric_network")
226 .p(config.seedServer.fabric_iface, "fabric_iface")
227 .p(config.seedServer.domain, "domain")
228 .p(config.seedServer.virtualbox_support, "virtualbox_support")
229 .p(config.seedServer.power_helper_user, "power_helper_user")
230 .p(config.seedServer.power_helper_host, "power_helper_host")
231 .p(config.seedServer.port, "ansible_ssh_port")
232 }
233
234 if (config.otherServers) {
235 extraVars = extraVars.p(config.otherServers.location, "prov_location")
236 .p(config.otherServers.rolesPath, "prov_role_path")
237 .p(config.otherServers.role, "prov_role")
238 }
239
240 if (config.docker) {
241 extraVars = extraVars.p(config.docker.registry, "docker_registry")
242 .p(config.docker.imageVersion, "docker_image_version")
243 }
244
245 def skipTags = [].p(config.seedServer.skipTags)
246
247 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-single-playbook.yml"
248}
249
Andy Baviera27effe2016-07-18 19:23:26 -0400250task postDeployTests (type: Exec) {
251 dependsOn copyAnsibleInventory
252
253 println "Using deployment config: $deployConfig"
254 File configFile = new File(deployConfig)
255 def yaml = new Yaml()
256 def config = yaml.load(configFile.newReader())
257
258 executable = "ansible-playbook"
259 args = ["-i", "inventory/single-prod"]
260
261 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
262 args = args << "--user=$config.seedServer.user"
263 }
264
265 def extraVars = []
266 if (config.seedServer) {
267 extraVars = extraVars.p(config.seedServer.extraVars)
268 .p(config.seedServer.password, "ansible_ssh_pass")
269 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
270 .p(config.seedServer.fabric_ip, "fabric_ip")
271 .p(config.seedServer.management_ip, "management_ip")
272 .p(config.seedServer.management_network, "management_network")
273 .p(config.seedServer.management_iface, "management_iface")
274 .p(config.seedServer.external_ip, "external_ip")
275 .p(config.seedServer.external_network, "external_network")
276 .p(config.seedServer.external_iface, "external_iface")
277 .p(config.seedServer.fabric_ip, "fabric_ip")
278 .p(config.seedServer.fabric_network, "fabric_network")
279 .p(config.seedServer.fabric_iface, "fabric_iface")
280 .p(config.seedServer.domain, "domain")
281 .p(config.seedServer.virtualbox_support, "virtualbox_support")
282 .p(config.seedServer.power_helper_user, "power_helper_user")
283 .p(config.seedServer.power_helper_host, "power_helper_host")
284 .p(config.seedServer.port, "ansible_ssh_port")
285 }
286
287 if (config.otherServers) {
288 extraVars = extraVars.p(config.otherServers.location, "prov_location")
289 .p(config.otherServers.rolesPath, "prov_role_path")
290 .p(config.otherServers.role, "prov_role")
291 }
292
293 if (config.docker) {
294 extraVars = extraVars.p(config.docker.registry, "docker_registry")
295 .p(config.docker.imageVersion, "docker_image_version")
296 }
297
298 def skipTags = [].p(config.seedServer.skipTags)
299
300 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
301}
302