blob: 92c7c3931cc6bf523eef7db4e84b50df33d9e63a [file] [log] [blame]
Andy Bavieradea0fd2016-07-06 05:26:26 -04001/*
2 * Copyright 2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import org.opencord.gradle.rules.*
18import org.yaml.snakeyaml.Yaml
19
20allprojects {
21 apply plugin: 'base'
22 apply plugin: 'de.gesellix.docker'
23 //apply plugin: 'com.tmiyamon.config'
24
25 docker {
26 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
27 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
28 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
29 // authConfigPlain = [
30 // "username" : "joe",
31 // "password" : "some-pw-as-needed",
32 // "email" : "joe@acme.com",
33 // "serveraddress" : "https://index.docker.io/v1/"
34 // ]
35 }
36}
37
38ext {
39
40 // Upstream registry to simplify filling out the comps table below
41 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
42
43 // Target registry to be used to publish docker images needed for deployment
44 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
45
46 // The tag used to tag the docker images push to the target registry
47 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
48
49 // Component table
50 comps = [
51 ]
52
53 // Deployment target config file (yaml format); this can be overwritten from the command line
54 // using the -PdeployConfig=<file-path> syntax.
55 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
56
57}
58
Andy Bavier6dbb1a32016-07-06 07:12:50 -040059task copyAnsibleInventory(type: Copy) {
60 File configFile = new File(deployConfig)
61 def yaml = new Yaml()
62 def config = yaml.load(configFile.newReader())
63
64 from 'inventory/templates/single-prod'
65 into 'inventory'
66 expand([
67 prod: config.seedServer.ip,
68 ])
69}
70
Andy Bavieradea0fd2016-07-06 05:26:26 -040071// ------------- PlaceHolders ----------------
72
73task updateDocker (type: Exec) {
74 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
75}
76
77task prime {
78 // TODO this is a place-holder.
Andy Bavier6dbb1a32016-07-06 07:12:50 -040079 // dependsOn updateDocker
Andy Bavieradea0fd2016-07-06 05:26:26 -040080 doFirst {
81 println "Using deployment config: $deployConfig"
82 File configFile = new File(deployConfig)
83 def yaml = new Yaml()
84 def config = yaml.load(configFile.newReader())
85 println "Config: $config"
86 println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
87 }
88}
89
90// ---------------- Useful tasks ----------------
91
92task fetchUpstreamImages {
93 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
94}
95
96task fetchGitSubmodules {
97 comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } }
98}
99
100task fetch {
101 dependsOn fetchUpstreamImages
102 dependsOn fetchGitSubmodules
103}
104
105task publishImages {
106 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
107}
108
109task publish {
110 dependsOn publishImages
111}
112
113tasks.addRule(new DockerFetchRule(project))
114tasks.addRule(new DockerPublishRule(project))
115tasks.addRule(new DockerTagRule(project))
116tasks.addRule(new GitSubmoduleUpdateRule(project))
117
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400118task deploy (type: Exec) {
119 dependsOn copyAnsibleInventory
Andy Bavieradea0fd2016-07-06 05:26:26 -0400120
Andy Bavier6dbb1a32016-07-06 07:12:50 -0400121 println "Using deployment config: $deployConfig"
122 File configFile = new File(deployConfig)
123 def yaml = new Yaml()
124 def config = yaml.load(configFile.newReader())
125
126 executable = "ansible-playbook"
127 args = ["-i", "inventory/single-prod"]
128
129 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
130 args = args << "--user=$config.seedServer.user"
131 }
132
133 def extraVars = []
134 if (config.seedServer) {
135 extraVars = extraVars.p(config.seedServer.extraVars)
136 .p(config.seedServer.password, "ansible_ssh_pass")
137 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
138 .p(config.seedServer.fabric_ip, "fabric_ip")
139 .p(config.seedServer.management_ip, "management_ip")
140 .p(config.seedServer.management_network, "management_network")
141 .p(config.seedServer.management_iface, "management_iface")
142 .p(config.seedServer.external_ip, "external_ip")
143 .p(config.seedServer.external_network, "external_network")
144 .p(config.seedServer.external_iface, "external_iface")
145 .p(config.seedServer.fabric_ip, "fabric_ip")
146 .p(config.seedServer.fabric_network, "fabric_network")
147 .p(config.seedServer.fabric_iface, "fabric_iface")
148 .p(config.seedServer.domain, "domain")
149 .p(config.seedServer.virtualbox_support, "virtualbox_support")
150 .p(config.seedServer.power_helper_user, "power_helper_user")
151 .p(config.seedServer.power_helper_host, "power_helper_host")
152 .p(config.seedServer.port, "ansible_ssh_port")
153 }
154
155 if (config.otherServers) {
156 extraVars = extraVars.p(config.otherServers.location, "prov_location")
157 .p(config.otherServers.rolesPath, "prov_role_path")
158 .p(config.otherServers.role, "prov_role")
159 }
160
161 if (config.docker) {
162 extraVars = extraVars.p(config.docker.registry, "docker_registry")
163 .p(config.docker.imageVersion, "docker_image_version")
164 }
165
166 def skipTags = [].p(config.seedServer.skipTags)
167
168 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml"
169}