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 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 74 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 75 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 76 | // To be used to fetch upstream binaries, clone repos, etc. |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 77 | task fetch { |
| 78 | //commandLine "$cordTesterPath/onos_pull.sh", 'latest' |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 79 | } |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 80 | |
| 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 Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 83 | task buildImages { |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 84 | // ... |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 85 | 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 Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 92 | } |
| 93 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 94 | task buildRadiusImage(type: Exec) { |
| 95 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/radius', '-f', 'Dockerfile.radius', '.' |
| 96 | } |
| 97 | |
| 98 | task tagRadiusImage(type: Exec) { |
| 99 | dependsOn buildRadiusImage |
| 100 | commandLine "$dockerPath/docker", 'tag', 'cord-test/radius', "$targetReg/cord-test/radius:$targetTag" |
| 101 | } |
| 102 | |
| 103 | task publishRadiusImage(type: Exec) { |
| 104 | dependsOn tagRadiusImage |
| 105 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/radius:$targetTag" |
| 106 | } |
| 107 | |
| 108 | task buildQuaggaImage(type: Exec) { |
| 109 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/quagga', '-f', 'Dockerfile.quagga', '.' |
| 110 | } |
| 111 | |
| 112 | task tagQuaggaImage(type: Exec) { |
| 113 | dependsOn buildQuaggaImage |
| 114 | commandLine "$dockerPath/docker", 'tag', 'cord-test/quagga', "$targetReg/cord-test/quagga:$targetTag" |
| 115 | } |
| 116 | |
| 117 | task publishQuaggaImage(type: Exec) { |
| 118 | dependsOn tagQuaggaImage |
| 119 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/quagga:$targetTag" |
| 120 | } |
| 121 | |
| 122 | task buildTesterImage(type: Exec) { |
| 123 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/nose', '-f', 'Dockerfile.tester', '.' |
| 124 | } |
| 125 | |
| 126 | task tagTesterImage(type: Exec) { |
| 127 | dependsOn buildTesterImage |
| 128 | commandLine "$dockerPath/docker", 'tag', 'cord-test/nose', "$targetReg/cord-test/nose:$targetTag" |
| 129 | } |
| 130 | |
| 131 | task publishTesterImage(type: Exec) { |
| 132 | dependsOn tagTesterImage |
| 133 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/nose:$targetTag" |
| 134 | } |
| 135 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 136 | // 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 Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 138 | task publishImages { |
| 139 | dependsOn publishTesterImage |
| 140 | dependsOn publishQuaggaImage |
| 141 | dependsOn publishRadiusImage |
| 142 | } |
| 143 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 144 | task publish { |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 145 | dependsOn publishImages |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 146 | } |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 147 | |
| 148 | task deployBase (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 149 | 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 | |
| 201 | task verify (type: Exec) { |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 202 | 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 | } |