blob: 4fcd370ec4757221b4cef497d02077150598ff56 [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 {
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070038
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070039 // Target registry to be used to publish docker images needed for deployment
40 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
41
42 // The tag used to tag the docker images push to the target registry
43 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
44
A R Karthick6d98a592016-08-24 15:16:46 -070045 // Deployment target config file (yaml format); this can be overwritten from the command line
46 // using the -PdeployConfig=<file-path> syntax.
47 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
48
ChetanGaonker5979e212016-06-03 09:30:49 -070049 cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup'
50
51 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
A R Karthick577520a2016-06-07 14:40:12 -070052
A.R Karthick490f51f2016-06-09 21:29:13 -070053 cordTesterImages = [ 'cord-test/radius:latest' : 'Dockerfile.radius', 'cord-test/quagga:latest' : 'Dockerfile.quagga', 'cord-test/nose:latest' : 'Dockerfile.tester' ]
A R Karthick07608ef2016-08-23 16:51:19 -070054
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070055}
56
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070057// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070058
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070059// To be used to fetch upstream binaries, clone repos, etc.
A.R Karthick490f51f2016-06-09 21:29:13 -070060task fetch {
61 //commandLine "$cordTesterPath/onos_pull.sh", 'latest'
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070062}
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070063
64// To be used to generate all needed binaries that need to be present on the target
65// as docker images in the local docker runner.
A.R Karthick490f51f2016-06-09 21:29:13 -070066task buildImages {
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070067 // ...
A.R Karthick490f51f2016-06-09 21:29:13 -070068 cordTesterImages.each { tag, dockerfile ->
69 println "Building Docker image ${tag} using ${dockerfile}"
70 exec {
71 executable "$dockerPath/docker"
72 args "build", "-t", "${tag}", "-f", "${dockerfile}", "."
73 }
74 }
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070075}
76
A R Karthick07608ef2016-08-23 16:51:19 -070077task buildRadiusImage(type: Exec) {
78 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/radius', '-f', 'Dockerfile.radius', '.'
79}
80
81task tagRadiusImage(type: Exec) {
82 dependsOn buildRadiusImage
83 commandLine "$dockerPath/docker", 'tag', 'cord-test/radius', "$targetReg/cord-test/radius:$targetTag"
84}
85
86task publishRadiusImage(type: Exec) {
87 dependsOn tagRadiusImage
88 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/radius:$targetTag"
89}
90
91task buildQuaggaImage(type: Exec) {
92 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/quagga', '-f', 'Dockerfile.quagga', '.'
93}
94
95task tagQuaggaImage(type: Exec) {
96 dependsOn buildQuaggaImage
97 commandLine "$dockerPath/docker", 'tag', 'cord-test/quagga', "$targetReg/cord-test/quagga:$targetTag"
98}
99
100task publishQuaggaImage(type: Exec) {
101 dependsOn tagQuaggaImage
102 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/quagga:$targetTag"
103}
104
105task buildTesterImage(type: Exec) {
106 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/nose', '-f', 'Dockerfile.tester', '.'
107}
108
109task tagTesterImage(type: Exec) {
110 dependsOn buildTesterImage
111 commandLine "$dockerPath/docker", 'tag', 'cord-test/nose', "$targetReg/cord-test/nose:$targetTag"
112}
113
114task publishTesterImage(type: Exec) {
115 dependsOn tagTesterImage
116 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/nose:$targetTag"
117}
118
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700119// Publish image(s) built during the build step into targetReg registry using the targetTag
120// tag. See maas subproject for examples on how to do this.
A R Karthick07608ef2016-08-23 16:51:19 -0700121task publishImages {
122 dependsOn publishTesterImage
123 dependsOn publishQuaggaImage
124 dependsOn publishRadiusImage
125}
126
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700127task publish {
A R Karthick07608ef2016-08-23 16:51:19 -0700128 dependsOn publishImages
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700129}
A R Karthick6d98a592016-08-24 15:16:46 -0700130
131task deployBase (type: Exec) {
132 println "Using deployment config: $deployConfig"
133 File configFile = new File(deployConfig)
134 def yaml = new Yaml()
135 def config = yaml.load(configFile.newReader())
136
137 executable = "ansible-playbook"
138 args = ["-i", config.seedServer.ip + ',']
139
140 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
141 args = args << "--user=$config.seedServer.user"
142 }
143
144
145 if ( config.debug ) {
146 args = args << "-vvvv"
147 }
148
149 def extraVars = []
150 if (config.seedServer) {
151 extraVars = extraVars.p(config.seedServer.extraVars)
152 .p(config.seedServer.password, "ansible_ssh_pass")
153 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
154 .p(config.seedServer.fabric_ip, "fabric_ip")
155 .p(config.seedServer.management_ip, "management_ip")
156 .p(config.seedServer.management_gw, "management_gw")
157 .p(config.seedServer.management_network, "management_network")
158 .p(config.seedServer.management_iface, "management_iface")
159 .p(config.seedServer.external_ip, "external_ip")
160 .p(config.seedServer.external_gw, "external_gw")
161 .p(config.seedServer.external_network, "external_network")
162 .p(config.seedServer.external_iface, "external_iface")
163 .p(config.seedServer.fabric_ip, "fabric_ip")
164 .p(config.seedServer.fabric_network, "fabric_network")
165 .p(config.seedServer.fabric_iface, "fabric_iface")
166 .p(config.seedServer.domain, "domain")
167 .p(config.seedServer.virtualbox_support, "virtualbox_support")
168 .p(config.seedServer.power_helper_user, "power_helper_user")
169 .p(config.seedServer.power_helper_host, "power_helper_host")
170 .p(config.seedServer.port, "ansible_ssh_port")
171 }
172
173 if (config.otherServers) {
174 extraVars = extraVars.p(config.otherServers.location, "prov_location")
175 .p(config.otherServers.rolesPath, "prov_role_path")
176 .p(config.otherServers.role, "prov_role")
177 }
178
179 if (config.docker) {
180 extraVars = extraVars.p(config.docker.registry, "docker_registry")
181 .p(config.docker.imageVersion, "docker_image_version")
182 }
183
184 def skipTags = [].p(config.seedServer.skipTags)
185
186 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-deploy.yml"
187}
188
189task verify (type: Exec) {
190 println "Using deployment config: $deployConfig"
191 File configFile = new File(deployConfig)
192 def yaml = new Yaml()
193 def config = yaml.load(configFile.newReader())
194
195 executable = "ansible-playbook"
196 args = ["-i", config.seedServer.ip + ',']
197
198 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
199 args = args << "--user=$config.seedServer.user"
200 }
201
202
203 if ( config.debug ) {
204 args = args << "-vvvv"
205 }
206
207 def extraVars = []
208 if (config.seedServer) {
209 extraVars = extraVars.p(config.seedServer.extraVars)
210 .p(config.seedServer.password, "ansible_ssh_pass")
211 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
212 .p(config.seedServer.fabric_ip, "fabric_ip")
213 .p(config.seedServer.management_ip, "management_ip")
214 .p(config.seedServer.management_gw, "management_gw")
215 .p(config.seedServer.management_network, "management_network")
216 .p(config.seedServer.management_iface, "management_iface")
217 .p(config.seedServer.external_ip, "external_ip")
218 .p(config.seedServer.external_gw, "external_gw")
219 .p(config.seedServer.external_network, "external_network")
220 .p(config.seedServer.external_iface, "external_iface")
221 .p(config.seedServer.fabric_ip, "fabric_ip")
222 .p(config.seedServer.fabric_network, "fabric_network")
223 .p(config.seedServer.fabric_iface, "fabric_iface")
224 .p(config.seedServer.domain, "domain")
225 .p(config.seedServer.virtualbox_support, "virtualbox_support")
226 .p(config.seedServer.power_helper_user, "power_helper_user")
227 .p(config.seedServer.power_helper_host, "power_helper_host")
228 .p(config.seedServer.port, "ansible_ssh_port")
229 }
230
231 if (config.otherServers) {
232 extraVars = extraVars.p(config.otherServers.location, "prov_location")
233 .p(config.otherServers.rolesPath, "prov_role_path")
234 .p(config.otherServers.role, "prov_role")
235 }
236
237 if (config.docker) {
238 extraVars = extraVars.p(config.docker.registry, "docker_registry")
239 .p(config.docker.imageVersion, "docker_image_version")
240 }
241
242 def skipTags = [].p(config.seedServer.skipTags)
243
244 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-verify.yml"
245}