blob: 9b5de2caa91711f8a73ab65185753369bda05c60 [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 Karthick490f51f2016-06-09 21:29:13 -070070 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 -070071
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070072}
73
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070074// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070075
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070076// To be used to fetch upstream binaries, clone repos, etc.
A.R Karthick490f51f2016-06-09 21:29:13 -070077task fetch {
78 //commandLine "$cordTesterPath/onos_pull.sh", 'latest'
Zsolt Haraszti56700cd2016-06-01 16:02:05 -070079}
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070080
81// To be used to generate all needed binaries that need to be present on the target
82// as docker images in the local docker runner.
A.R Karthick490f51f2016-06-09 21:29:13 -070083task buildImages {
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070084 // ...
A.R Karthick490f51f2016-06-09 21:29:13 -070085 cordTesterImages.each { tag, dockerfile ->
86 println "Building Docker image ${tag} using ${dockerfile}"
87 exec {
88 executable "$dockerPath/docker"
89 args "build", "-t", "${tag}", "-f", "${dockerfile}", "."
90 }
91 }
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -070092}
93
A R Karthick07608ef2016-08-23 16:51:19 -070094task buildRadiusImage(type: Exec) {
95 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/radius', '-f', 'Dockerfile.radius', '.'
96}
97
98task tagRadiusImage(type: Exec) {
99 dependsOn buildRadiusImage
100 commandLine "$dockerPath/docker", 'tag', 'cord-test/radius', "$targetReg/cord-test/radius:$targetTag"
101}
102
103task publishRadiusImage(type: Exec) {
104 dependsOn tagRadiusImage
105 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/radius:$targetTag"
106}
107
108task buildQuaggaImage(type: Exec) {
109 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/quagga', '-f', 'Dockerfile.quagga', '.'
110}
111
112task tagQuaggaImage(type: Exec) {
113 dependsOn buildQuaggaImage
114 commandLine "$dockerPath/docker", 'tag', 'cord-test/quagga', "$targetReg/cord-test/quagga:$targetTag"
115}
116
117task publishQuaggaImage(type: Exec) {
118 dependsOn tagQuaggaImage
119 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/quagga:$targetTag"
120}
121
122task buildTesterImage(type: Exec) {
123 commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/nose', '-f', 'Dockerfile.tester', '.'
124}
125
126task tagTesterImage(type: Exec) {
127 dependsOn buildTesterImage
128 commandLine "$dockerPath/docker", 'tag', 'cord-test/nose', "$targetReg/cord-test/nose:$targetTag"
129}
130
131task publishTesterImage(type: Exec) {
132 dependsOn tagTesterImage
133 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/nose:$targetTag"
134}
135
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700136// Publish image(s) built during the build step into targetReg registry using the targetTag
137// tag. See maas subproject for examples on how to do this.
A R Karthick07608ef2016-08-23 16:51:19 -0700138task publishImages {
139 dependsOn publishTesterImage
140 dependsOn publishQuaggaImage
141 dependsOn publishRadiusImage
142}
143
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700144task publish {
A R Karthick07608ef2016-08-23 16:51:19 -0700145 dependsOn publishImages
Zsolt Harasztid5fa9ed2016-06-01 16:07:16 -0700146}
A R Karthick6d98a592016-08-24 15:16:46 -0700147
148task deployBase (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700149 executable = "ansible-playbook"
150 args = ["-i", config.seedServer.ip + ',']
151
152 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
153 args = args << "--user=$config.seedServer.user"
154 }
155
156
157 if ( config.debug ) {
158 args = args << "-vvvv"
159 }
160
161 def extraVars = []
162 if (config.seedServer) {
163 extraVars = extraVars.p(config.seedServer.extraVars)
164 .p(config.seedServer.password, "ansible_ssh_pass")
165 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
166 .p(config.seedServer.fabric_ip, "fabric_ip")
167 .p(config.seedServer.management_ip, "management_ip")
168 .p(config.seedServer.management_gw, "management_gw")
169 .p(config.seedServer.management_network, "management_network")
170 .p(config.seedServer.management_iface, "management_iface")
171 .p(config.seedServer.external_ip, "external_ip")
172 .p(config.seedServer.external_gw, "external_gw")
173 .p(config.seedServer.external_network, "external_network")
174 .p(config.seedServer.external_iface, "external_iface")
175 .p(config.seedServer.fabric_ip, "fabric_ip")
176 .p(config.seedServer.fabric_network, "fabric_network")
177 .p(config.seedServer.fabric_iface, "fabric_iface")
178 .p(config.seedServer.domain, "domain")
179 .p(config.seedServer.virtualbox_support, "virtualbox_support")
180 .p(config.seedServer.power_helper_user, "power_helper_user")
181 .p(config.seedServer.power_helper_host, "power_helper_host")
182 .p(config.seedServer.port, "ansible_ssh_port")
183 }
184
185 if (config.otherServers) {
186 extraVars = extraVars.p(config.otherServers.location, "prov_location")
187 .p(config.otherServers.rolesPath, "prov_role_path")
188 .p(config.otherServers.role, "prov_role")
189 }
190
191 if (config.docker) {
192 extraVars = extraVars.p(config.docker.registry, "docker_registry")
193 .p(config.docker.imageVersion, "docker_image_version")
194 }
195
196 def skipTags = [].p(config.seedServer.skipTags)
197
198 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-deploy.yml"
199}
200
201task verify (type: Exec) {
A R Karthick6d98a592016-08-24 15:16:46 -0700202 executable = "ansible-playbook"
203 args = ["-i", config.seedServer.ip + ',']
204
205 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
206 args = args << "--user=$config.seedServer.user"
207 }
208
209
210 if ( config.debug ) {
211 args = args << "-vvvv"
212 }
213
214 def extraVars = []
215 if (config.seedServer) {
216 extraVars = extraVars.p(config.seedServer.extraVars)
217 .p(config.seedServer.password, "ansible_ssh_pass")
218 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
219 .p(config.seedServer.fabric_ip, "fabric_ip")
220 .p(config.seedServer.management_ip, "management_ip")
221 .p(config.seedServer.management_gw, "management_gw")
222 .p(config.seedServer.management_network, "management_network")
223 .p(config.seedServer.management_iface, "management_iface")
224 .p(config.seedServer.external_ip, "external_ip")
225 .p(config.seedServer.external_gw, "external_gw")
226 .p(config.seedServer.external_network, "external_network")
227 .p(config.seedServer.external_iface, "external_iface")
228 .p(config.seedServer.fabric_ip, "fabric_ip")
229 .p(config.seedServer.fabric_network, "fabric_network")
230 .p(config.seedServer.fabric_iface, "fabric_iface")
231 .p(config.seedServer.domain, "domain")
232 .p(config.seedServer.virtualbox_support, "virtualbox_support")
233 .p(config.seedServer.power_helper_user, "power_helper_user")
234 .p(config.seedServer.power_helper_host, "power_helper_host")
235 .p(config.seedServer.port, "ansible_ssh_port")
236 }
237
238 if (config.otherServers) {
239 extraVars = extraVars.p(config.otherServers.location, "prov_location")
240 .p(config.otherServers.rolesPath, "prov_role_path")
241 .p(config.otherServers.role, "prov_role")
242 }
243
244 if (config.docker) {
245 extraVars = extraVars.p(config.docker.registry, "docker_registry")
246 .p(config.docker.imageVersion, "docker_image_version")
247 }
248
249 def skipTags = [].p(config.seedServer.skipTags)
250
251 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-verify.yml"
252}