blob: 89b65b5e4e17bfb220103f3d375630c460aada40 [file] [log] [blame]
alshabib11163052016-08-24 17:59:41 -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 */
16import org.opencord.gradle.rules.*
17import org.yaml.snakeyaml.Yaml
18
19allprojects {
20 apply plugin: 'base'
21 apply plugin: 'de.gesellix.docker'
22 //apply plugin: 'com.tmiyamon.config'
23
24 docker {
25 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
26 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
27 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
28 // authConfigPlain = [
29 // "username" : "joe",
30 // "password" : "some-pw-as-needed",
31 // "email" : "joe@acme.com",
32 // "serveraddress" : "https://index.docker.io/v1/"
33 // ]
34 }
35}
36
37ext {
38
39 // Upstream registry to simplify filling out the comps table below
40 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
41
42 // Target registry to be used to publish docker images needed for deployment
43 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
44
45 // The tag used to tag the docker images push to the target registry
46 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
47
48 // Deployment target config file (yaml format); this can be overwritten from the command line
49 // using the -PdeployConfig=<file-path> syntax.
50 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
51
52 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
53
54 comps = [
55 'consul': [
56 'type': 'image',
57 'upstream': upstreamReg,
58 'name': 'consul',
59 'digest': 'sha256:0dc990ff3c44d5b5395475bcc5ebdae4fc8b67f69e17942a8b9793b3df74d290'
60 ]
61 ]
62}
63
64task fetchUpstreamImages {
65 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
66}
67
68// Switch Configuration Image
69
70task buildSwitchqImage(type: Exec) {
71 commandLine "$dockerPath/docker", 'build', '-t', 'cord-maas-switchq', './switchq'
72}
73
74task tagSwitchqImage(type: Exec) {
75 dependsOn buildSwitchqImage
76 commandLine "$dockerPath/docker", 'tag', 'cord-maas-switchq', "$targetReg/cord-maas-switchq:$targetTag"
77}
78
79task publishSwitchqImage(type: Exec) {
80 dependsOn tagSwitchqImage
81 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-switchq:$targetTag"
82}
83
84// Bootstrap Image
85
86task buildBootstrapImage(type: Exec) {
87 commandLine "$dockerPath/docker", 'build', '-t', 'cord-maas-bootstrap', './bootstrap'
88}
89
90task tagBootstrapImage(type: Exec) {
91 dependsOn buildBootstrapImage
92 commandLine "$dockerPath/docker", 'tag', 'cord-maas-bootstrap', "$targetReg/cord-maas-bootstrap:$targetTag"
93}
94
95task publishBootstrapImage(type: Exec) {
96 dependsOn tagBootstrapImage
97 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-bootstrap:$targetTag"
98}
99
100// IP Allocator Image
101
102task buildAllocationImage(type: Exec) {
103 commandLine "$dockerPath/docker", 'build', '-t', 'cord-ip-allocator', './ip-allocator'
104}
105
106task tagAllocationImage(type: Exec) {
107 dependsOn buildAllocationImage
108 commandLine "$dockerPath/docker", 'tag', 'cord-ip-allocator', "$targetReg/cord-ip-allocator:$targetTag"
109}
110
111task publishAllocationImage(type: Exec) {
112 dependsOn tagAllocationImage
113 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-ip-allocator:$targetTag"
114}
115
116// Provisioner Image
117
118task buildProvisionerImage(type: Exec) {
119 commandLine "$dockerPath/docker", 'build', '-t', 'cord-provisioner', './provisioner'
120}
121
122task tagProvisionerImage(type: Exec) {
123 dependsOn buildProvisionerImage
124 commandLine "$dockerPath/docker", 'tag', 'cord-provisioner', "$targetReg/cord-provisioner:$targetTag"
125}
126
127task publishProvisionerImage(type: Exec) {
128 dependsOn tagProvisionerImage
129 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-provisioner:$targetTag"
130}
131
132// Config Generator Image
133
134task buildConfigGeneratorImage(type: Exec) {
135 commandLine "$dockerPath/docker", 'build', '-t', 'config-generator', './config-generator'
136}
137
138task tagConfigGeneratorImage(type: Exec) {
139 dependsOn buildConfigGeneratorImage
140 commandLine "$dockerPath/docker", 'tag', 'config-generator', "$targetReg/config-generator:$targetTag"
141}
142
143task publishConfigGeneratorImage(type: Exec) {
144 dependsOn tagConfigGeneratorImage
145 commandLine "$dockerPath/docker", 'push', "$targetReg/config-generator:$targetTag"
146}
147
148// Automation Image
149
150task buildAutomationImage(type: Exec) {
151 commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
152}
153
154task tagAutomationImage(type: Exec) {
155 dependsOn buildAutomationImage
156 commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation', "$targetReg/cord-maas-automation:$targetTag"
157}
158
159task publishAutomationImage(type: Exec) {
160 dependsOn tagAutomationImage
161 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag"
162}
163
164// DHCP Harvester Images
165
166task buildHarvesterImage(type: Exec) {
167 commandLine "$dockerPath/docker", 'build', '-t', "cord-dhcp-harvester", "./harvester"
168}
169
170task tagHarvesterImage(type: Exec) {
171 dependsOn buildHarvesterImage
172 commandLine "$dockerPath/docker", 'tag', 'cord-dhcp-harvester', "$targetReg/cord-dhcp-harvester:$targetTag"
173}
174
175task publishHarvesterImage(type: Exec) {
176 dependsOn tagHarvesterImage
177 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-dhcp-harvester:$targetTag"
178}
179
180// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
181
182task updateDocker (type: Exec) {
183 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
184}
185
186// To be used to fetch upstream binaries, clone repos, etc.
187task fetch(type: Exec) {
188 // this is where we fetch upstream artifacts that we do not need internet for the build phase"
189 // Placeholdr example:
190 dependsOn fetchUpstreamImages
191 commandLine "$dockerPath/docker", "pull", "golang:alpine"
192 commandLine "$dockerPath/docker", "pull", "python:2.7-alpine"
193}
194
195// To be used to generate all needed binaries that need to be present on the target
196// as docker images in the local docker runner.
197task buildImages {
198 dependsOn buildBootstrapImage
199 dependsOn buildHarvesterImage
200 dependsOn buildAutomationImage
201 dependsOn buildAllocationImage
202 dependsOn buildProvisionerImage
203 dependsOn buildConfigGeneratorImage
204 dependsOn buildSwitchqImage
205}
206
207task tagImages {
208 dependsOn tagBootstrapImage
209 dependsOn tagHarvesterImage
210 dependsOn tagAutomationImage
211 dependsOn tagAllocationImage
212 dependsOn tagProvisionerImage
213 dependsOn tagConfigGeneratorImage
214 dependsOn tagSwitchqImage
215}
216
217task publish {
218 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
219 dependsOn publishBootstrapImage
220 dependsOn publishHarvesterImage
221 dependsOn publishAutomationImage
222 dependsOn publishAllocationImage
223 dependsOn publishProvisionerImage
224 dependsOn publishConfigGeneratorImage
225 dependsOn publishSwitchqImage
226}
227
228tasks.addRule(new DockerFetchRule(project))
229tasks.addRule(new DockerPublishRule(project))
230tasks.addRule(new DockerTagRule(project))
231
232// ~~~~~~~~~~~~~~~~~~~ Deployment / Test Tasks ~~~~~~~~~~~~~~~~~~~~~~~
233
234List.metaClass.asParam = { prefix, sep ->
235 if (delegate.size() == 0) {
236 ""
237 }
238 String result = "--" + prefix + "="
239 String p = ""
240 delegate.each {
241 result += p + "${it}"
242 p = sep
243 }
244 result
245}
246
247List.metaClass.p = { value, name ->
248 if (value != null && value != "") {
249 delegate << name + "=" + value
250 } else {
251 delegate
252 }
253}
254
255List.metaClass.p = { spec ->
256 if (spec != null && spec != "") {
257 delegate += spec
258 } else {
259 delegate
260 }
261}
262
263task prime (type: Exec) {
264 println "Using deployment config: $deployConfig"
265 File configFile = new File(deployConfig)
266 def yaml = new Yaml()
267 def config = yaml.load(configFile.newReader())
268
269 executable = "ansible-playbook"
270 args = ["-i", config.seedServer.ip + ',']
271
272 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
273 args = args << "--user=$config.seedServer.user"
274 }
275
276 if ( config.debug ) {
277 args = args << "-vvvv"
278 }
279
280 def extraVars = []
281 if (config.seedServer) {
282 extraVars = extraVars.p(config.seedServer.extraVars)
283 .p(config.seedServer.password, "ansible_ssh_pass")
284 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
285 .p(config.seedServer.fabric_ip, "fabric_ip")
286 .p(config.seedServer.management_ip, "management_ip")
287 .p(config.seedServer.management_gw, "management_gw")
288 .p(config.seedServer.management_network, "management_network")
289 .p(config.seedServer.management_iface, "management_iface")
290 .p(config.seedServer.external_ip, "external_ip")
291 .p(config.seedServer.external_gw, "external_gw")
292 .p(config.seedServer.external_network, "external_network")
293 .p(config.seedServer.external_iface, "external_iface")
294 .p(config.seedServer.fabric_ip, "fabric_ip")
295 .p(config.seedServer.fabric_network, "fabric_network")
296 .p(config.seedServer.fabric_iface, "fabric_iface")
297 .p(config.seedServer.fabric_iface_spec, "fabric_iface_spec")
298 .p(config.seedServer.domain, "domain")
299 .p(config.seedServer.virtualbox_support, "virtualbox_support")
300 .p(config.seedServer.power_helper_user, "power_helper_user")
301 .p(config.seedServer.power_helper_host, "power_helper_host")
302 .p(config.seedServer.port, "ansible_ssh_port")
303 }
304
305 if (config.otherServers) {
306 extraVars = extraVars.p(config.otherServers.location, "prov_location")
307 .p(config.otherServers.rolesPath, "prov_role_path")
308 .p(config.otherServers.role, "prov_role")
309 }
310
311 if (config.docker) {
312 extraVars = extraVars.p(config.docker.registry, "docker_registry")
313 .p(config.docker.imageVersion, "docker_image_version")
314 }
315
316 def skipTags = [].p(config.seedServer.skipTags)
317
318 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "prime-node.yml"
319}
320
321task deployBase(type: Exec) {
322 println "Using deployment config: $deployConfig"
323 File configFile = new File(deployConfig)
324 def yaml = new Yaml()
325 def config = yaml.load(configFile.newReader())
326
327 executable = "ansible-playbook"
328 args = ["-i", config.seedServer.ip + ',']
329
330 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
331 args = args << "--user=$config.seedServer.user"
332 }
333
334
335 if ( config.debug ) {
336 args = args << "-vvvv"
337 }
338
339 def extraVars = []
340 if (config.seedServer) {
341 extraVars = extraVars.p(config.seedServer.extraVars)
342 .p(config.seedServer.password, "ansible_ssh_pass")
343 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
344 .p(config.seedServer.fabric_ip, "fabric_ip")
345 .p(config.seedServer.management_ip, "management_ip")
346 .p(config.seedServer.management_gw, "management_gw")
347 .p(config.seedServer.management_network, "management_network")
348 .p(config.seedServer.management_iface, "management_iface")
349 .p(config.seedServer.external_ip, "external_ip")
350 .p(config.seedServer.external_gw, "external_gw")
351 .p(config.seedServer.external_network, "external_network")
352 .p(config.seedServer.external_iface, "external_iface")
353 .p(config.seedServer.fabric_ip, "fabric_ip")
354 .p(config.seedServer.fabric_network, "fabric_network")
355 .p(config.seedServer.fabric_iface, "fabric_iface")
356 .p(config.seedServer.fabric_iface_spec, "fabric_iface_spec")
357 .p(config.seedServer.domain, "domain")
358 .p(config.seedServer.virtualbox_support, "virtualbox_support")
359 .p(config.seedServer.power_helper_user, "power_helper_user")
360 .p(config.seedServer.power_helper_host, "power_helper_host")
361 .p(config.seedServer.port, "ansible_ssh_port")
362 }
363
364 if (config.otherServers) {
365 extraVars = extraVars.p(config.otherServers.location, "prov_location")
366 .p(config.otherServers.rolesPath, "prov_role_path")
367 .p(config.otherServers.role, "prov_role")
368 }
369
370 if (config.docker) {
371 extraVars = extraVars.p(config.docker.registry, "docker_registry")
372 .p(config.docker.imageVersion, "docker_image_version")
373 }
374
375 def skipTags = [].p(config.seedServer.skipTags)
376
377 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "head-node.yml"
378}
379
380publish.mustRunAfter prime
381
382prime.dependsOn {
383 updateDocker
384}