blob: b82f55e9f043ac7106ad24b8921a8956ba80b626 [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
David K. Bainbridge94b24712016-11-15 15:09:42 -080058 : config.seedServer.ip
59 ? config.seedServer.ip + ":5000"
60 : 'localhost:5000'
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -080061
62 // The tag used to tag the docker images push to the target registry
63 targetTag = project.hasProperty('targetTag')
64 ? project.getProperty('targetTag')
65 : config.docker && config.docker.imageVersion
66 ? config.docker.imageVersion
67 : 'candidate'
68
69 println "targetReg = $targetReg, targetTag = $targetTag"
70
71 // Component table
72 comps = [
73 ]
Andy Bavieradea0fd2016-07-06 05:26:26 -040074}
75
Andy Bavier6dbb1a32016-07-06 07:12:50 -040076task copyAnsibleInventory(type: Copy) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -040077 from 'inventory/templates/single-prod'
78 into 'inventory'
79 expand([
80 prod: config.seedServer.ip,
81 ])
82}
83
Andy Bavieradea0fd2016-07-06 05:26:26 -040084// ------------- PlaceHolders ----------------
85
86task updateDocker (type: Exec) {
87 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
88}
89
90task prime {
91 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -040092 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -040093}
94
95// ---------------- Useful tasks ----------------
96
Andy Bavier1b8a5372016-07-07 19:36:21 -040097List.metaClass.asParam = { prefix, sep ->
98 if (delegate.size() == 0) {
99 ""
100 }
101 String result = "--" + prefix + "="
102 String p = ""
103 delegate.each {
104 result += p + "${it}"
105 p = sep
106 }
107 result
108}
109
110List.metaClass.p = { value, name ->
111 if (value != null && value != "") {
112 delegate << name + "=" + value
113 } else {
114 delegate
115 }
116}
117
118List.metaClass.p = { spec ->
119 if (spec != null && spec != "") {
120 delegate += spec
121 } else {
122 delegate
123 }
124}
125
alshabibfe09d772016-08-29 16:15:56 -0700126task fetch << {
127 logger.info 'Platform install has nothing to fetch'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400128}
129
alshabibfe09d772016-08-29 16:15:56 -0700130task buildImages << {
131 logger.info 'Platform install has nothing to build'
Andy Bavieradea0fd2016-07-06 05:26:26 -0400132}
133
134task publishImages {
135 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
136}
137
138task publish {
139 dependsOn publishImages
140}
141
142tasks.addRule(new DockerFetchRule(project))
143tasks.addRule(new DockerPublishRule(project))
144tasks.addRule(new DockerTagRule(project))
145tasks.addRule(new GitSubmoduleUpdateRule(project))
146
Andy Bavierc27a2aa2016-07-06 19:20:04 -0400147task deployPlatform (type: Exec) {
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400148 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400149
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400150 executable = "ansible-playbook"
151 args = ["-i", "inventory/single-prod"]
152
153 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
154 args = args << "--user=$config.seedServer.user"
155 }
156
157 def extraVars = []
158 if (config.seedServer) {
159 extraVars = extraVars.p(config.seedServer.extraVars)
160 .p(config.seedServer.password, "ansible_ssh_pass")
161 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
162 .p(config.seedServer.fabric_ip, "fabric_ip")
163 .p(config.seedServer.management_ip, "management_ip")
164 .p(config.seedServer.management_network, "management_network")
165 .p(config.seedServer.management_iface, "management_iface")
166 .p(config.seedServer.external_ip, "external_ip")
167 .p(config.seedServer.external_network, "external_network")
168 .p(config.seedServer.external_iface, "external_iface")
169 .p(config.seedServer.fabric_ip, "fabric_ip")
170 .p(config.seedServer.fabric_network, "fabric_network")
171 .p(config.seedServer.fabric_iface, "fabric_iface")
172 .p(config.seedServer.domain, "domain")
173 .p(config.seedServer.virtualbox_support, "virtualbox_support")
174 .p(config.seedServer.power_helper_user, "power_helper_user")
175 .p(config.seedServer.power_helper_host, "power_helper_host")
176 .p(config.seedServer.port, "ansible_ssh_port")
177 }
178
179 if (config.otherServers) {
180 extraVars = extraVars.p(config.otherServers.location, "prov_location")
181 .p(config.otherServers.rolesPath, "prov_role_path")
182 .p(config.otherServers.role, "prov_role")
183 }
184
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800185 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
186 .p("$targetTag", "deploy_docker_tag")
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400187
188 def skipTags = [].p(config.seedServer.skipTags)
189
190 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml"
191}
Andy Bavier1b8a5372016-07-07 19:36:21 -0400192
193task deploySingle (type: Exec) {
194 dependsOn copyAnsibleInventory
195
Andy Bavier1b8a5372016-07-07 19:36:21 -0400196 executable = "ansible-playbook"
197 args = ["-i", "inventory/single-prod"]
198
199 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
200 args = args << "--user=$config.seedServer.user"
201 }
202
203 def extraVars = []
204 if (config.seedServer) {
205 extraVars = extraVars.p(config.seedServer.extraVars)
206 .p(config.seedServer.password, "ansible_ssh_pass")
207 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
208 .p(config.seedServer.fabric_ip, "fabric_ip")
209 .p(config.seedServer.management_ip, "management_ip")
210 .p(config.seedServer.management_network, "management_network")
211 .p(config.seedServer.management_iface, "management_iface")
212 .p(config.seedServer.external_ip, "external_ip")
213 .p(config.seedServer.external_network, "external_network")
214 .p(config.seedServer.external_iface, "external_iface")
215 .p(config.seedServer.fabric_ip, "fabric_ip")
216 .p(config.seedServer.fabric_network, "fabric_network")
217 .p(config.seedServer.fabric_iface, "fabric_iface")
218 .p(config.seedServer.domain, "domain")
219 .p(config.seedServer.virtualbox_support, "virtualbox_support")
220 .p(config.seedServer.power_helper_user, "power_helper_user")
221 .p(config.seedServer.power_helper_host, "power_helper_host")
222 .p(config.seedServer.port, "ansible_ssh_port")
223 }
224
225 if (config.otherServers) {
226 extraVars = extraVars.p(config.otherServers.location, "prov_location")
227 .p(config.otherServers.rolesPath, "prov_role_path")
228 .p(config.otherServers.role, "prov_role")
229 }
230
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800231 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
232 .p("$targetTag", "deploy_docker_tag")
Andy Bavier1b8a5372016-07-07 19:36:21 -0400233
234 def skipTags = [].p(config.seedServer.skipTags)
235
236 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-single-playbook.yml"
237}
238
Andy Baviera27effe2016-07-18 19:23:26 -0400239task postDeployTests (type: Exec) {
240 dependsOn copyAnsibleInventory
241
Andy Baviera27effe2016-07-18 19:23:26 -0400242 executable = "ansible-playbook"
243 args = ["-i", "inventory/single-prod"]
244
245 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
246 args = args << "--user=$config.seedServer.user"
247 }
248
249 def extraVars = []
250 if (config.seedServer) {
251 extraVars = extraVars.p(config.seedServer.extraVars)
252 .p(config.seedServer.password, "ansible_ssh_pass")
253 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
254 .p(config.seedServer.fabric_ip, "fabric_ip")
255 .p(config.seedServer.management_ip, "management_ip")
256 .p(config.seedServer.management_network, "management_network")
257 .p(config.seedServer.management_iface, "management_iface")
258 .p(config.seedServer.external_ip, "external_ip")
259 .p(config.seedServer.external_network, "external_network")
260 .p(config.seedServer.external_iface, "external_iface")
261 .p(config.seedServer.fabric_ip, "fabric_ip")
262 .p(config.seedServer.fabric_network, "fabric_network")
263 .p(config.seedServer.fabric_iface, "fabric_iface")
264 .p(config.seedServer.domain, "domain")
265 .p(config.seedServer.virtualbox_support, "virtualbox_support")
266 .p(config.seedServer.power_helper_user, "power_helper_user")
267 .p(config.seedServer.power_helper_host, "power_helper_host")
268 .p(config.seedServer.port, "ansible_ssh_port")
269 }
270
271 if (config.otherServers) {
272 extraVars = extraVars.p(config.otherServers.location, "prov_location")
273 .p(config.otherServers.rolesPath, "prov_role_path")
274 .p(config.otherServers.role, "prov_role")
275 }
276
David K. Bainbridgeecfbd4d2016-11-14 13:18:39 -0800277 extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
278 .p("$targetTag", "deploy_docker_tag")
Andy Baviera27effe2016-07-18 19:23:26 -0400279
280 def skipTags = [].p(config.seedServer.skipTags)
281
282 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
283}
284