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