alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | import org.opencord.gradle.rules.* |
| 18 | import org.yaml.snakeyaml.Yaml |
| 19 | |
| 20 | allprojects { |
| 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 | |
| 38 | ext { |
| 39 | |
| 40 | appVersion = null |
| 41 | |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 42 | // Upstream registry to simplify filling out the comps table below |
| 43 | upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io' |
| 44 | |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 45 | // Target registry to be used to publish docker images needed for deployment |
| 46 | targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000' |
| 47 | |
| 48 | // The tag used to tag the docker images push to the target registry |
| 49 | targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate' |
| 50 | |
| 51 | comps = [ |
| 52 | 'aaa' : [ |
| 53 | 'type': 'gitmodule', |
| 54 | 'upstream': 'https://gerrit.opencord.org/aaa', |
| 55 | 'branch' : 'master', |
| 56 | 'tag' : appVersion, |
| 57 | 'componentDir': './apps/aaa' |
| 58 | ], |
| 59 | 'vtn' : [ |
| 60 | 'type': 'gitmodule', |
| 61 | 'upstream': 'https://gerrit.opencord.org/vtn', |
| 62 | 'branch' : 'master', |
| 63 | 'tag' : appVersion, |
| 64 | 'componentDir': './apps/vtn' |
| 65 | ], |
| 66 | 'mcast' : [ |
| 67 | 'type': 'gitmodule', |
| 68 | 'upstream': 'https://gerrit.opencord.org/mcast', |
| 69 | 'branch' : 'master', |
| 70 | 'tag' : appVersion, |
| 71 | 'componentDir': './apps/mcast' |
| 72 | ], |
| 73 | 'igmp' : [ |
| 74 | 'type': 'gitmodule', |
| 75 | 'upstream': 'https://gerrit.opencord.org/igmp', |
| 76 | 'branch' : 'master', |
| 77 | 'tag' : appVersion, |
| 78 | 'componentDir': './apps/igmp' |
| 79 | ], |
| 80 | 'olt' : [ |
| 81 | 'type': 'gitmodule', |
| 82 | 'upstream': 'https://gerrit.opencord.org/olt', |
| 83 | 'branch' : 'master', |
| 84 | 'tag' : appVersion, |
| 85 | 'componentDir': './apps/olt' |
| 86 | ], |
| 87 | 'config' : [ |
| 88 | 'type': 'gitmodule', |
| 89 | 'upstream': 'https://gerrit.opencord.org/config', |
| 90 | 'branch' : 'master', |
| 91 | 'tag' : appVersion, |
| 92 | 'componentDir': './apps/config' |
| 93 | ] |
| 94 | ] |
alshabib | d4b75bf | 2016-06-16 22:58:00 -0700 | [diff] [blame] | 95 | |
| 96 | deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml' |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 97 | } |
| 98 | |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 99 | |
| 100 | task fetchGitSubmodules { |
| 101 | comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } } |
| 102 | } |
| 103 | |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 104 | task buildOnosApps (type: Exec) { |
| 105 | workingDir './apps' |
| 106 | commandLine 'mvn', 'clean', 'install' |
| 107 | } |
| 108 | |
| 109 | task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) { |
| 110 | workingDir './' |
| 111 | commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', 'repository' |
| 112 | } |
| 113 | |
| 114 | task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) { |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 115 | commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.' |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | task tagMavenRepoImage (type: Exec) { |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 119 | commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag" |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | task publishMavenRepoImage (type: Exec) { |
| 123 | dependsOn tagMavenRepoImage |
| 124 | commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag" |
| 125 | } |
| 126 | |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 127 | List.metaClass.asParam = { prefix, sep -> |
| 128 | if (delegate.size() == 0) { |
| 129 | "" |
| 130 | } |
| 131 | String result = "--" + prefix + "=" |
| 132 | String p = "" |
| 133 | delegate.each { |
| 134 | result += p + "${it}" |
| 135 | p = sep |
| 136 | } |
| 137 | result |
| 138 | } |
| 139 | |
| 140 | List.metaClass.p = { value, name -> |
| 141 | if (value != null && value != "") { |
| 142 | delegate << name + "=" + value |
| 143 | } else { |
| 144 | delegate |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | List.metaClass.p = { spec -> |
| 149 | if (spec != null && spec != "") { |
| 150 | delegate += spec |
| 151 | } else { |
| 152 | delegate |
| 153 | } |
| 154 | } |
| 155 | |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 156 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 157 | |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 158 | task fetch { |
| 159 | dependsOn fetchGitSubmodules |
| 160 | } |
| 161 | |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 162 | task buildImages (dependsOn: fetch) { |
| 163 | dependsOn buildOnosApps |
| 164 | dependsOn copyLocalRepo |
| 165 | dependsOn buildRepoImage |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 166 | } |
| 167 | |
alshabib | f751d34 | 2016-06-17 14:20:30 -0700 | [diff] [blame] | 168 | task publish { |
| 169 | dependsOn buildImages |
alshabib | 28a35f9 | 2016-06-03 00:16:26 -0700 | [diff] [blame] | 170 | dependsOn publishMavenRepoImage |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 171 | } |
| 172 | |
alshabib | 4847159 | 2016-06-17 14:04:38 -0700 | [diff] [blame] | 173 | task deploy (type: Exec) { |
alshabib | e5e26ca | 2016-06-17 10:12:54 -0700 | [diff] [blame] | 174 | println "Using deployment config: $deployConfig" |
| 175 | File configFile = new File(deployConfig) |
| 176 | def yaml = new Yaml() |
| 177 | def config = yaml.load(configFile.newReader()) |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 178 | |
alshabib | e5e26ca | 2016-06-17 10:12:54 -0700 | [diff] [blame] | 179 | executable = "ansible-playbook" |
| 180 | args = ["-i", config.seedServer.ip + ','] |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 181 | |
alshabib | e5e26ca | 2016-06-17 10:12:54 -0700 | [diff] [blame] | 182 | if ( config.seedServer.user != null && config.seedServer.user != "" ) { |
| 183 | args = args << "--user=$config.seedServer.user" |
| 184 | } |
| 185 | |
| 186 | def extraVars = [] |
| 187 | if (config.seedServer) { |
| 188 | extraVars = extraVars.p(config.seedServer.extraVars) |
| 189 | .p(config.seedServer.password, "ansible_ssh_pass") |
| 190 | .p(config.seedServer.sudoPassword, "ansible_sudo_pass") |
| 191 | .p(config.seedServer.domain, "domain") |
| 192 | } |
| 193 | |
| 194 | if (config.otherServers) { |
| 195 | extraVars = extraVars.p(config.otherServers.location, "prov_location") |
| 196 | .p(config.otherServers.rolesPath, "prov_role_path") |
| 197 | .p(config.otherServers.role, "prov_role") |
| 198 | } |
| 199 | |
| 200 | if (config.docker) { |
| 201 | extraVars = extraVars.p(config.docker.registry, "docker_registry") |
| 202 | .p(config.docker.imageVersion, "docker_image_version") |
| 203 | } |
| 204 | |
| 205 | def skipTags = [].p(config.seedServer.skipTags) |
| 206 | |
| 207 | args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml" |
alshabib | 853a403 | 2016-06-16 14:54:34 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
alshabib | 9c7e028 | 2016-06-03 13:50:29 -0700 | [diff] [blame] | 211 | // Depending on the version of the apps this will either make a release or publish a snapshot |
| 212 | task release (type: Exec) { |
| 213 | workingDir './apps' |
| 214 | commandLine 'mvn', 'clean', 'deploy' |
| 215 | } |
| 216 | |
alshabib | 676bef5 | 2016-06-02 12:18:32 -0700 | [diff] [blame] | 217 | tasks.addRule(new GitSubmoduleUpdateRule(project)) |