Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [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 | */ |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 16 | import org.opencord.gradle.rules.* |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 17 | import org.yaml.snakeyaml.Yaml |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 18 | |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 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 | } |
| 36 | |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 37 | ext { |
| 38 | |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 39 | // Upstream registry to simplify filling out the comps table below |
| 40 | upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io' |
| 41 | |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 42 | // Deployment target config file (yaml format); this can be overwritten from the command line |
| 43 | // using the -PdeployConfig=<file-path> syntax. |
| 44 | deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml' |
David K. Bainbridge | 19b8d27 | 2016-05-26 21:20:43 -0700 | [diff] [blame] | 45 | |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 46 | println "Using deployment config: $deployConfig" |
| 47 | File configFile = new File(deployConfig) |
| 48 | def yaml = new Yaml() |
| 49 | config = yaml.load(configFile.newReader()) |
| 50 | |
| 51 | // Target registry to be used to publish docker images needed for deployment |
| 52 | targetReg = project.hasProperty('targetReg') |
| 53 | ? project.getProperty('targetReg') |
| 54 | : config.docker && config.docker.registry |
| 55 | ? config.docker.registry |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 56 | : config.headnode.ip |
| 57 | ? config.headnode.ip + ":5000" |
David K. Bainbridge | c9cacd3 | 2016-11-15 15:10:06 -0800 | [diff] [blame] | 58 | : 'localhost:5000' |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 59 | |
| 60 | // The tag used to tag the docker images push to the target registry |
| 61 | targetTag = project.hasProperty('targetTag') |
| 62 | ? project.getProperty('targetTag') |
| 63 | : config.docker && config.docker.imageVersion |
| 64 | ? config.docker.imageVersion |
| 65 | : 'candidate' |
| 66 | |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 67 | comps = [ |
| 68 | 'consul': [ |
| 69 | 'type': 'image', |
| 70 | 'upstream': upstreamReg, |
| 71 | 'name': 'consul', |
| 72 | 'digest': 'sha256:0dc990ff3c44d5b5395475bcc5ebdae4fc8b67f69e17942a8b9793b3df74d290' |
| 73 | ] |
| 74 | ] |
| 75 | } |
| 76 | |
| 77 | task fetchUpstreamImages { |
| 78 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } } |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 79 | } |
| 80 | |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 81 | // Switch Configuration Image |
| 82 | |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 83 | def getBuildTimestamp() { |
| 84 | def cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")) |
| 85 | def date = cal.getTime() |
David K. Bainbridge | 151e845 | 2016-12-19 23:05:51 -0800 | [diff] [blame] | 86 | def formattedDate = date.format("yyyy-MM-dd'T'HH:mm:ssZ") |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 87 | return formattedDate |
| 88 | } |
| 89 | |
David K. Bainbridge | 151e845 | 2016-12-19 23:05:51 -0800 | [diff] [blame] | 90 | def getCommitDate = { -> |
| 91 | def stdOut = new ByteArrayOutputStream() |
| 92 | exec { |
| 93 | commandLine "git", "log", "--pretty=format:%cd", "--date=format:%FT%T%z", "-n", "1" |
| 94 | standardOutput = stdOut |
| 95 | } |
| 96 | return stdOut.toString().trim() |
| 97 | } |
| 98 | |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 99 | def getCommitHash = { -> |
| 100 | def hashStdOut = new ByteArrayOutputStream() |
| 101 | exec { |
David K. Bainbridge | 151e845 | 2016-12-19 23:05:51 -0800 | [diff] [blame] | 102 | commandLine "git", "log", "--pretty=format:%H", "-n", "1" |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 103 | standardOutput = hashStdOut |
| 104 | } |
| 105 | return hashStdOut.toString().trim() |
| 106 | } |
| 107 | |
David K. Bainbridge | d4e3f62 | 2017-01-12 14:07:54 -0800 | [diff] [blame] | 108 | def isModified = { -> |
| 109 | def statusOut = new ByteArrayOutputStream() |
| 110 | def branchesOut = new ByteArrayOutputStream() |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 111 | exec { |
David K. Bainbridge | d4e3f62 | 2017-01-12 14:07:54 -0800 | [diff] [blame] | 112 | commandLine "bash", "-c", "repo --color=never --no-pager status . | tail -n +2 | wc -l" |
| 113 | standardOutput = statusOut |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 114 | } |
David K. Bainbridge | d4e3f62 | 2017-01-12 14:07:54 -0800 | [diff] [blame] | 115 | exec { |
| 116 | commandLine "bash", "-c", "repo --color=never --no-pager branches | wc -l" |
| 117 | standardOutput = branchesOut |
| 118 | } |
| 119 | def statusVal = statusOut.toString().trim() |
| 120 | def branchesVal = branchesOut.toString().trim() |
| 121 | |
| 122 | return statusVal != "0" || branchesVal != "0" |
| 123 | } |
| 124 | |
| 125 | def getBranchName = { -> |
| 126 | def stdout = new ByteArrayOutputStream() |
| 127 | exec { |
| 128 | commandLine "bash", "-c", "repo --color=never --no-pager info -l -o | grep 'Manifest branch:' | awk '{print \$NF}'" |
| 129 | standardOutput = stdout |
| 130 | } |
| 131 | def val = stdout.toString().trim() |
| 132 | if ( isModified() != "0" ) { |
| 133 | val += '[modified]' |
| 134 | } |
| 135 | return val |
David K. Bainbridge | de0d926 | 2016-09-13 20:12:06 -0700 | [diff] [blame] | 136 | } |
David K. Bainbridge | 6e23ac8 | 2016-12-07 12:55:41 -0800 | [diff] [blame] | 137 | |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 138 | task buildSwitchqImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 139 | workingDir 'switchq' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 140 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | task publishSwitchqImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 144 | workingDir 'switchq' |
| 145 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 146 | } |
| 147 | |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 148 | // IP Allocator Image |
| 149 | |
David K. Bainbridge | 8bc905c | 2016-05-31 14:07:10 -0700 | [diff] [blame] | 150 | task buildAllocationImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 151 | workingDir 'ip-allocator' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 152 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
David K. Bainbridge | 8bc905c | 2016-05-31 14:07:10 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | task publishAllocationImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 156 | workingDir 'ip-allocator' |
| 157 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
David K. Bainbridge | 8bc905c | 2016-05-31 14:07:10 -0700 | [diff] [blame] | 158 | } |
| 159 | |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 160 | // Provisioner Image |
| 161 | |
David K. Bainbridge | f0da873 | 2016-06-01 16:15:37 -0700 | [diff] [blame] | 162 | task buildProvisionerImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 163 | workingDir 'provisioner' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 164 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
David K. Bainbridge | f0da873 | 2016-06-01 16:15:37 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | task publishProvisionerImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 168 | workingDir 'provisioner' |
| 169 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
David K. Bainbridge | f0da873 | 2016-06-01 16:15:37 -0700 | [diff] [blame] | 170 | } |
| 171 | |
gunjan5 | e9bdd1d | 2016-07-13 14:59:33 -0700 | [diff] [blame] | 172 | // Config Generator Image |
| 173 | |
| 174 | task buildConfigGeneratorImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 175 | workingDir 'config-generator' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 176 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
gunjan5 | e9bdd1d | 2016-07-13 14:59:33 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | task publishConfigGeneratorImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 180 | workingDir 'config-generator' |
| 181 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
gunjan5 | e9bdd1d | 2016-07-13 14:59:33 -0700 | [diff] [blame] | 182 | } |
| 183 | |
David K. Bainbridge | 9d1e02d | 2016-06-22 09:22:16 -0700 | [diff] [blame] | 184 | // Automation Image |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 185 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 186 | task buildAutomationImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 187 | workingDir 'automation' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 188 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 189 | } |
| 190 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 191 | task publishAutomationImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 192 | workingDir 'automation' |
| 193 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 196 | // DHCP Harvester Images |
| 197 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 198 | task buildHarvesterImage(type: Exec) { |
David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame] | 199 | workingDir 'harvester' |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 200 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'build' |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | task publishHarvesterImage(type: Exec) { |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 204 | workingDir 'harvester' |
| 205 | commandLine 'make', "DOCKER_TAG=$targetTag", "DOCKER_REGISTRY=$targetReg", 'publish' |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 209 | |
alshabib | 462f625 | 2016-08-29 16:15:28 -0700 | [diff] [blame] | 210 | task updateDocker (type: Exec) { |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 211 | commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg" |
| 212 | } |
| 213 | |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 214 | // To be used to fetch upstream binaries, clone repos, etc. |
| 215 | task fetch(type: Exec) { |
| 216 | // this is where we fetch upstream artifacts that we do not need internet for the build phase" |
| 217 | // Placeholdr example: |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 218 | dependsOn fetchUpstreamImages |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 219 | commandLine "docker", "pull", "golang:alpine" |
| 220 | commandLine "docker", "pull", "python:2.7-alpine" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // To be used to generate all needed binaries that need to be present on the target |
| 224 | // as docker images in the local docker runner. |
| 225 | task buildImages { |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 226 | dependsOn buildHarvesterImage |
David K. Bainbridge | 9d1e02d | 2016-06-22 09:22:16 -0700 | [diff] [blame] | 227 | dependsOn buildAutomationImage |
David K. Bainbridge | 8bc905c | 2016-05-31 14:07:10 -0700 | [diff] [blame] | 228 | dependsOn buildAllocationImage |
David K. Bainbridge | f0da873 | 2016-06-01 16:15:37 -0700 | [diff] [blame] | 229 | dependsOn buildProvisionerImage |
gunjan5 | e9bdd1d | 2016-07-13 14:59:33 -0700 | [diff] [blame] | 230 | dependsOn buildConfigGeneratorImage |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 231 | dependsOn buildSwitchqImage |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 234 | task publish { |
alshabib | 462f625 | 2016-08-29 16:15:28 -0700 | [diff] [blame] | 235 | //FIXME: This works because the upstream project primes the nodes before running this. |
David K. Bainbridge | 59bdb54 | 2016-07-01 11:07:45 -0700 | [diff] [blame] | 236 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } } |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 237 | dependsOn publishHarvesterImage |
David K. Bainbridge | 9d1e02d | 2016-06-22 09:22:16 -0700 | [diff] [blame] | 238 | dependsOn publishAutomationImage |
David K. Bainbridge | 8bc905c | 2016-05-31 14:07:10 -0700 | [diff] [blame] | 239 | dependsOn publishAllocationImage |
David K. Bainbridge | f0da873 | 2016-06-01 16:15:37 -0700 | [diff] [blame] | 240 | dependsOn publishProvisionerImage |
gunjan5 | e9bdd1d | 2016-07-13 14:59:33 -0700 | [diff] [blame] | 241 | dependsOn publishConfigGeneratorImage |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 242 | dependsOn publishSwitchqImage |
David K. Bainbridge | efa951d | 2016-05-26 10:54:25 -0700 | [diff] [blame] | 243 | } |
| 244 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 245 | // ~~~~~~~~~~~~~~~~~~~ Deployment / Test Tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 246 | |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 247 | List.metaClass.asParam = { prefix, sep -> |
| 248 | if (delegate.size() == 0) { |
| 249 | "" |
| 250 | } |
| 251 | String result = "--" + prefix + "=" |
| 252 | String p = "" |
| 253 | delegate.each { |
| 254 | result += p + "${it}" |
| 255 | p = sep |
| 256 | } |
| 257 | result |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 258 | } |
| 259 | |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 260 | List.metaClass.p = { value, name -> |
| 261 | if (value != null && value != "") { |
| 262 | delegate << name + "=" + value |
| 263 | } else { |
| 264 | delegate |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | List.metaClass.p = { spec -> |
| 269 | if (spec != null && spec != "") { |
| 270 | delegate += spec |
| 271 | } else { |
| 272 | delegate |
| 273 | } |
| 274 | } |
| 275 | |
alshabib | 462f625 | 2016-08-29 16:15:28 -0700 | [diff] [blame] | 276 | task prime (type: Exec) { |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 277 | executable = "ansible-playbook" |
Zack Williams | 642388d | 2017-04-12 22:39:15 -0700 | [diff] [blame] | 278 | args = ["-i", '../genconfig/cord-inv'] |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 279 | |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 280 | if ( config.headnode.ansible_user != null && config.headnode.ansible_user != "" ) { |
| 281 | args = args << "--user=$config.headnode.ansible_user" |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 282 | } |
| 283 | |
David K. Bainbridge | 5ba01a9 | 2016-08-16 14:58:31 -0700 | [diff] [blame] | 284 | if ( config.debug ) { |
| 285 | args = args << "-vvvv" |
| 286 | } |
| 287 | |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 288 | def extraVars = [] |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 289 | if (config.common) { |
| 290 | extraVars = extraVars.p(config.common.extraVars) |
| 291 | .p(config.headnode.ansible_ssh_pass, "ansible_ssh_pass") |
| 292 | .p(config.headnode.ansible_become_pass, "ansible_become_pass") |
| 293 | .p(config.headnode.ansible_ssh_port, "ansible_ssh_port") |
| 294 | .p(config.common.fabric_ip, "fabric_ip") |
| 295 | .p(config.common.fabric_range_low, "fabric_range_low") |
| 296 | .p(config.common.fabric_range_high, "fabric_range_high") |
| 297 | .p(config.common.management_ip, "management_ip") |
| 298 | .p(config.common.management_range_low, "management_range_low") |
| 299 | .p(config.common.management_range_high, "management_range_high") |
| 300 | .p(config.common.management_gw, "management_gw") |
| 301 | .p(config.common.management_bc, "management_bc") |
| 302 | .p(config.common.management_network, "management_network") |
| 303 | .p(config.common.management_iface, "management_iface") |
| 304 | .p(config.common.external_ip, "external_ip") |
| 305 | .p(config.common.external_gw, "external_gw") |
| 306 | .p(config.common.external_bc, "external_bc") |
| 307 | .p(config.common.external_network, "external_network") |
| 308 | .p(config.common.external_iface, "external_iface") |
| 309 | .p(config.common.fabric_iface, "fabric_iface") |
| 310 | .p(config.common.domain, "domain") |
| 311 | .p(config.common.virtualbox_support, "virtualbox_support") |
| 312 | .p(config.common.power_helper_user, "power_helper_user") |
| 313 | .p(config.common.power_helper_host, "power_helper_host") |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 314 | } |
| 315 | |
David K. Bainbridge | 8b17904 | 2016-11-30 15:38:42 -0800 | [diff] [blame] | 316 | if (config.passwords) { |
| 317 | extraVars = extraVars.p(config.passwords.compute_node, "password_compute_node") |
| 318 | .p(config.passwords.maas_admin, "password_maas_admin") |
| 319 | .p(config.passwords.maas_user, "password_maas_user") |
| 320 | } |
| 321 | |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 322 | if (config.otherServers) { |
| 323 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 324 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 325 | .p(config.otherServers.role, "prov_role") |
| 326 | } |
| 327 | |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 328 | extraVars = extraVars.p("$targetReg", "deploy_docker_registry") |
| 329 | .p("$targetTag", "deploy_docker_tag") |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 330 | |
David K. Bainbridge | 6e23ac8 | 2016-12-07 12:55:41 -0800 | [diff] [blame] | 331 | // the password set on the compute node is skipped because this is being run against the |
| 332 | // head node and we don't want to change the head node password as this node was manualy |
David K. Bainbridge | 8b17904 | 2016-11-30 15:38:42 -0800 | [diff] [blame] | 333 | // set up. |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 334 | def skipTags = [].p(config.common.skipTags).p('set_compute_node_password') |
David K. Bainbridge | f418170 | 2016-06-17 14:44:03 -0700 | [diff] [blame] | 335 | |
| 336 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "prime-node.yml" |
| 337 | } |
| 338 | |
alshabib | 462f625 | 2016-08-29 16:15:28 -0700 | [diff] [blame] | 339 | task deployBase(type: Exec) { |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 340 | executable = "ansible-playbook" |
Zack Williams | 642388d | 2017-04-12 22:39:15 -0700 | [diff] [blame] | 341 | args = ["-i", '../genconfig/cord-inv'] |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 342 | |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 343 | if ( config.headnode.ansible_user != null && config.headnode.ansible_user != "" ) { |
| 344 | args = args << "--user=$config.headnode.ansible_user" |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 345 | } |
| 346 | |
David K. Bainbridge | 5ba01a9 | 2016-08-16 14:58:31 -0700 | [diff] [blame] | 347 | if ( config.debug ) { |
| 348 | args = args << "-vvvv" |
| 349 | } |
| 350 | |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 351 | def extraVars = [] |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 352 | if (config.common) { |
| 353 | extraVars = extraVars.p(config.common.extraVars) |
| 354 | .p(config.headnode.ansible_ssh_pass, "ansible_ssh_pass") |
| 355 | .p(config.headnode.ansible_become_pass, "ansible_become_pass") |
| 356 | .p(config.headnode.ansible_ssh_port, "ansible_ssh_port") |
| 357 | .p(config.common.fabric_ip, "fabric_ip") |
| 358 | .p(config.common.fabric_range_low, "fabric_range_low") |
| 359 | .p(config.common.fabric_range_high, "fabric_range_high") |
| 360 | .p(config.common.management_ip, "management_ip") |
| 361 | .p(config.common.management_range_low, "management_range_low") |
| 362 | .p(config.common.management_range_high, "management_range_high") |
| 363 | .p(config.common.management_gw, "management_gw") |
| 364 | .p(config.common.management_network, "management_network") |
| 365 | .p(config.common.management_iface, "management_iface") |
| 366 | .p(config.common.external_ip, "external_ip") |
| 367 | .p(config.common.external_gw, "external_gw") |
| 368 | .p(config.common.external_network, "external_network") |
| 369 | .p(config.common.external_iface, "external_iface") |
| 370 | .p(config.common.fabric_iface, "fabric_iface") |
| 371 | .p(config.common.domain, "domain") |
| 372 | .p(config.common.virtualbox_support, "virtualbox_support") |
| 373 | .p(config.common.power_helper_user, "power_helper_user") |
| 374 | .p(config.common.power_helper_host, "power_helper_host") |
David K. Bainbridge | 6ea57c1 | 2016-06-06 23:29:12 -0700 | [diff] [blame] | 375 | } |
| 376 | |
David K. Bainbridge | 8b17904 | 2016-11-30 15:38:42 -0800 | [diff] [blame] | 377 | if (config.passwords) { |
| 378 | extraVars = extraVars.p(config.passwords.compute_node, "password_compute_node") |
| 379 | .p(config.passwords.maas_admin, "password_maas_admin") |
| 380 | .p(config.passwords.maas_user, "password_maas_user") |
| 381 | } |
| 382 | |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 383 | if (config.otherServers) { |
| 384 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 385 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 386 | .p(config.otherServers.role, "prov_role") |
| 387 | } |
| 388 | |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 389 | extraVars = extraVars.p("$targetReg", "deploy_docker_registry") |
| 390 | .p("$targetTag", "deploy_docker_tag") |
David K. Bainbridge | 97ee805 | 2016-06-14 00:52:07 -0700 | [diff] [blame] | 391 | |
David K. Bainbridge | 8b17904 | 2016-11-30 15:38:42 -0800 | [diff] [blame] | 392 | // the password set on the compute node is skipped because this is being run against the |
| 393 | // head node and we don't want to change the head node password as this node was manualy |
| 394 | // set up. |
Zack Williams | b55e8ef | 2017-02-01 10:54:36 -0700 | [diff] [blame] | 395 | def skipTags = [].p(config.common.skipTags).p('set_compute_node_password') |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 396 | |
| 397 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "head-node.yml" |
David K. Bainbridge | 10b0c11 | 2016-05-24 13:17:23 -0700 | [diff] [blame] | 398 | } |
alshabib | 462f625 | 2016-08-29 16:15:28 -0700 | [diff] [blame] | 399 | |
| 400 | prime.dependsOn { |
| 401 | updateDocker |
| 402 | } |
| 403 | |
| 404 | tasks.addRule(new DockerFetchRule(project)) |
| 405 | tasks.addRule(new DockerPublishRule(project, project(':maas').prime)) |
| 406 | tasks.addRule(new DockerTagRule(project)) |
| 407 | |
| 408 | |