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 { |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 38 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 39 | // 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 Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 45 | // 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 | |
ChetanGaonker | 5979e21 | 2016-06-03 09:30:49 -0700 | [diff] [blame] | 49 | cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup' |
| 50 | |
| 51 | dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin' |
A R Karthick | 577520a | 2016-06-07 14:40:12 -0700 | [diff] [blame] | 52 | |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 53 | 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] | 54 | |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 57 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 58 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 59 | // To be used to fetch upstream binaries, clone repos, etc. |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 60 | task fetch { |
| 61 | //commandLine "$cordTesterPath/onos_pull.sh", 'latest' |
Zsolt Haraszti | 56700cd | 2016-06-01 16:02:05 -0700 | [diff] [blame] | 62 | } |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 63 | |
| 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 Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 66 | task buildImages { |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 67 | // ... |
A.R Karthick | 490f51f | 2016-06-09 21:29:13 -0700 | [diff] [blame] | 68 | 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 Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 75 | } |
| 76 | |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 77 | task buildRadiusImage(type: Exec) { |
| 78 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/radius', '-f', 'Dockerfile.radius', '.' |
| 79 | } |
| 80 | |
| 81 | task tagRadiusImage(type: Exec) { |
| 82 | dependsOn buildRadiusImage |
| 83 | commandLine "$dockerPath/docker", 'tag', 'cord-test/radius', "$targetReg/cord-test/radius:$targetTag" |
| 84 | } |
| 85 | |
| 86 | task publishRadiusImage(type: Exec) { |
| 87 | dependsOn tagRadiusImage |
| 88 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/radius:$targetTag" |
| 89 | } |
| 90 | |
| 91 | task buildQuaggaImage(type: Exec) { |
| 92 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/quagga', '-f', 'Dockerfile.quagga', '.' |
| 93 | } |
| 94 | |
| 95 | task tagQuaggaImage(type: Exec) { |
| 96 | dependsOn buildQuaggaImage |
| 97 | commandLine "$dockerPath/docker", 'tag', 'cord-test/quagga', "$targetReg/cord-test/quagga:$targetTag" |
| 98 | } |
| 99 | |
| 100 | task publishQuaggaImage(type: Exec) { |
| 101 | dependsOn tagQuaggaImage |
| 102 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/quagga:$targetTag" |
| 103 | } |
| 104 | |
| 105 | task buildTesterImage(type: Exec) { |
| 106 | commandLine "$dockerPath/docker", 'build', '-t', 'cord-test/nose', '-f', 'Dockerfile.tester', '.' |
| 107 | } |
| 108 | |
| 109 | task tagTesterImage(type: Exec) { |
| 110 | dependsOn buildTesterImage |
| 111 | commandLine "$dockerPath/docker", 'tag', 'cord-test/nose', "$targetReg/cord-test/nose:$targetTag" |
| 112 | } |
| 113 | |
| 114 | task publishTesterImage(type: Exec) { |
| 115 | dependsOn tagTesterImage |
| 116 | commandLine "$dockerPath/docker", 'push', "$targetReg/cord-test/nose:$targetTag" |
| 117 | } |
| 118 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 119 | // 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 Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 121 | task publishImages { |
| 122 | dependsOn publishTesterImage |
| 123 | dependsOn publishQuaggaImage |
| 124 | dependsOn publishRadiusImage |
| 125 | } |
| 126 | |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 127 | task publish { |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 128 | dependsOn publishImages |
Zsolt Haraszti | d5fa9ed | 2016-06-01 16:07:16 -0700 | [diff] [blame] | 129 | } |
A R Karthick | 6d98a59 | 2016-08-24 15:16:46 -0700 | [diff] [blame] | 130 | |
| 131 | task 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 | |
| 189 | task 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 | } |