Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 1 | /* |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 2 | * Copyright 2012 the original author or authors. |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 3 | * |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 4 | * 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 Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 15 | */ |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 16 | import org.opencord.gradle.rules.* |
| 17 | import org.yaml.snakeyaml.Yaml |
| 18 | |
| 19 | allprojects { |
| 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 Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 36 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 37 | ext { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 38 | // 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. Bainbridge | f528961 | 2016-11-15 17:22:33 -0800 | [diff] [blame] | 42 | 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 | |
ChetanGaonker | 5979e21 | 2016-06-03 09:30:49 -0700 | [diff] [blame] | 66 | cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup' |
| 67 | |
| 68 | dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin' |
A R Karthick | 577520a | 2016-06-07 14:40:12 -0700 | [diff] [blame] | 69 | |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 70 | cordTesterImages = [ 'cord-test/radius:latest' : 'Dockerfile.radius', 'cord-test/quagga:latest' : 'Dockerfile.quagga', 'cord-test/nose:latest' : 'Dockerfile.tester' ] |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 71 | |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 72 | } |
| 73 | |
A R Karthick | e7aff36 | 2016-12-13 10:27:07 -0800 | [diff] [blame] | 74 | List.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 | |
| 87 | List.metaClass.p = { value, name -> |
| 88 | if (value != null && value != "") { |
| 89 | delegate << name + "=" + value |
| 90 | } else { |
| 91 | delegate |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | List.metaClass.p = { spec -> |
| 96 | if (spec != null && spec != "") { |
| 97 | delegate += spec |
| 98 | } else { |
| 99 | delegate |
| 100 | } |
| 101 | } |
| 102 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 103 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 104 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 105 | // To be used to fetch upstream binaries, clone repos, etc. |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 106 | task fetch { |
| 107 | //commandLine "$cordTesterPath/onos_pull.sh", 'latest' |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 108 | } |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 109 | |
| 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 Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 112 | task buildImages { |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 113 | // ... |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 114 | 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 Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 121 | } |
| 122 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 123 | task buildRadiusImage(type: Exec) { |
| 124 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/radius', '-f', 'Dockerfile.radius', '.' |
| 125 | } |
| 126 | |
| 127 | task tagRadiusImage(type: Exec) { |
| 128 | dependsOn buildRadiusImage |
| 129 | commandLine "$dockerPath/docker", 'tag', 'cord-test/radius', "$targetReg/cord-test/radius:$targetTag" |
| 130 | } |
| 131 | |
| 132 | task publishRadiusImage(type: Exec) { |
| 133 | dependsOn tagRadiusImage |
| 134 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/radius:$targetTag" |
| 135 | } |
| 136 | |
| 137 | task buildQuaggaImage(type: Exec) { |
| 138 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/quagga', '-f', 'Dockerfile.quagga', '.' |
| 139 | } |
| 140 | |
| 141 | task tagQuaggaImage(type: Exec) { |
| 142 | dependsOn buildQuaggaImage |
| 143 | commandLine "$dockerPath/docker", 'tag', 'cord-test/quagga', "$targetReg/cord-test/quagga:$targetTag" |
| 144 | } |
| 145 | |
| 146 | task publishQuaggaImage(type: Exec) { |
| 147 | dependsOn tagQuaggaImage |
| 148 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/quagga:$targetTag" |
| 149 | } |
| 150 | |
| 151 | task buildTesterImage(type: Exec) { |
| 152 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/nose', '-f', 'Dockerfile.tester', '.' |
| 153 | } |
| 154 | |
| 155 | task tagTesterImage(type: Exec) { |
| 156 | dependsOn buildTesterImage |
| 157 | commandLine "$dockerPath/docker", 'tag', 'cord-test/nose', "$targetReg/cord-test/nose:$targetTag" |
| 158 | } |
| 159 | |
| 160 | task publishTesterImage(type: Exec) { |
| 161 | dependsOn tagTesterImage |
| 162 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/nose:$targetTag" |
| 163 | } |
| 164 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 165 | // 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 Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 167 | task publishImages { |
| 168 | dependsOn publishTesterImage |
| 169 | dependsOn publishQuaggaImage |
| 170 | dependsOn publishRadiusImage |
| 171 | } |
| 172 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 173 | task publish { |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 174 | dependsOn publishImages |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 175 | } |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 176 | |
| 177 | task deployBase (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 178 | executable = "ansible-playbook" |
| 179 | args = ["-i", config.seedServer.ip + ','] |
| 180 | |
David K. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 181 | if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) { |
| 182 | args = args << "--user=$config.seedServer.ansible_user" |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 183 | } |
| 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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 193 | .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass") |
| 194 | .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 195 | .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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 211 | .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 212 | } |
| 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 | |
| 230 | task verify (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 231 | executable = "ansible-playbook" |
| 232 | args = ["-i", config.seedServer.ip + ','] |
| 233 | |
David K. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 234 | if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) { |
| 235 | args = args << "--user=$config.seedServer.ansible_user" |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 236 | } |
| 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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 246 | .p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass") |
| 247 | .p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 248 | .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. Bainbridge | a343a7e | 2017-01-26 09:03:05 -0800 | [diff] [blame] | 264 | .p(config.seedServer.ansible_ssh_port, "ansible_ssh_port") |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 265 | } |
| 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 | } |