Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 the original author or authors. |
| 3 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | import org.opencord.gradle.rules.* |
| 18 | import org.yaml.snakeyaml.Yaml |
| 19 | |
| 20 | allprojects { |
| 21 | apply plugin: 'base' |
| 22 | apply plugin: 'de.gesellix.docker' |
| 23 | //apply plugin: 'com.tmiyamon.config' |
| 24 | |
| 25 | docker { |
| 26 | // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock' |
| 27 | // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376' |
| 28 | // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default" |
| 29 | // authConfigPlain = [ |
| 30 | // "username" : "joe", |
| 31 | // "password" : "some-pw-as-needed", |
| 32 | // "email" : "joe@acme.com", |
| 33 | // "serveraddress" : "https://index.docker.io/v1/" |
| 34 | // ] |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | ext { |
| 39 | |
| 40 | // Upstream registry to simplify filling out the comps table below |
| 41 | upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io' |
| 42 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 43 | // Deployment target config file (yaml format); this can be overwritten from the command line |
| 44 | // using the -PdeployConfig=<file-path> syntax. |
| 45 | deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml' |
| 46 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 47 | println "Using deployment config: $deployConfig" |
| 48 | File configFile = new File(deployConfig) |
| 49 | def yaml = new Yaml() |
| 50 | config = yaml.load(configFile.newReader()) |
| 51 | |
| 52 | |
| 53 | // Target registry to be used to publish docker images needed for deployment |
| 54 | targetReg = project.hasProperty('targetReg') |
| 55 | ? project.getProperty('targetReg') |
| 56 | : config.docker && config.docker.registry |
| 57 | ? config.docker.registry |
David K. Bainbridge | 94b2471 | 2016-11-15 15:09:42 -0800 | [diff] [blame] | 58 | : config.seedServer.ip |
| 59 | ? config.seedServer.ip + ":5000" |
| 60 | : 'localhost:5000' |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 61 | |
| 62 | // The tag used to tag the docker images push to the target registry |
| 63 | targetTag = project.hasProperty('targetTag') |
| 64 | ? project.getProperty('targetTag') |
| 65 | : config.docker && config.docker.imageVersion |
| 66 | ? config.docker.imageVersion |
| 67 | : 'candidate' |
| 68 | |
| 69 | println "targetReg = $targetReg, targetTag = $targetTag" |
| 70 | |
| 71 | // Component table |
| 72 | comps = [ |
| 73 | ] |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 76 | task copyAnsibleInventory(type: Copy) { |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 77 | from 'inventory/templates/single-prod' |
| 78 | into 'inventory' |
| 79 | expand([ |
| 80 | prod: config.seedServer.ip, |
| 81 | ]) |
| 82 | } |
| 83 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 84 | // ------------- PlaceHolders ---------------- |
| 85 | |
| 86 | task updateDocker (type: Exec) { |
| 87 | commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg" |
| 88 | } |
| 89 | |
| 90 | task prime { |
| 91 | // TODO this is a place-holder. |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 92 | // dependsOn updateDocker |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | // ---------------- Useful tasks ---------------- |
| 96 | |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 97 | List.metaClass.asParam = { prefix, sep -> |
| 98 | if (delegate.size() == 0) { |
| 99 | "" |
| 100 | } |
| 101 | String result = "--" + prefix + "=" |
| 102 | String p = "" |
| 103 | delegate.each { |
| 104 | result += p + "${it}" |
| 105 | p = sep |
| 106 | } |
| 107 | result |
| 108 | } |
| 109 | |
| 110 | List.metaClass.p = { value, name -> |
| 111 | if (value != null && value != "") { |
| 112 | delegate << name + "=" + value |
| 113 | } else { |
| 114 | delegate |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | List.metaClass.p = { spec -> |
| 119 | if (spec != null && spec != "") { |
| 120 | delegate += spec |
| 121 | } else { |
| 122 | delegate |
| 123 | } |
| 124 | } |
| 125 | |
alshabib | fe09d77 | 2016-08-29 16:15:56 -0700 | [diff] [blame] | 126 | task fetch << { |
| 127 | logger.info 'Platform install has nothing to fetch' |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 128 | } |
| 129 | |
alshabib | fe09d77 | 2016-08-29 16:15:56 -0700 | [diff] [blame] | 130 | task buildImages << { |
| 131 | logger.info 'Platform install has nothing to build' |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | task publishImages { |
| 135 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } } |
| 136 | } |
| 137 | |
| 138 | task publish { |
| 139 | dependsOn publishImages |
| 140 | } |
| 141 | |
| 142 | tasks.addRule(new DockerFetchRule(project)) |
| 143 | tasks.addRule(new DockerPublishRule(project)) |
| 144 | tasks.addRule(new DockerTagRule(project)) |
| 145 | tasks.addRule(new GitSubmoduleUpdateRule(project)) |
| 146 | |
Andy Bavier | c27a2aa | 2016-07-06 19:20:04 -0400 | [diff] [blame] | 147 | task deployPlatform (type: Exec) { |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 148 | dependsOn copyAnsibleInventory |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 149 | |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 150 | executable = "ansible-playbook" |
| 151 | args = ["-i", "inventory/single-prod"] |
| 152 | |
| 153 | if ( config.seedServer.user != null && config.seedServer.user != "" ) { |
| 154 | args = args << "--user=$config.seedServer.user" |
| 155 | } |
| 156 | |
| 157 | def extraVars = [] |
| 158 | if (config.seedServer) { |
| 159 | extraVars = extraVars.p(config.seedServer.extraVars) |
| 160 | .p(config.seedServer.password, "ansible_ssh_pass") |
| 161 | .p(config.seedServer.sudoPassword, "ansible_sudo_pass") |
| 162 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 163 | .p(config.seedServer.management_ip, "management_ip") |
| 164 | .p(config.seedServer.management_network, "management_network") |
| 165 | .p(config.seedServer.management_iface, "management_iface") |
| 166 | .p(config.seedServer.external_ip, "external_ip") |
| 167 | .p(config.seedServer.external_network, "external_network") |
| 168 | .p(config.seedServer.external_iface, "external_iface") |
| 169 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 170 | .p(config.seedServer.fabric_network, "fabric_network") |
| 171 | .p(config.seedServer.fabric_iface, "fabric_iface") |
| 172 | .p(config.seedServer.domain, "domain") |
| 173 | .p(config.seedServer.virtualbox_support, "virtualbox_support") |
| 174 | .p(config.seedServer.power_helper_user, "power_helper_user") |
| 175 | .p(config.seedServer.power_helper_host, "power_helper_host") |
| 176 | .p(config.seedServer.port, "ansible_ssh_port") |
| 177 | } |
| 178 | |
| 179 | if (config.otherServers) { |
| 180 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 181 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 182 | .p(config.otherServers.role, "prov_role") |
| 183 | } |
| 184 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 185 | extraVars = extraVars.p("$targetReg", "deploy_docker_registry") |
| 186 | .p("$targetTag", "deploy_docker_tag") |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 187 | |
| 188 | def skipTags = [].p(config.seedServer.skipTags) |
| 189 | |
| 190 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml" |
| 191 | } |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 192 | |
| 193 | task deploySingle (type: Exec) { |
| 194 | dependsOn copyAnsibleInventory |
| 195 | |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 196 | executable = "ansible-playbook" |
| 197 | args = ["-i", "inventory/single-prod"] |
| 198 | |
| 199 | if ( config.seedServer.user != null && config.seedServer.user != "" ) { |
| 200 | args = args << "--user=$config.seedServer.user" |
| 201 | } |
| 202 | |
| 203 | def extraVars = [] |
| 204 | if (config.seedServer) { |
| 205 | extraVars = extraVars.p(config.seedServer.extraVars) |
| 206 | .p(config.seedServer.password, "ansible_ssh_pass") |
| 207 | .p(config.seedServer.sudoPassword, "ansible_sudo_pass") |
| 208 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 209 | .p(config.seedServer.management_ip, "management_ip") |
| 210 | .p(config.seedServer.management_network, "management_network") |
| 211 | .p(config.seedServer.management_iface, "management_iface") |
| 212 | .p(config.seedServer.external_ip, "external_ip") |
| 213 | .p(config.seedServer.external_network, "external_network") |
| 214 | .p(config.seedServer.external_iface, "external_iface") |
| 215 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 216 | .p(config.seedServer.fabric_network, "fabric_network") |
| 217 | .p(config.seedServer.fabric_iface, "fabric_iface") |
| 218 | .p(config.seedServer.domain, "domain") |
| 219 | .p(config.seedServer.virtualbox_support, "virtualbox_support") |
| 220 | .p(config.seedServer.power_helper_user, "power_helper_user") |
| 221 | .p(config.seedServer.power_helper_host, "power_helper_host") |
| 222 | .p(config.seedServer.port, "ansible_ssh_port") |
| 223 | } |
| 224 | |
| 225 | if (config.otherServers) { |
| 226 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 227 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 228 | .p(config.otherServers.role, "prov_role") |
| 229 | } |
| 230 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 231 | extraVars = extraVars.p("$targetReg", "deploy_docker_registry") |
| 232 | .p("$targetTag", "deploy_docker_tag") |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 233 | |
| 234 | def skipTags = [].p(config.seedServer.skipTags) |
| 235 | |
| 236 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-single-playbook.yml" |
| 237 | } |
| 238 | |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 239 | task postDeployTests (type: Exec) { |
| 240 | dependsOn copyAnsibleInventory |
| 241 | |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 242 | executable = "ansible-playbook" |
| 243 | args = ["-i", "inventory/single-prod"] |
| 244 | |
| 245 | if ( config.seedServer.user != null && config.seedServer.user != "" ) { |
| 246 | args = args << "--user=$config.seedServer.user" |
| 247 | } |
| 248 | |
| 249 | def extraVars = [] |
| 250 | if (config.seedServer) { |
| 251 | extraVars = extraVars.p(config.seedServer.extraVars) |
| 252 | .p(config.seedServer.password, "ansible_ssh_pass") |
| 253 | .p(config.seedServer.sudoPassword, "ansible_sudo_pass") |
| 254 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 255 | .p(config.seedServer.management_ip, "management_ip") |
| 256 | .p(config.seedServer.management_network, "management_network") |
| 257 | .p(config.seedServer.management_iface, "management_iface") |
| 258 | .p(config.seedServer.external_ip, "external_ip") |
| 259 | .p(config.seedServer.external_network, "external_network") |
| 260 | .p(config.seedServer.external_iface, "external_iface") |
| 261 | .p(config.seedServer.fabric_ip, "fabric_ip") |
| 262 | .p(config.seedServer.fabric_network, "fabric_network") |
| 263 | .p(config.seedServer.fabric_iface, "fabric_iface") |
| 264 | .p(config.seedServer.domain, "domain") |
| 265 | .p(config.seedServer.virtualbox_support, "virtualbox_support") |
| 266 | .p(config.seedServer.power_helper_user, "power_helper_user") |
| 267 | .p(config.seedServer.power_helper_host, "power_helper_host") |
| 268 | .p(config.seedServer.port, "ansible_ssh_port") |
| 269 | } |
| 270 | |
| 271 | if (config.otherServers) { |
| 272 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 273 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 274 | .p(config.otherServers.role, "prov_role") |
| 275 | } |
| 276 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 277 | extraVars = extraVars.p("$targetReg", "deploy_docker_registry") |
| 278 | .p("$targetTag", "deploy_docker_tag") |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 279 | |
| 280 | def skipTags = [].p(config.seedServer.skipTags) |
| 281 | |
| 282 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml" |
| 283 | } |
| 284 | |