blob: 6b8afde8d602a5ecda149e4159f7727b50f3afe9 [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.
alshabib0bf710f2017-02-14 11:26:38 -080042 deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : '../build/config/default.yml'
David K. Bainbridge3da136f2016-11-15 17:22:06 -080043
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
Zack Williams04869e22017-02-01 13:42:18 -070057 : config.headnode.ip
58 ? config.headnode.ip + ":5000"
David K. Bainbridge3da136f2016-11-15 17:22:06 -080059 : '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"
Zack Williams04869e22017-02-01 13:42:18 -0700140 args = ["-i", config.headnode.ip + ',']
alshabib853a4032016-06-16 14:54:34 -0700141
Zack Williams04869e22017-02-01 13:42:18 -0700142 if ( config.headnode.ansible_user != null && config.headnode.ansible_user != "" ) {
143 args = args << "--user=$config.headnode.ansible_user"
alshabibe5e26ca2016-06-17 10:12:54 -0700144 }
145
146 def extraVars = []
Zack Williams04869e22017-02-01 13:42:18 -0700147 if (config.headnode) {
148 extraVars = extraVars.p(config.common.extraVars)
149 .p(config.headnode.ansible_ssh_pass, "ansible_ssh_pass")
150 .p(config.headnode.ansible_sudo_pass, "ansible_sudo_pass")
151 .p(config.headnode.ansible_ssh_port, "ansible_ssh_port")
alshabibe5e26ca2016-06-17 10:12:54 -0700152 }
153
154 if (config.otherServers) {
155 extraVars = extraVars.p(config.otherServers.location, "prov_location")
156 .p(config.otherServers.rolesPath, "prov_role_path")
157 .p(config.otherServers.role, "prov_role")
158 }
159
160 if (config.docker) {
161 extraVars = extraVars.p(config.docker.registry, "docker_registry")
162 .p(config.docker.imageVersion, "docker_image_version")
163 }
164
Zack Williams04869e22017-02-01 13:42:18 -0700165 def skipTags = [].p(config.common.skipTags)
alshabibe5e26ca2016-06-17 10:12:54 -0700166
167 args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml"
alshabib853a4032016-06-16 14:54:34 -0700168}
169
170
alshabib9c7e0282016-06-03 13:50:29 -0700171// Depending on the version of the apps this will either make a release or publish a snapshot
172task release (type: Exec) {
173 workingDir './apps'
174 commandLine 'mvn', 'clean', 'deploy'
175}