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