Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame^] | 1 | |
| 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 Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 19 | /* |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 20 | * Copyright 2012 the original author or authors. |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 21 | * |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 22 | * 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 Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 33 | */ |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 34 | import org.opencord.gradle.rules.* |
| 35 | import org.yaml.snakeyaml.Yaml |
| 36 | |
| 37 | allprojects { |
| 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 Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 54 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 55 | ext { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 56 | // 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. Bainbridge | f528961 | 2016-11-15 17:22:33 -0800 | [diff] [blame] | 60 | 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 | |
ChetanGaonker | 5979e21 | 2016-06-03 09:30:49 -0700 | [diff] [blame] | 84 | cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup' |
| 85 | |
| 86 | dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin' |
A R Karthick | 577520a | 2016-06-07 14:40:12 -0700 | [diff] [blame] | 87 | |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 88 | cordTesterImages = [ 'cordtest/radius:candidate' : 'Dockerfile.radius', 'cordtest/quagga:candidate' : 'Dockerfile.quagga', 'cordtest/nose:candidate' : 'Dockerfile.tester' ] |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 89 | |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 90 | } |
| 91 | |
A R Karthick | e7aff36 | 2016-12-13 10:27:07 -0800 | [diff] [blame] | 92 | List.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 | |
| 105 | List.metaClass.p = { value, name -> |
| 106 | if (value != null && value != "") { |
| 107 | delegate << name + "=" + value |
| 108 | } else { |
| 109 | delegate |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | List.metaClass.p = { spec -> |
| 114 | if (spec != null && spec != "") { |
| 115 | delegate += spec |
| 116 | } else { |
| 117 | delegate |
| 118 | } |
| 119 | } |
| 120 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 121 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 122 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 123 | // To be used to fetch upstream binaries, clone repos, etc. |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 124 | task fetch { |
| 125 | //commandLine "$cordTesterPath/onos_pull.sh", 'latest' |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 126 | } |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 127 | |
| 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 Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 130 | task buildImages { |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 131 | // ... |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 132 | 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 Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 139 | } |
| 140 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 141 | task buildRadiusImage(type: Exec) { |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 142 | commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/radius', '-f', 'Dockerfile.radius', '.' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | task tagRadiusImage(type: Exec) { |
| 146 | dependsOn buildRadiusImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 147 | commandLine "$dockerPath/docker", 'tag', 'cordtest/radius', "$targetReg/cordtest/radius:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | task publishRadiusImage(type: Exec) { |
| 151 | dependsOn tagRadiusImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 152 | commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/radius:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | task buildQuaggaImage(type: Exec) { |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 156 | commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/quagga', '-f', 'Dockerfile.quagga', '.' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | task tagQuaggaImage(type: Exec) { |
| 160 | dependsOn buildQuaggaImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 161 | commandLine "$dockerPath/docker", 'tag', 'cordtest/quagga', "$targetReg/cordtest/quagga:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | task publishQuaggaImage(type: Exec) { |
| 165 | dependsOn tagQuaggaImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 166 | commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/quagga:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | task buildTesterImage(type: Exec) { |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 170 | commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/nose', '-f', 'Dockerfile.tester', '.' |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | task tagTesterImage(type: Exec) { |
| 174 | dependsOn buildTesterImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 175 | commandLine "$dockerPath/docker", 'tag', 'cordtest/nose', "$targetReg/cordtest/nose:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | task publishTesterImage(type: Exec) { |
| 179 | dependsOn tagTesterImage |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 180 | commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/nose:$targetTag" |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 183 | // 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 Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 185 | task publishImages { |
| 186 | dependsOn publishTesterImage |
| 187 | dependsOn publishQuaggaImage |
| 188 | dependsOn publishRadiusImage |
| 189 | } |
| 190 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 191 | task publish { |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 192 | dependsOn publishImages |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 193 | } |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 194 | |
| 195 | task deployBase (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 196 | executable = "ansible-playbook" |
| 197 | args = ["-i", config.seedServer.ip + ','] |
| 198 | |
David K. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 199 | if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) { |
| 200 | args = args << "--user=$config.seedServer.ansible_user" |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 201 | } |
| 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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 211 | .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass") |
| 212 | .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 213 | .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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 229 | .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 230 | } |
| 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 | |
| 248 | task verify (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 249 | executable = "ansible-playbook" |
| 250 | args = ["-i", config.seedServer.ip + ','] |
| 251 | |
David K. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 252 | if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) { |
| 253 | args = args << "--user=$config.seedServer.ansible_user" |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 254 | } |
| 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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 264 | .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass") |
| 265 | .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 266 | .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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 282 | .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 283 | } |
| 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 | } |