blob: f5120d3e265a08c94366a19d6837d213221f2332 [file] [log] [blame]
Zsolt Haraszti2a792f62016-05-12 17:49:02 -07001/*
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. Bainbridge10b0c112016-05-24 13:17:23 -070016import org.yaml.snakeyaml.Yaml
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070017
18ext {
19
20 // Target registry to be used to publish docker images needed for deployment
21 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
22
23 // The tag used to tag the docker images push to the target registry
24 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
25
David K. Bainbridge10b0c112016-05-24 13:17:23 -070026 // Deployment target config file (yaml format); this can be overwritten from the command line
27 // using the -PdeployConfig=<file-path> syntax.
28 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
David K. Bainbridge19b8d272016-05-26 21:20:43 -070029
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070030 dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070031}
32
David K. Bainbridgeb5415042016-05-13 17:06:10 -070033task buildBootstrapImage(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -070034 commandLine "$dockerPath/docker", 'build', '-t', 'cord-maas-bootstrap', './bootstrap'
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070035}
36
David K. Bainbridgeb5415042016-05-13 17:06:10 -070037task tagBootstrapImage(type: Exec) {
38 dependsOn buildBootstrapImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -070039 commandLine "$dockerPath/docker", 'tag', 'cord-maas-bootstrap', "$targetReg/cord-maas-bootstrap:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070040}
41
David K. Bainbridgeb5415042016-05-13 17:06:10 -070042task publishBootstrapImage(type: Exec) {
43 dependsOn tagBootstrapImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -070044 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-bootstrap:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070045}
46
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070047task buildAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -070048 commandLine "$dockerPath/docker", 'build', '-t', 'cord-ip-allocator', './ip-allocator'
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070049}
50
51task tagAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -070052 dependsOn buildAllocationImage
53 commandLine "$dockerPath/docker", 'tag', 'cord-ip-allocator', "$targetReg/cord-ip-allocator:$targetTag"
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070054}
55
56task publishAllocationImage(type: Exec) {
David K. Bainbridgef22dc062016-05-31 15:35:39 -070057 dependsOn tagAllocationImage
58 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-ip-allocator:$targetTag"
David K. Bainbridge8bc905c2016-05-31 14:07:10 -070059}
60
David K. Bainbridgef0da8732016-06-01 16:15:37 -070061task buildProvisionerImage(type: Exec) {
David K. Bainbridged86d96d2016-06-01 17:28:46 -070062 commandLine "$dockerPath/docker", 'build', '-t', 'cord-provisioner', './provisioner'
David K. Bainbridgef0da8732016-06-01 16:15:37 -070063}
64
65task tagProvisionerImage(type: Exec) {
66 dependsOn buildProvisionerImage
67 commandLine "$dockerPath/docker", 'tag', 'cord-provisioner', "$targetReg/cord-provisioner:$targetTag"
68}
69
70task publishProvisionerImage(type: Exec) {
71 dependsOn tagProvisionerImage
72 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-provisioner:$targetTag"
73}
74
David K. Bainbridgeb5415042016-05-13 17:06:10 -070075task buildAutomationImage(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -070076 commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
David K. Bainbridgeefa951d2016-05-26 10:54:25 -070077}
78
79task buildAutomationImageAnsible(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -070080 commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-automation:ansible", "-f", "./automation/Dockerfile.ansible", "./automation"
David K. Bainbridgeefa951d2016-05-26 10:54:25 -070081}
82
83task buildAutomationImages {
84 dependsOn buildAutomationImage
85 dependsOn buildAutomationImageAnsible
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070086}
87
David K. Bainbridgeb5415042016-05-13 17:06:10 -070088task tagAutomationImage(type: Exec) {
89 dependsOn buildAutomationImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -070090 commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation', "$targetReg/cord-maas-automation:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070091}
92
David K. Bainbridgeefa951d2016-05-26 10:54:25 -070093task tagAutomationImageAnsible(type: Exec) {
94 dependsOn buildAutomationImageAnsible
David K. Bainbridge19b8d272016-05-26 21:20:43 -070095 commandLine "$dockerPath/docker", 'tag', 'cord-maas-automation:ansible', "$targetReg/cord-maas-automation:$targetTag-ansible"
David K. Bainbridgeefa951d2016-05-26 10:54:25 -070096}
97
98task tagAutomationImages {
99 dependsOn tagAutomationImage
100 dependsOn tagAutomationImageAnsible
101}
102
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700103task publishAutomationImage(type: Exec) {
104 dependsOn tagAutomationImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700105 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700106}
107
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700108task publishAutomationImageAnsible(type: Exec) {
109 dependsOn tagAutomationImageAnsible
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700110 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-automation:$targetTag-ansible"
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700111}
112
113task publishAutomationImages {
114 dependsOn publishAutomationImage
115 dependsOn publishAutomationImageAnsible
116}
117
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700118task buildHarvesterImage(type: Exec) {
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700119 commandLine "$dockerPath/docker", 'build', '-t', "cord-maas-dhcp-harvester", "./harvester"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700120}
121
122task tagHarvesterImage(type: Exec) {
123 dependsOn buildHarvesterImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700124 commandLine "$dockerPath/docker", 'tag', 'cord-maas-dhcp-harvester', "$targetReg/cord-maas-dhcp-harvester:$targetTag"
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700125}
126
127task publishHarvesterImage(type: Exec) {
128 dependsOn tagHarvesterImage
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700129 commandLine "$dockerPath/docker", 'push', "$targetReg/cord-maas-dhcp-harvester:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700130}
131
132// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
133
134// To be used to fetch upstream binaries, clone repos, etc.
135task fetch(type: Exec) {
136 // this is where we fetch upstream artifacts that we do not need internet for the build phase"
137 // Placeholdr example:
David K. Bainbridge19b8d272016-05-26 21:20:43 -0700138 commandLine "$dockerPath/docker", "pull", "golang:alpine"
139 commandLine "$dockerPath/docker", "pull", "python:2.7-alpine"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700140}
141
142// To be used to generate all needed binaries that need to be present on the target
143// as docker images in the local docker runner.
144task buildImages {
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700145 dependsOn buildBootstrapImage
146 dependsOn buildHarvesterImage
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700147 dependsOn buildAutomationImages
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700148 dependsOn buildAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700149 dependsOn buildProvisionerImage
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700150}
151
152task tagImages {
153 dependsOn tagBootstrapImage
154 dependsOn tagHarvesterImage
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700155 dependsOn tagAutomationImages
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700156 dependsOn tagAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700157 dependsOn tagProvisionerImage
Zsolt Haraszti2a792f62016-05-12 17:49:02 -0700158}
159
160task publish {
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700161 dependsOn publishBootstrapImage
162 dependsOn publishHarvesterImage
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700163 dependsOn publishAutomationImages
David K. Bainbridge8bc905c2016-05-31 14:07:10 -0700164 dependsOn publishAllocationImage
David K. Bainbridgef0da8732016-06-01 16:15:37 -0700165 dependsOn publishProvisionerImage
David K. Bainbridgeefa951d2016-05-26 10:54:25 -0700166}
167
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700168// ~~~~~~~~~~~~~~~~~~~ Deployment / Test Tasks ~~~~~~~~~~~~~~~~~~~~~~~
169
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700170List.metaClass.asParam = { prefix, sep ->
171 if (delegate.size() == 0) {
172 ""
173 }
174 String result = "--" + prefix + "="
175 String p = ""
176 delegate.each {
177 result += p + "${it}"
178 p = sep
179 }
180 result
David K. Bainbridgeb5415042016-05-13 17:06:10 -0700181}
182
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700183List.metaClass.p = { value, name ->
184 if (value != null && value != "") {
185 delegate << name + "=" + value
186 } else {
187 delegate
188 }
189}
190
191List.metaClass.p = { spec ->
192 if (spec != null && spec != "") {
193 delegate += spec
194 } else {
195 delegate
196 }
197}
198
199task deploy (type: Exec) {
200 println "Using deployment config: $deployConfig"
201 File configFile = new File(deployConfig)
202 def yaml = new Yaml()
203 def config = yaml.load(configFile.newReader())
204
205 executable = "ansible-playbook"
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700206 args = ["-i", config.seedServer.ip + ',']
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700207
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700208 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
209 args = args << "--user=$config.seedServer.user"
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700210 }
211
212 def extraVars = []
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700213 if (config.seedServer) {
214 extraVars = extraVars.p(config.seedServer.extraVars)
215 .p(config.seedServer.password, "ansible_ssh_pass")
216 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
217 .p(config.seedServer.fabric_ip, "fabric_ip")
218 .p(config.seedServer.management_ip, "management_ip")
219 .p(config.seedServer.external_ip, "external_ip")
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700220 }
221
222 if (config.otherServers) {
223 extraVars = extraVars.p(config.otherServers.location, "prov_location")
224 .p(config.otherServers.rolesPath, "prov_role_path")
225 .p(config.otherServers.role, "prov_role")
226 }
227
David K. Bainbridge13c765c2016-05-26 11:24:22 -0700228 def skipTags = [].p(config.seedServer.skipTags)
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700229
230 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "head-node.yml"
David K. Bainbridge10b0c112016-05-24 13:17:23 -0700231}