blob: a97ce4bf77c024cc88f396111559ec237c086772 [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
David K. Bainbridge3da136f2016-11-15 17:22:06 -080040 // Deployment target config file (yaml format); this can be overwritten from the command line
41 // using the -PdeployConfig=<file-path> syntax.
42 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
43
44 println "Using deployment config: $deployConfig"
45 File configFile = new File(deployConfig)
46 def yaml = new Yaml()
47 config = yaml.load(configFile.newReader())
48
alshabib28a35f92016-06-03 00:16:26 -070049 // Upstream registry to simplify filling out the comps table below
50 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
51
alshabib676bef52016-06-02 12:18:32 -070052 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge3da136f2016-11-15 17:22:06 -080053 targetReg = project.hasProperty('targetReg')
54 ? project.getProperty('targetReg')
55 : config.docker && config.docker.registry
56 ? config.docker.registry
57 : config.seedServer.ip
58 ? config.seedServer.ip + ":5000"
59 : 'localhost:5000'
alshabib676bef52016-06-02 12:18:32 -070060
61 // The tag used to tag the docker images push to the target registry
David K. Bainbridge3da136f2016-11-15 17:22:06 -080062 targetTag = project.hasProperty('targetTag')
63 ? project.getProperty('targetTag')
64 : config.docker && config.docker.imageVersion
65 ? config.docker.imageVersion
66 : 'candidate'
alshabib676bef52016-06-02 12:18:32 -070067}
68
alshabib676bef52016-06-02 12:18:32 -070069
alshabib28a35f92016-06-03 00:16:26 -070070task buildOnosApps (type: Exec) {
71 workingDir './apps'
Charles Chancafaca52016-06-23 16:40:41 -070072 commandLine 'mvn', 'clean', 'install', '-U'
alshabib28a35f92016-06-03 00:16:26 -070073}
74
75task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
76 workingDir './'
David K. Bainbridge64030c42016-07-29 00:01:15 -070077 commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', '.'
alshabib28a35f92016-06-03 00:16:26 -070078}
79
80task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
alshabib853a4032016-06-16 14:54:34 -070081 commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
alshabib28a35f92016-06-03 00:16:26 -070082}
83
84task tagMavenRepoImage (type: Exec) {
alshabib853a4032016-06-16 14:54:34 -070085 commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
alshabib28a35f92016-06-03 00:16:26 -070086}
87
88task publishMavenRepoImage (type: Exec) {
89 dependsOn tagMavenRepoImage
90 commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
91}
92
alshabib853a4032016-06-16 14:54:34 -070093List.metaClass.asParam = { prefix, sep ->
94 if (delegate.size() == 0) {
95 ""
96 }
97 String result = "--" + prefix + "="
98 String p = ""
99 delegate.each {
100 result += p + "${it}"
101 p = sep
102 }
103 result
104}
105
106List.metaClass.p = { value, name ->
107 if (value != null && value != "") {
108 delegate << name + "=" + value
109 } else {
110 delegate
111 }
112}
113
114List.metaClass.p = { spec ->
115 if (spec != null && spec != "") {
116 delegate += spec
117 } else {
118 delegate
119 }
120}
121
alshabib28a35f92016-06-03 00:16:26 -0700122// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
123
alshabib676bef52016-06-02 12:18:32 -0700124task fetch {
alshabibe0b3e702016-08-29 14:43:01 -0700125 logger.info 'Nothing to fetch for me'
alshabib676bef52016-06-02 12:18:32 -0700126}
127
alshabibe0b3e702016-08-29 14:43:01 -0700128task buildImages {
alshabib28a35f92016-06-03 00:16:26 -0700129 dependsOn buildOnosApps
130 dependsOn copyLocalRepo
131 dependsOn buildRepoImage
alshabib676bef52016-06-02 12:18:32 -0700132}
133
alshabibf751d342016-06-17 14:20:30 -0700134task publish {
alshabib28a35f92016-06-03 00:16:26 -0700135 dependsOn publishMavenRepoImage
alshabib676bef52016-06-02 12:18:32 -0700136}
137
alshabibe0b3e702016-08-29 14:43:01 -0700138task deploy (type: Exec) {
alshabibe5e26ca2016-06-17 10:12:54 -0700139 executable = "ansible-playbook"
140 args = ["-i", config.seedServer.ip + ',']
alshabib853a4032016-06-16 14:54:34 -0700141
alshabibe5e26ca2016-06-17 10:12:54 -0700142 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
143 args = args << "--user=$config.seedServer.user"
144 }
145
146 def extraVars = []
147 if (config.seedServer) {
148 extraVars = extraVars.p(config.seedServer.extraVars)
149 .p(config.seedServer.password, "ansible_ssh_pass")
150 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
151 .p(config.seedServer.domain, "domain")
David K. Bainbridge06fbe142016-07-06 16:00:07 -0700152 .p(config.seedServer.port, "ansible_ssh_port")
alshabibe5e26ca2016-06-17 10:12:54 -0700153 }
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", " ")) << "mavenrepo.yml"
alshabib853a4032016-06-16 14:54:34 -0700169}
170
171
alshabib9c7e0282016-06-03 13:50:29 -0700172// Depending on the version of the apps this will either make a release or publish a snapshot
173task release (type: Exec) {
174 workingDir './apps'
175 commandLine 'mvn', 'clean', 'deploy'
176}