blob: 8fd06d52df24f8538679e96818b87e50e8781085 [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
alshabib28a35f92016-06-03 00:16:26 -070040 // Upstream registry to simplify filling out the comps table below
41 upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
42
alshabib676bef52016-06-02 12:18:32 -070043 // 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
alshabibd4b75bf2016-06-16 22:58:00 -070049 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
alshabib676bef52016-06-02 12:18:32 -070050}
51
alshabib676bef52016-06-02 12:18:32 -070052
alshabib28a35f92016-06-03 00:16:26 -070053task buildOnosApps (type: Exec) {
54 workingDir './apps'
Charles Chancafaca52016-06-23 16:40:41 -070055 commandLine 'mvn', 'clean', 'install', '-U'
alshabib28a35f92016-06-03 00:16:26 -070056}
57
58task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
59 workingDir './'
David K. Bainbridge64030c42016-07-29 00:01:15 -070060 commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', '.'
alshabib28a35f92016-06-03 00:16:26 -070061}
62
63task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
alshabib853a4032016-06-16 14:54:34 -070064 commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
alshabib28a35f92016-06-03 00:16:26 -070065}
66
67task tagMavenRepoImage (type: Exec) {
alshabib853a4032016-06-16 14:54:34 -070068 commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
alshabib28a35f92016-06-03 00:16:26 -070069}
70
71task publishMavenRepoImage (type: Exec) {
72 dependsOn tagMavenRepoImage
73 commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
74}
75
alshabib853a4032016-06-16 14:54:34 -070076List.metaClass.asParam = { prefix, sep ->
77 if (delegate.size() == 0) {
78 ""
79 }
80 String result = "--" + prefix + "="
81 String p = ""
82 delegate.each {
83 result += p + "${it}"
84 p = sep
85 }
86 result
87}
88
89List.metaClass.p = { value, name ->
90 if (value != null && value != "") {
91 delegate << name + "=" + value
92 } else {
93 delegate
94 }
95}
96
97List.metaClass.p = { spec ->
98 if (spec != null && spec != "") {
99 delegate += spec
100 } else {
101 delegate
102 }
103}
104
alshabib28a35f92016-06-03 00:16:26 -0700105// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
106
alshabib676bef52016-06-02 12:18:32 -0700107task fetch {
alshabibe0b3e702016-08-29 14:43:01 -0700108 logger.info 'Nothing to fetch for me'
alshabib676bef52016-06-02 12:18:32 -0700109}
110
alshabibe0b3e702016-08-29 14:43:01 -0700111task buildImages {
alshabib28a35f92016-06-03 00:16:26 -0700112 dependsOn buildOnosApps
113 dependsOn copyLocalRepo
114 dependsOn buildRepoImage
alshabib676bef52016-06-02 12:18:32 -0700115}
116
alshabibf751d342016-06-17 14:20:30 -0700117task publish {
alshabib28a35f92016-06-03 00:16:26 -0700118 dependsOn publishMavenRepoImage
alshabib676bef52016-06-02 12:18:32 -0700119}
120
alshabibe0b3e702016-08-29 14:43:01 -0700121task deploy (type: Exec) {
alshabibe5e26ca2016-06-17 10:12:54 -0700122 println "Using deployment config: $deployConfig"
123 File configFile = new File(deployConfig)
124 def yaml = new Yaml()
125 def config = yaml.load(configFile.newReader())
alshabib853a4032016-06-16 14:54:34 -0700126
alshabibe5e26ca2016-06-17 10:12:54 -0700127 executable = "ansible-playbook"
128 args = ["-i", config.seedServer.ip + ',']
alshabib853a4032016-06-16 14:54:34 -0700129
alshabibe5e26ca2016-06-17 10:12:54 -0700130 if ( config.seedServer.user != null && config.seedServer.user != "" ) {
131 args = args << "--user=$config.seedServer.user"
132 }
133
134 def extraVars = []
135 if (config.seedServer) {
136 extraVars = extraVars.p(config.seedServer.extraVars)
137 .p(config.seedServer.password, "ansible_ssh_pass")
138 .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
139 .p(config.seedServer.domain, "domain")
David K. Bainbridge06fbe142016-07-06 16:00:07 -0700140 .p(config.seedServer.port, "ansible_ssh_port")
alshabibe5e26ca2016-06-17 10:12:54 -0700141 }
142
143 if (config.otherServers) {
144 extraVars = extraVars.p(config.otherServers.location, "prov_location")
145 .p(config.otherServers.rolesPath, "prov_role_path")
146 .p(config.otherServers.role, "prov_role")
147 }
148
149 if (config.docker) {
150 extraVars = extraVars.p(config.docker.registry, "docker_registry")
151 .p(config.docker.imageVersion, "docker_image_version")
152 }
153
154 def skipTags = [].p(config.seedServer.skipTags)
155
156 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml"
alshabib853a4032016-06-16 14:54:34 -0700157}
158
159
alshabib9c7e0282016-06-03 13:50:29 -0700160// Depending on the version of the apps this will either make a release or publish a snapshot
161task release (type: Exec) {
162 workingDir './apps'
163 commandLine 'mvn', 'clean', 'deploy'
164}