blob: 3b8f64526d6d3567837ef7827c59170a4eca0ce7 [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
Andy Bavieradea0fd2016-07-06 05:26:26 -040043 // Deployment target config file (yaml format); this can be overwritten from the command line
44 // using the -PdeployConfig=<file-path> syntax.
45 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
46
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080047 println "Using deployment config: $deployConfig"
48 File configFile = new File(deployConfig)
49 def yaml = new Yaml()
50 config = yaml.load(configFile.newReader())
51
52
53 // Target registry to be used to publish docker images needed for deployment
54 targetReg = project.hasProperty('targetReg')
55 ? project.getProperty('targetReg')
56 : config.docker && config.docker.registry
57 ? config.docker.registry
58 : 'localhost:5000'
59
60 // The tag used to tag the docker images push to the target registry
61 targetTag = project.hasProperty('targetTag')
62 ? project.getProperty('targetTag')
63 : config.docker && config.docker.imageVersion
64 ? config.docker.imageVersion
65 : 'candidate'
66
67 println "targetReg = $targetReg, targetTag = $targetTag"
68
69 // Component table
70 comps = [
71 ]
Andy Bavieradea0fd2016-07-06 05:26:26 -040072}
73
Andy Bavier6dbb1a32016-07-06 07:12:50 -040074task copyAnsibleInventory(type: Copy) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -040075 from 'inventory/templates/single-prod'
76 into 'inventory'
77 expand([
78 prod: config.seedServer.ip,
79 ])
80}
81
Andy Bavieradea0fd2016-07-06 05:26:26 -040082// ------------- PlaceHolders ----------------
83
84task updateDocker (type: Exec) {
85 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
86}
87
88task prime {
89 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -040090 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -040091}
92
93// ---------------- Useful tasks ----------------
94
Andy Bavier1b8a5372016-07-07 19:36:21 -040095List.metaClass.asParam = { prefix, sep ->
96 if (delegate.size() == 0) {
97 ""
98 }
99 String result = "--" + prefix + "="
100 String p = ""
101 delegate.each {
102 result += p + "${it}"
103 p = sep
104 }
105 result
106}
107
108List.metaClass.p = { value, name ->
109 if (value != null && value != "") {
110 delegate << name + "=" + value
111 } else {
112 delegate
113 }
114}
115
116List.metaClass.p = { spec ->
117 if (spec != null && spec != "") {
118 delegate += spec
119 } else {
120 delegate
121 }
122}
123
alshabibfe09d772016-08-29 16:15:56 -0700124task fetch << {
125 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400126}
127
alshabibfe09d772016-08-29 16:15:56 -0700128task buildImages << {
129 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400130}
131
132task publishImages {
133 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
134}
135
136task publish {
137 dependsOn publishImages
138}
139
140tasks.addRule(new DockerFetchRule(project))
141tasks.addRule(new DockerPublishRule(project))
142tasks.addRule(new DockerTagRule(project))
143tasks.addRule(new GitSubmoduleUpdateRule(project))
144
Andy Bavierc27a2aa2016-07-06 19:20:04 -0400145task deployPlatform (type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400146 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400147
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400148 executable = "ansible-playbook"
149 args = ["-i", "inventory/single-prod"]
150
151 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
152 args = args << "--user=$config.seedServer.user"
153 }
154
155 def extraVars = []
156 if (config.seedServer) {
157 extraVars = extraVars.p(config.seedServer.extraVars)
158 .p(config.seedServer.password, "ansible_ssh_pass")
159 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
160 .p(config.seedServer.fabric_ip, "fabric_ip")
161 .p(config.seedServer.management_ip, "management_ip")
162 .p(config.seedServer.management_network, "management_network")
163 .p(config.seedServer.management_iface, "management_iface")
164 .p(config.seedServer.external_ip, "external_ip")
165 .p(config.seedServer.external_network, "external_network")
166 .p(config.seedServer.external_iface, "external_iface")
167 .p(config.seedServer.fabric_ip, "fabric_ip")
168 .p(config.seedServer.fabric_network, "fabric_network")
169 .p(config.seedServer.fabric_iface, "fabric_iface")
170 .p(config.seedServer.domain, "domain")
171 .p(config.seedServer.virtualbox_support, "virtualbox_support")
172 .p(config.seedServer.power_helper_user, "power_helper_user")
173 .p(config.seedServer.power_helper_host, "power_helper_host")
174 .p(config.seedServer.port, "ansible_ssh_port")
175 }
176
177 if (config.otherServers) {
178 extraVars = extraVars.p(config.otherServers.location, "prov_location")
179 .p(config.otherServers.rolesPath, "prov_role_path")
180 .p(config.otherServers.role, "prov_role")
181 }
182
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800183 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
184 .p("$targetTag", "deploy_docker_tag")
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400185
186 def skipTags = [].p(config.seedServer.skipTags)
187
188 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml"
189}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400190
191task deploySingle (type: Exec) {
192 dependsOn copyAnsibleInventory
193
Andy Bavier1b8a5372016-07-07 19:36:21 -0400194 executable = "ansible-playbook"
195 args = ["-i", "inventory/single-prod"]
196
197 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
198 args = args << "--user=$config.seedServer.user"
199 }
200
201 def extraVars = []
202 if (config.seedServer) {
203 extraVars = extraVars.p(config.seedServer.extraVars)
204 .p(config.seedServer.password, "ansible_ssh_pass")
205 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
206 .p(config.seedServer.fabric_ip, "fabric_ip")
207 .p(config.seedServer.management_ip, "management_ip")
208 .p(config.seedServer.management_network, "management_network")
209 .p(config.seedServer.management_iface, "management_iface")
210 .p(config.seedServer.external_ip, "external_ip")
211 .p(config.seedServer.external_network, "external_network")
212 .p(config.seedServer.external_iface, "external_iface")
213 .p(config.seedServer.fabric_ip, "fabric_ip")
214 .p(config.seedServer.fabric_network, "fabric_network")
215 .p(config.seedServer.fabric_iface, "fabric_iface")
216 .p(config.seedServer.domain, "domain")
217 .p(config.seedServer.virtualbox_support, "virtualbox_support")
218 .p(config.seedServer.power_helper_user, "power_helper_user")
219 .p(config.seedServer.power_helper_host, "power_helper_host")
220 .p(config.seedServer.port, "ansible_ssh_port")
221 }
222
223 if (config.otherServers) {
224 extraVars = extraVars.p(config.otherServers.location, "prov_location")
225 .p(config.otherServers.rolesPath, "prov_role_path")
226 .p(config.otherServers.role, "prov_role")
227 }
228
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800229 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
230 .p("$targetTag", "deploy_docker_tag")
Andy Bavier1b8a5372016-07-07 19:36:21 -0400231
232 def skipTags = [].p(config.seedServer.skipTags)
233
234 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-single-playbook.yml"
235}
236
Andy Baviera27effe2016-07-18 19:23:26 -0400237task postDeployTests (type: Exec) {
238 dependsOn copyAnsibleInventory
239
Andy Baviera27effe2016-07-18 19:23:26 -0400240 executable = "ansible-playbook"
241 args = ["-i", "inventory/single-prod"]
242
243 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
244 args = args << "--user=$config.seedServer.user"
245 }
246
247 def extraVars = []
248 if (config.seedServer) {
249 extraVars = extraVars.p(config.seedServer.extraVars)
250 .p(config.seedServer.password, "ansible_ssh_pass")
251 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
252 .p(config.seedServer.fabric_ip, "fabric_ip")
253 .p(config.seedServer.management_ip, "management_ip")
254 .p(config.seedServer.management_network, "management_network")
255 .p(config.seedServer.management_iface, "management_iface")
256 .p(config.seedServer.external_ip, "external_ip")
257 .p(config.seedServer.external_network, "external_network")
258 .p(config.seedServer.external_iface, "external_iface")
259 .p(config.seedServer.fabric_ip, "fabric_ip")
260 .p(config.seedServer.fabric_network, "fabric_network")
261 .p(config.seedServer.fabric_iface, "fabric_iface")
262 .p(config.seedServer.domain, "domain")
263 .p(config.seedServer.virtualbox_support, "virtualbox_support")
264 .p(config.seedServer.power_helper_user, "power_helper_user")
265 .p(config.seedServer.power_helper_host, "power_helper_host")
266 .p(config.seedServer.port, "ansible_ssh_port")
267 }
268
269 if (config.otherServers) {
270 extraVars = extraVars.p(config.otherServers.location, "prov_location")
271 .p(config.otherServers.rolesPath, "prov_role_path")
272 .p(config.otherServers.role, "prov_role")
273 }
274
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800275 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
276 .p("$targetTag", "deploy_docker_tag")
Andy Baviera27effe2016-07-18 19:23:26 -0400277
278 def skipTags = [].p(config.seedServer.skipTags)
279
280 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
281}
282