blob: c9239f285740431e419041984e7ec1f3f8365472 [file] [log] [blame]
Zsolt Haraszti56700cd2016-06-01 16:02:05 -07001/*
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -07002 * Copyright 2012 the original author or authors.
Zsolt Haraszti56700cd2016-06-01 16:02:05 -07003 *
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -07004 * 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.
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070015 */
A R Karthick6d98a592016-08-24 15:16:46 -070016import 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}
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070036
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070037ext {
A R Karthick6d98a592016-08-24 15:16:46 -070038 // Deployment target config file (yaml format); this can be overwritten from the command line
39 // using the -PdeployConfig=<file-path> syntax.
40 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
41
David K. Bainbridgef5289612016-11-15 17:22:33 -080042 println "Using deployment config: $deployConfig"
43 File configFile = new File(deployConfig)
44 def yaml = new Yaml()
45 config = yaml.load(configFile.newReader())
46
47 // Upstream registry to simplify filling out the comps table below
48 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
49
50 // Target registry to be used to publish docker images needed for deployment
51 targetReg = project.hasProperty('targetReg')
52 ? project.getProperty('targetReg')
53 : config.docker && config.docker.registry
54 ? config.docker.registry
55 : config.seedServer.ip
56 ? config.seedServer.ip + ":5000"
57 : 'localhost:5000'
58
59 // The tag used to tag the docker images push to the target registry
60 targetTag = project.hasProperty('targetTag')
61 ? project.getProperty('targetTag')
62 : config.docker && config.docker.imageVersion
63 ? config.docker.imageVersion
64 : 'candidate'
65
ChetanGaonker5979e212016-06-03 09:30:49 -070066 cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup'
67
68 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
A R Karthick577520a2016-06-07 14:40:12 -070069
A R Karthickf7a613b2017-02-24 09:36:44 -080070 cordTesterImages = [ 'cordtest/radius:candidate' : 'Dockerfile.radius', 'cordtest/quagga:candidate' : 'Dockerfile.quagga', 'cordtest/nose:candidate' : 'Dockerfile.tester' ]
A R Karthick07608ef2016-08-23 16:51:19 -070071
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070072}
73
A R Karthicke7aff362016-12-13 10:27:07 -080074List.metaClass.asParam = { prefix, sep ->
75 if (delegate.size() == 0) {
76 ""
77 }
78 String result = "--" + prefix + "="
79 String p = ""
80 delegate.each {
81 result += p + "${it}"
82 p = sep
83 }
84 result
85}
86
87List.metaClass.p = { value, name ->
88 if (value != null && value != "") {
89 delegate << name + "=" + value
90 } else {
91 delegate
92 }
93}
94
95List.metaClass.p = { spec ->
96 if (spec != null && spec != "") {
97 delegate += spec
98 } else {
99 delegate
100 }
101}
102
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700103// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
Zsolt Haraszti56700cd2016-06-01 16:02:05 -0700104
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700105// To be used to fetch upstream binaries, clone repos, etc.
A.R Karthick490f51f2016-06-09 21:29:13 -0700106task fetch {
107 //commandLine "$cordTesterPath/onos_pull.sh", 'latest'
Zsolt Haraszti56700cd2016-06-01 16:02:05 -0700108}
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700109
110// To be used to generate all needed binaries that need to be present on the target
111// as docker images in the local docker runner.
A.R Karthick490f51f2016-06-09 21:29:13 -0700112task buildImages {
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700113 // ...
A.R Karthick490f51f2016-06-09 21:29:13 -0700114 cordTesterImages.each { tag, dockerfile ->
115 println "Building Docker image ${tag} using ${dockerfile}"
116 exec {
117 executable "$dockerPath/docker"
118 args "build", "-t", "${tag}", "-f", "${dockerfile}", "."
119 }
120 }
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700121}
122
A R Karthick07608ef2016-08-23 16:51:19 -0700123task buildRadiusImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800124 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/radius', '-f', 'Dockerfile.radius', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700125}
126
127task tagRadiusImage(type: Exec) {
128 dependsOn buildRadiusImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800129 commandLine "$dockerPath/docker", 'tag', 'cordtest/radius', "$targetReg/cordtest/radius:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700130}
131
132task publishRadiusImage(type: Exec) {
133 dependsOn tagRadiusImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800134 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/radius:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700135}
136
137task buildQuaggaImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800138 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/quagga', '-f', 'Dockerfile.quagga', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700139}
140
141task tagQuaggaImage(type: Exec) {
142 dependsOn buildQuaggaImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800143 commandLine "$dockerPath/docker", 'tag', 'cordtest/quagga', "$targetReg/cordtest/quagga:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700144}
145
146task publishQuaggaImage(type: Exec) {
147 dependsOn tagQuaggaImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800148 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/quagga:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700149}
150
151task buildTesterImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800152 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/nose', '-f', 'Dockerfile.tester', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700153}
154
155task tagTesterImage(type: Exec) {
156 dependsOn buildTesterImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800157 commandLine "$dockerPath/docker", 'tag', 'cordtest/nose', "$targetReg/cordtest/nose:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700158}
159
160task publishTesterImage(type: Exec) {
161 dependsOn tagTesterImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800162 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/nose:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700163}
164
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700165// Publish image(s) built during the build step into targetReg registry using the targetTag
166// tag. See maas subproject for examples on how to do this.
A R Karthick07608ef2016-08-23 16:51:19 -0700167task publishImages {
168 dependsOn publishTesterImage
169 dependsOn publishQuaggaImage
170 dependsOn publishRadiusImage
171}
172
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700173task publish {
A R Karthick07608ef2016-08-23 16:51:19 -0700174 dependsOn publishImages
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700175}
A R Karthick6d98a592016-08-24 15:16:46 -0700176
177task deployBase (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700178 executable = "ansible-playbook"
179 args = ["-i", config.seedServer.ip + ',']
180
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800181 if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
182 args = args << "--user=$config.seedServer.ansible_user"
A R Karthick6d98a592016-08-24 15:16:46 -0700183 }
184
185
186 if ( config.debug ) {
187 args = args << "-vvvv"
188 }
189
190 def extraVars = []
191 if (config.seedServer) {
192 extraVars = extraVars.p(config.seedServer.extraVars)
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800193 .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
194 .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
A R Karthick6d98a592016-08-24 15:16:46 -0700195 .p(config.seedServer.fabric_ip, "fabric_ip")
196 .p(config.seedServer.management_ip, "management_ip")
197 .p(config.seedServer.management_gw, "management_gw")
198 .p(config.seedServer.management_network, "management_network")
199 .p(config.seedServer.management_iface, "management_iface")
200 .p(config.seedServer.external_ip, "external_ip")
201 .p(config.seedServer.external_gw, "external_gw")
202 .p(config.seedServer.external_network, "external_network")
203 .p(config.seedServer.external_iface, "external_iface")
204 .p(config.seedServer.fabric_ip, "fabric_ip")
205 .p(config.seedServer.fabric_network, "fabric_network")
206 .p(config.seedServer.fabric_iface, "fabric_iface")
207 .p(config.seedServer.domain, "domain")
208 .p(config.seedServer.virtualbox_support, "virtualbox_support")
209 .p(config.seedServer.power_helper_user, "power_helper_user")
210 .p(config.seedServer.power_helper_host, "power_helper_host")
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800211 .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
A R Karthick6d98a592016-08-24 15:16:46 -0700212 }
213
214 if (config.otherServers) {
215 extraVars = extraVars.p(config.otherServers.location, "prov_location")
216 .p(config.otherServers.rolesPath, "prov_role_path")
217 .p(config.otherServers.role, "prov_role")
218 }
219
220 if (config.docker) {
221 extraVars = extraVars.p(config.docker.registry, "docker_registry")
222 .p(config.docker.imageVersion, "docker_image_version")
223 }
224
225 def skipTags = [].p(config.seedServer.skipTags)
226
227 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-deploy.yml"
228}
229
230task verify (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700231 executable = "ansible-playbook"
232 args = ["-i", config.seedServer.ip + ',']
233
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800234 if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
235 args = args << "--user=$config.seedServer.ansible_user"
A R Karthick6d98a592016-08-24 15:16:46 -0700236 }
237
238
239 if ( config.debug ) {
240 args = args << "-vvvv"
241 }
242
243 def extraVars = []
244 if (config.seedServer) {
245 extraVars = extraVars.p(config.seedServer.extraVars)
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800246 .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
247 .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
A R Karthick6d98a592016-08-24 15:16:46 -0700248 .p(config.seedServer.fabric_ip, "fabric_ip")
249 .p(config.seedServer.management_ip, "management_ip")
250 .p(config.seedServer.management_gw, "management_gw")
251 .p(config.seedServer.management_network, "management_network")
252 .p(config.seedServer.management_iface, "management_iface")
253 .p(config.seedServer.external_ip, "external_ip")
254 .p(config.seedServer.external_gw, "external_gw")
255 .p(config.seedServer.external_network, "external_network")
256 .p(config.seedServer.external_iface, "external_iface")
257 .p(config.seedServer.fabric_ip, "fabric_ip")
258 .p(config.seedServer.fabric_network, "fabric_network")
259 .p(config.seedServer.fabric_iface, "fabric_iface")
260 .p(config.seedServer.domain, "domain")
261 .p(config.seedServer.virtualbox_support, "virtualbox_support")
262 .p(config.seedServer.power_helper_user, "power_helper_user")
263 .p(config.seedServer.power_helper_host, "power_helper_host")
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800264 .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
A R Karthick6d98a592016-08-24 15:16:46 -0700265 }
266
267 if (config.otherServers) {
268 extraVars = extraVars.p(config.otherServers.location, "prov_location")
269 .p(config.otherServers.rolesPath, "prov_role_path")
270 .p(config.otherServers.role, "prov_role")
271 }
272
273 if (config.docker) {
274 extraVars = extraVars.p(config.docker.registry, "docker_registry")
275 .p(config.docker.imageVersion, "docker_image_version")
276 }
277
278 def skipTags = [].p(config.seedServer.skipTags)
279
280 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-verify.yml"
281}