blob: f4979baab49b64dc90aaf2397c5d7a430c65737a [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070019/*
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070020 * Copyright 2012 the original author or authors.
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070021 *
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070022 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070033 */
A R Karthick6d98a592016-08-24 15:16:46 -070034import org.opencord.gradle.rules.*
35import org.yaml.snakeyaml.Yaml
36
37allprojects {
38 apply plugin: 'base'
39 apply plugin: 'de.gesellix.docker'
40 //apply plugin: 'com.tmiyamon.config'
41
42 docker {
43 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
44 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
45 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
46 // authConfigPlain = [
47 // "username" : "joe",
48 // "password" : "some-pw-as-needed",
49 // "email" : "joe@acme.com",
50 // "serveraddress" : "https://index.docker.io/v1/"
51 // ]
52 }
53}
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070054
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070055ext {
A R Karthick6d98a592016-08-24 15:16:46 -070056 // Deployment target config file (yaml format); this can be overwritten from the command line
57 // using the -PdeployConfig=<file-path> syntax.
58 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
59
David K. Bainbridgef5289612016-11-15 17:22:33 -080060 println "Using deployment config: $deployConfig"
61 File configFile = new File(deployConfig)
62 def yaml = new Yaml()
63 config = yaml.load(configFile.newReader())
64
65 // Upstream registry to simplify filling out the comps table below
66 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
67
68 // Target registry to be used to publish docker images needed for deployment
69 targetReg = project.hasProperty('targetReg')
70 ? project.getProperty('targetReg')
71 : config.docker && config.docker.registry
72 ? config.docker.registry
73 : config.seedServer.ip
74 ? config.seedServer.ip + ":5000"
75 : 'localhost:5000'
76
77 // The tag used to tag the docker images push to the target registry
78 targetTag = project.hasProperty('targetTag')
79 ? project.getProperty('targetTag')
80 : config.docker && config.docker.imageVersion
81 ? config.docker.imageVersion
82 : 'candidate'
83
ChetanGaonker5979e212016-06-03 09:30:49 -070084 cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup'
85
86 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
A R Karthick577520a2016-06-07 14:40:12 -070087
A R Karthickf7a613b2017-02-24 09:36:44 -080088 cordTesterImages = [ 'cordtest/radius:candidate' : 'Dockerfile.radius', 'cordtest/quagga:candidate' : 'Dockerfile.quagga', 'cordtest/nose:candidate' : 'Dockerfile.tester' ]
A R Karthick07608ef2016-08-23 16:51:19 -070089
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070090}
91
A R Karthicke7aff362016-12-13 10:27:07 -080092List.metaClass.asParam = { prefix, sep ->
93 if (delegate.size() == 0) {
94 ""
95 }
96 String result = "--" + prefix + "="
97 String p = ""
98 delegate.each {
99 result += p + "${it}"
100 p = sep
101 }
102 result
103}
104
105List.metaClass.p = { value, name ->
106 if (value != null && value != "") {
107 delegate << name + "=" + value
108 } else {
109 delegate
110 }
111}
112
113List.metaClass.p = { spec ->
114 if (spec != null && spec != "") {
115 delegate += spec
116 } else {
117 delegate
118 }
119}
120
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700121// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
Zsolt Haraszti56700cd2016-06-01 16:02:05 -0700122
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700123// To be used to fetch upstream binaries, clone repos, etc.
A.R Karthick490f51f2016-06-09 21:29:13 -0700124task fetch {
125 //commandLine "$cordTesterPath/onos_pull.sh", 'latest'
Zsolt Haraszti56700cd2016-06-01 16:02:05 -0700126}
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700127
128// To be used to generate all needed binaries that need to be present on the target
129// as docker images in the local docker runner.
A.R Karthick490f51f2016-06-09 21:29:13 -0700130task buildImages {
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700131 // ...
A.R Karthick490f51f2016-06-09 21:29:13 -0700132 cordTesterImages.each { tag, dockerfile ->
133 println "Building Docker image ${tag} using ${dockerfile}"
134 exec {
135 executable "$dockerPath/docker"
136 args "build", "-t", "${tag}", "-f", "${dockerfile}", "."
137 }
138 }
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700139}
140
A R Karthick07608ef2016-08-23 16:51:19 -0700141task buildRadiusImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800142 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/radius', '-f', 'Dockerfile.radius', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700143}
144
145task tagRadiusImage(type: Exec) {
146 dependsOn buildRadiusImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800147 commandLine "$dockerPath/docker", 'tag', 'cordtest/radius', "$targetReg/cordtest/radius:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700148}
149
150task publishRadiusImage(type: Exec) {
151 dependsOn tagRadiusImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800152 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/radius:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700153}
154
155task buildQuaggaImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800156 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/quagga', '-f', 'Dockerfile.quagga', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700157}
158
159task tagQuaggaImage(type: Exec) {
160 dependsOn buildQuaggaImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800161 commandLine "$dockerPath/docker", 'tag', 'cordtest/quagga', "$targetReg/cordtest/quagga:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700162}
163
164task publishQuaggaImage(type: Exec) {
165 dependsOn tagQuaggaImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800166 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/quagga:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700167}
168
169task buildTesterImage(type: Exec) {
A R Karthickf7a613b2017-02-24 09:36:44 -0800170 commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/nose', '-f', 'Dockerfile.tester', '.'
A R Karthick07608ef2016-08-23 16:51:19 -0700171}
172
173task tagTesterImage(type: Exec) {
174 dependsOn buildTesterImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800175 commandLine "$dockerPath/docker", 'tag', 'cordtest/nose', "$targetReg/cordtest/nose:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700176}
177
178task publishTesterImage(type: Exec) {
179 dependsOn tagTesterImage
A R Karthickf7a613b2017-02-24 09:36:44 -0800180 commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/nose:$targetTag"
A R Karthick07608ef2016-08-23 16:51:19 -0700181}
182
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700183// Publish image(s) built during the build step into targetReg registry using the targetTag
184// tag. See maas subproject for examples on how to do this.
A R Karthick07608ef2016-08-23 16:51:19 -0700185task publishImages {
186 dependsOn publishTesterImage
187 dependsOn publishQuaggaImage
188 dependsOn publishRadiusImage
189}
190
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700191task publish {
A R Karthick07608ef2016-08-23 16:51:19 -0700192 dependsOn publishImages
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700193}
A R Karthick6d98a592016-08-24 15:16:46 -0700194
195task deployBase (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700196 executable = "ansible-playbook"
197 args = ["-i", config.seedServer.ip + ',']
198
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800199 if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
200 args = args << "--user=$config.seedServer.ansible_user"
A R Karthick6d98a592016-08-24 15:16:46 -0700201 }
202
203
204 if ( config.debug ) {
205 args = args << "-vvvv"
206 }
207
208 def extraVars = []
209 if (config.seedServer) {
210 extraVars = extraVars.p(config.seedServer.extraVars)
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800211 .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
212 .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
A R Karthick6d98a592016-08-24 15:16:46 -0700213 .p(config.seedServer.fabric_ip, "fabric_ip")
214 .p(config.seedServer.management_ip, "management_ip")
215 .p(config.seedServer.management_gw, "management_gw")
216 .p(config.seedServer.management_network, "management_network")
217 .p(config.seedServer.management_iface, "management_iface")
218 .p(config.seedServer.external_ip, "external_ip")
219 .p(config.seedServer.external_gw, "external_gw")
220 .p(config.seedServer.external_network, "external_network")
221 .p(config.seedServer.external_iface, "external_iface")
222 .p(config.seedServer.fabric_ip, "fabric_ip")
223 .p(config.seedServer.fabric_network, "fabric_network")
224 .p(config.seedServer.fabric_iface, "fabric_iface")
225 .p(config.seedServer.domain, "domain")
226 .p(config.seedServer.virtualbox_support, "virtualbox_support")
227 .p(config.seedServer.power_helper_user, "power_helper_user")
228 .p(config.seedServer.power_helper_host, "power_helper_host")
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800229 .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
A R Karthick6d98a592016-08-24 15:16:46 -0700230 }
231
232 if (config.otherServers) {
233 extraVars = extraVars.p(config.otherServers.location, "prov_location")
234 .p(config.otherServers.rolesPath, "prov_role_path")
235 .p(config.otherServers.role, "prov_role")
236 }
237
238 if (config.docker) {
239 extraVars = extraVars.p(config.docker.registry, "docker_registry")
240 .p(config.docker.imageVersion, "docker_image_version")
241 }
242
243 def skipTags = [].p(config.seedServer.skipTags)
244
245 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-deploy.yml"
246}
247
248task verify (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700249 executable = "ansible-playbook"
250 args = ["-i", config.seedServer.ip + ',']
251
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800252 if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
253 args = args << "--user=$config.seedServer.ansible_user"
A R Karthick6d98a592016-08-24 15:16:46 -0700254 }
255
256
257 if ( config.debug ) {
258 args = args << "-vvvv"
259 }
260
261 def extraVars = []
262 if (config.seedServer) {
263 extraVars = extraVars.p(config.seedServer.extraVars)
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800264 .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
265 .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
A R Karthick6d98a592016-08-24 15:16:46 -0700266 .p(config.seedServer.fabric_ip, "fabric_ip")
267 .p(config.seedServer.management_ip, "management_ip")
268 .p(config.seedServer.management_gw, "management_gw")
269 .p(config.seedServer.management_network, "management_network")
270 .p(config.seedServer.management_iface, "management_iface")
271 .p(config.seedServer.external_ip, "external_ip")
272 .p(config.seedServer.external_gw, "external_gw")
273 .p(config.seedServer.external_network, "external_network")
274 .p(config.seedServer.external_iface, "external_iface")
275 .p(config.seedServer.fabric_ip, "fabric_ip")
276 .p(config.seedServer.fabric_network, "fabric_network")
277 .p(config.seedServer.fabric_iface, "fabric_iface")
278 .p(config.seedServer.domain, "domain")
279 .p(config.seedServer.virtualbox_support, "virtualbox_support")
280 .p(config.seedServer.power_helper_user, "power_helper_user")
281 .p(config.seedServer.power_helper_host, "power_helper_host")
David K. Bainbridgea343a7e2017-01-26 09:03:05 -0800282 .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
A R Karthick6d98a592016-08-24 15:16:46 -0700283 }
284
285 if (config.otherServers) {
286 extraVars = extraVars.p(config.otherServers.location, "prov_location")
287 .p(config.otherServers.rolesPath, "prov_role_path")
288 .p(config.otherServers.role, "prov_role")
289 }
290
291 if (config.docker) {
292 extraVars = extraVars.p(config.docker.registry, "docker_registry")
293 .p(config.docker.imageVersion, "docker_image_version")
294 }
295
296 def skipTags = [].p(config.seedServer.skipTags)
297
298 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-verify.yml"
299}