blob: 8fd06d52df24f8538679e96818b87e50e8781085 [file] [log] [blame]
alshabibc375bf42016-08-25 15:47:07 -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 // 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 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
50}
51
52
53task buildOnosApps (type: Exec) {
54 workingDir './apps'
55 commandLine 'mvn', 'clean', 'install', '-U'
56}
57
58task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
59 workingDir './'
60 commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', '.'
61}
62
63task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
64 commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
65}
66
67task tagMavenRepoImage (type: Exec) {
68 commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
69}
70
71task publishMavenRepoImage (type: Exec) {
72 dependsOn tagMavenRepoImage
73 commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
74}
75
76List.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
105// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
106
107task fetch {
108 logger.info 'Nothing to fetch for me'
109}
110
111task buildImages {
112 dependsOn buildOnosApps
113 dependsOn copyLocalRepo
114 dependsOn buildRepoImage
115}
116
117task publish {
118 dependsOn publishMavenRepoImage
119}
120
121task deploy (type: Exec) {
122 println "Using deployment config: $deployConfig"
123 File configFile = new File(deployConfig)
124 def yaml = new Yaml()
125 def config = yaml.load(configFile.newReader())
126
127 executable = "ansible-playbook"
128 args = ["-i", config.seedServer.ip + ',']
129
130 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")
140 .p(config.seedServer.port, "ansible_ssh_port")
141 }
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"
157}
158
159
160// 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}