blob: 16532369fd04b13f338491b4c65b8a2db78c744f [file] [log] [blame]
Matteo Scandolobea95272017-08-08 13:05:23 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
alshabib676bef52016-06-02 12:18:32 -070019/*
20 * Copyright 2012 the original author or authors.
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 */
34
35import org.opencord.gradle.rules.*
36import org.yaml.snakeyaml.Yaml
37
38allprojects {
39 apply plugin: 'base'
40 apply plugin: 'de.gesellix.docker'
41 //apply plugin: 'com.tmiyamon.config'
42
43 docker {
44 // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
45 // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
46 // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
47 // authConfigPlain = [
48 // "username" : "joe",
49 // "password" : "some-pw-as-needed",
50 // "email" : "joe@acme.com",
51 // "serveraddress" : "https://index.docker.io/v1/"
52 // ]
53 }
54}
55
56ext {
57
David K. Bainbridge3da136f2016-11-15 17:22:06 -080058 // Deployment target config file (yaml format); this can be overwritten from the command line
59 // using the -PdeployConfig=<file-path> syntax.
alshabib0bf710f2017-02-14 11:26:38 -080060 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : '../build/config/default.yml'
David K. Bainbridge3da136f2016-11-15 17:22:06 -080061
62 println "Using deployment config: $deployConfig"
63 File configFile = new File(deployConfig)
64 def yaml = new Yaml()
65 config = yaml.load(configFile.newReader())
66
alshabib28a35f92016-06-03 00:16:26 -070067 // Upstream registry to simplify filling out the comps table below
68 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
69
alshabib676bef52016-06-02 12:18:32 -070070 // Target registry to be used to publish docker images needed for deployment
David K. Bainbridge3da136f2016-11-15 17:22:06 -080071 targetReg = project.hasProperty('targetReg')
72 ? project.getProperty('targetReg')
73 : config.docker && config.docker.registry
74 ? config.docker.registry
Zack Williams04869e22017-02-01 13:42:18 -070075 : config.headnode.ip
76 ? config.headnode.ip + ":5000"
David K. Bainbridge3da136f2016-11-15 17:22:06 -080077 : 'localhost:5000'
alshabib676bef52016-06-02 12:18:32 -070078
79 // The tag used to tag the docker images push to the target registry
David K. Bainbridge3da136f2016-11-15 17:22:06 -080080 targetTag = project.hasProperty('targetTag')
81 ? project.getProperty('targetTag')
82 : config.docker && config.docker.imageVersion
83 ? config.docker.imageVersion
84 : 'candidate'
alshabib676bef52016-06-02 12:18:32 -070085}
86
alshabib676bef52016-06-02 12:18:32 -070087
alshabib28a35f92016-06-03 00:16:26 -070088task buildOnosApps (type: Exec) {
89 workingDir './apps'
Charles Chancafaca52016-06-23 16:40:41 -070090 commandLine 'mvn', 'clean', 'install', '-U'
alshabib28a35f92016-06-03 00:16:26 -070091}
92
93task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
94 workingDir './'
David K. Bainbridge64030c42016-07-29 00:01:15 -070095 commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', '.'
alshabib28a35f92016-06-03 00:16:26 -070096}
97
98task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
alshabib853a4032016-06-16 14:54:34 -070099 commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
alshabib28a35f92016-06-03 00:16:26 -0700100}
101
102task tagMavenRepoImage (type: Exec) {
alshabib853a4032016-06-16 14:54:34 -0700103 commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
alshabib28a35f92016-06-03 00:16:26 -0700104}
105
106task publishMavenRepoImage (type: Exec) {
107 dependsOn tagMavenRepoImage
108 commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
109}
110
alshabib853a4032016-06-16 14:54:34 -0700111List.metaClass.asParam = { prefix, sep ->
112 if (delegate.size() == 0) {
113 ""
114 }
115 String result = "--" + prefix + "="
116 String p = ""
117 delegate.each {
118 result += p + "${it}"
119 p = sep
120 }
121 result
122}
123
124List.metaClass.p = { value, name ->
125 if (value != null && value != "") {
126 delegate << name + "=" + value
127 } else {
128 delegate
129 }
130}
131
132List.metaClass.p = { spec ->
133 if (spec != null && spec != "") {
134 delegate += spec
135 } else {
136 delegate
137 }
138}
139
alshabib28a35f92016-06-03 00:16:26 -0700140// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
141
alshabib676bef52016-06-02 12:18:32 -0700142task fetch {
alshabibe0b3e702016-08-29 14:43:01 -0700143 logger.info 'Nothing to fetch for me'
alshabib676bef52016-06-02 12:18:32 -0700144}
145
alshabibe0b3e702016-08-29 14:43:01 -0700146task buildImages {
alshabib28a35f92016-06-03 00:16:26 -0700147 dependsOn buildOnosApps
148 dependsOn copyLocalRepo
149 dependsOn buildRepoImage
alshabib676bef52016-06-02 12:18:32 -0700150}
151
alshabibf751d342016-06-17 14:20:30 -0700152task publish {
alshabib28a35f92016-06-03 00:16:26 -0700153 dependsOn publishMavenRepoImage
alshabib676bef52016-06-02 12:18:32 -0700154}
155
alshabibe0b3e702016-08-29 14:43:01 -0700156task deploy (type: Exec) {
alshabibe5e26ca2016-06-17 10:12:54 -0700157 executable = "ansible-playbook"
Zack Williams04869e22017-02-01 13:42:18 -0700158 args = ["-i", config.headnode.ip + ',']
alshabib853a4032016-06-16 14:54:34 -0700159
Zack Williams04869e22017-02-01 13:42:18 -0700160 if ( config.headnode.ansible_user != null && config.headnode.ansible_user != "" ) {
161 args = args << "--user=$config.headnode.ansible_user"
alshabibe5e26ca2016-06-17 10:12:54 -0700162 }
163
164 def extraVars = []
Zack Williams04869e22017-02-01 13:42:18 -0700165 if (config.headnode) {
166 extraVars = extraVars.p(config.common.extraVars)
167 .p(config.headnode.ansible_ssh_pass, "ansible_ssh_pass")
168 .p(config.headnode.ansible_sudo_pass, "ansible_sudo_pass")
169 .p(config.headnode.ansible_ssh_port, "ansible_ssh_port")
alshabibe5e26ca2016-06-17 10:12:54 -0700170 }
171
172 if (config.otherServers) {
173 extraVars = extraVars.p(config.otherServers.location, "prov_location")
174 .p(config.otherServers.rolesPath, "prov_role_path")
175 .p(config.otherServers.role, "prov_role")
176 }
177
178 if (config.docker) {
179 extraVars = extraVars.p(config.docker.registry, "docker_registry")
180 .p(config.docker.imageVersion, "docker_image_version")
181 }
182
Zack Williams04869e22017-02-01 13:42:18 -0700183 def skipTags = [].p(config.common.skipTags)
alshabibe5e26ca2016-06-17 10:12:54 -0700184
185 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml"
alshabib853a4032016-06-16 14:54:34 -0700186}
187
188
alshabib9c7e0282016-06-03 13:50:29 -0700189// Depending on the version of the apps this will either make a release or publish a snapshot
190task release (type: Exec) {
191 workingDir './apps'
192 commandLine 'mvn', 'clean', 'deploy'
193}