blob: ae02221e4feef58fb9bf6ef5b53a7e1336be33bf [file] [log] [blame]
alshabib676bef52016-06-02 12:18:32 -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 */
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 appVersion = null
41
alshabib28a35f92016-06-03 00:16:26 -070042 // Upstream registry to simplify filling out the comps table below
43 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
44
alshabib676bef52016-06-02 12:18:32 -070045 // Target registry to be used to publish docker images needed for deployment
46 targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'
47
48 // The tag used to tag the docker images push to the target registry
49 targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'
50
51 comps = [
52 'aaa' : [
53 'type': 'gitmodule',
54 'upstream': 'https://gerrit.opencord.org/aaa',
55 'branch' : 'master',
56 'tag' : appVersion,
57 'componentDir': './apps/aaa'
58 ],
59 'vtn' : [
60 'type': 'gitmodule',
61 'upstream': 'https://gerrit.opencord.org/vtn',
62 'branch' : 'master',
63 'tag' : appVersion,
64 'componentDir': './apps/vtn'
65 ],
66 'mcast' : [
67 'type': 'gitmodule',
68 'upstream': 'https://gerrit.opencord.org/mcast',
69 'branch' : 'master',
70 'tag' : appVersion,
71 'componentDir': './apps/mcast'
72 ],
73 'igmp' : [
74 'type': 'gitmodule',
75 'upstream': 'https://gerrit.opencord.org/igmp',
76 'branch' : 'master',
77 'tag' : appVersion,
78 'componentDir': './apps/igmp'
79 ],
80 'olt' : [
81 'type': 'gitmodule',
82 'upstream': 'https://gerrit.opencord.org/olt',
83 'branch' : 'master',
84 'tag' : appVersion,
85 'componentDir': './apps/olt'
86 ],
87 'config' : [
88 'type': 'gitmodule',
89 'upstream': 'https://gerrit.opencord.org/config',
90 'branch' : 'master',
91 'tag' : appVersion,
92 'componentDir': './apps/config'
93 ]
94 ]
95}
96
alshabib676bef52016-06-02 12:18:32 -070097
98task fetchGitSubmodules {
99 comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } }
100}
101
alshabib28a35f92016-06-03 00:16:26 -0700102task buildOnosApps (type: Exec) {
103 workingDir './apps'
104 commandLine 'mvn', 'clean', 'install'
105}
106
107task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
108 workingDir './'
109 commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', 'repository'
110}
111
112task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
alshabib853a4032016-06-16 14:54:34 -0700113 commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
alshabib28a35f92016-06-03 00:16:26 -0700114}
115
116task tagMavenRepoImage (type: Exec) {
alshabib853a4032016-06-16 14:54:34 -0700117 commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
alshabib28a35f92016-06-03 00:16:26 -0700118}
119
120task publishMavenRepoImage (type: Exec) {
121 dependsOn tagMavenRepoImage
122 commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
123}
124
alshabib853a4032016-06-16 14:54:34 -0700125List.metaClass.asParam = { prefix, sep ->
126 if (delegate.size() == 0) {
127 ""
128 }
129 String result = "--" + prefix + "="
130 String p = ""
131 delegate.each {
132 result += p + "${it}"
133 p = sep
134 }
135 result
136}
137
138List.metaClass.p = { value, name ->
139 if (value != null && value != "") {
140 delegate << name + "=" + value
141 } else {
142 delegate
143 }
144}
145
146List.metaClass.p = { spec ->
147 if (spec != null && spec != "") {
148 delegate += spec
149 } else {
150 delegate
151 }
152}
153
alshabib28a35f92016-06-03 00:16:26 -0700154// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
155
alshabib676bef52016-06-02 12:18:32 -0700156task fetch {
157 dependsOn fetchGitSubmodules
158}
159
alshabib28a35f92016-06-03 00:16:26 -0700160task buildImages (dependsOn: fetch) {
161 dependsOn buildOnosApps
162 dependsOn copyLocalRepo
163 dependsOn buildRepoImage
alshabib676bef52016-06-02 12:18:32 -0700164}
165
alshabib47291352016-06-10 11:08:24 +0900166task publish (dependsOn: buildImages) {
alshabib28a35f92016-06-03 00:16:26 -0700167 dependsOn publishMavenRepoImage
alshabib676bef52016-06-02 12:18:32 -0700168}
169
alshabib853a4032016-06-16 14:54:34 -0700170task deploy (dependsOn: publishMavenRepoImage, type: Exec) {
171 println "Using deployment config: $deployConfig"
172 File configFile = new File(deployConfig)
173 def yaml = new Yaml()
174 def config = yaml.load(configFile.newReader())
175
176 executable = "ansible-playbook"
177 args = ["-i", config.seedServer.ip + ',']
178
179 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
180 args = args << "--user=$config.seedServer.user"
181 }
182
183 def extraVars = []
184 if (config.seedServer) {
185 extraVars = extraVars.p(config.seedServer.extraVars)
186 .p(config.seedServer.password, "ansible_ssh_pass")
187 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
188 .p(config.seedServer.domain, "domain")
189 }
190
191 if (config.otherServers) {
192 extraVars = extraVars.p(config.otherServers.location, "prov_location")
193 .p(config.otherServers.rolesPath, "prov_role_path")
194 .p(config.otherServers.role, "prov_role")
195 }
196
197 if (config.docker) {
198 extraVars = extraVars.p(config.docker.registry, "docker_registry")
199 .p(config.docker.imageVersion, "docker_image_version")
200 }
201
202 def skipTags = [].p(config.seedServer.skipTags)
203
204 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml"
205}
206
207
alshabib9c7e0282016-06-03 13:50:29 -0700208// Depending on the version of the apps this will either make a release or publish a snapshot
209task release (type: Exec) {
210 workingDir './apps'
211 commandLine 'mvn', 'clean', 'deploy'
212}
213
alshabib676bef52016-06-02 12:18:32 -0700214tasks.addRule(new GitSubmoduleUpdateRule(project))