Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [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 |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 19 | import org.yaml.snakeyaml.DumperOptions |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 20 | |
| 21 | allprojects { |
| 22 | apply plugin: 'base' |
| 23 | apply plugin: 'de.gesellix.docker' |
| 24 | //apply plugin: 'com.tmiyamon.config' |
| 25 | |
| 26 | docker { |
| 27 | // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock' |
| 28 | // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376' |
| 29 | // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default" |
| 30 | // authConfigPlain = [ |
| 31 | // "username" : "joe", |
| 32 | // "password" : "some-pw-as-needed", |
| 33 | // "email" : "joe@acme.com", |
| 34 | // "serveraddress" : "https://index.docker.io/v1/" |
| 35 | // ] |
| 36 | } |
| 37 | } |
| 38 | |
Andy Bavier | 829bc00 | 2017-01-11 14:59:48 -0500 | [diff] [blame] | 39 | def getCordAppVersion = { -> |
| 40 | def StdOut = new ByteArrayOutputStream() |
| 41 | exec { |
| 42 | commandLine "xpath", "-q", "-e", "project/version/text()", "../../onos-apps/apps/pom.xml" |
| 43 | standardOutput = StdOut |
| 44 | } |
| 45 | return StdOut.toString().trim() |
| 46 | } |
| 47 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 48 | ext { |
| 49 | |
| 50 | // Upstream registry to simplify filling out the comps table below |
| 51 | upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io' |
| 52 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 53 | // Deployment target config file (yaml format); this can be overwritten from the command line |
| 54 | // using the -PdeployConfig=<file-path> syntax. |
| 55 | deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml' |
| 56 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 57 | println "Using deployment config: $deployConfig" |
| 58 | File configFile = new File(deployConfig) |
| 59 | def yaml = new Yaml() |
| 60 | config = yaml.load(configFile.newReader()) |
| 61 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 62 | // Target registry to be used to publish docker images needed for deployment |
| 63 | targetReg = project.hasProperty('targetReg') |
| 64 | ? project.getProperty('targetReg') |
| 65 | : config.docker && config.docker.registry |
| 66 | ? config.docker.registry |
David K. Bainbridge | 94b2471 | 2016-11-15 15:09:42 -0800 | [diff] [blame] | 67 | : config.seedServer.ip |
| 68 | ? config.seedServer.ip + ":5000" |
| 69 | : 'localhost:5000' |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 70 | |
| 71 | // The tag used to tag the docker images push to the target registry |
| 72 | targetTag = project.hasProperty('targetTag') |
| 73 | ? project.getProperty('targetTag') |
| 74 | : config.docker && config.docker.imageVersion |
| 75 | ? config.docker.imageVersion |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 76 | : 'candidate' |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 77 | |
| 78 | println "targetReg = $targetReg, targetTag = $targetTag" |
| 79 | |
Andy Bavier | 829bc00 | 2017-01-11 14:59:48 -0500 | [diff] [blame] | 80 | |
| 81 | // Version of the CORD apps to load into ONOS |
| 82 | cordAppVersion = project.hasProperty('cordAppVersion') |
| 83 | ? project.getProperty('cordAppVersion') |
| 84 | : getCordAppVersion() |
| 85 | |
| 86 | println "CORD app version: $cordAppVersion" |
| 87 | |
David K. Bainbridge | ecfbd4d | 2016-11-14 13:18:39 -0800 | [diff] [blame] | 88 | // Component table |
| 89 | comps = [ |
| 90 | ] |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 93 | task copyAnsibleInventory(type: Copy) { |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 94 | from 'inventory/templates/single-prod' |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 95 | into 'inventory' |
| 96 | expand([ |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 97 | prod: config.seedServer.ip, |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 98 | ]) |
| 99 | } |
| 100 | |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 101 | task writeYamlConfig { |
| 102 | def outvar = config.seedServer |
| 103 | def outfilename = "genconfig/deployconf.yml" |
| 104 | |
| 105 | DumperOptions options = new DumperOptions() |
| 106 | |
| 107 | options.setExplicitStart(true); |
| 108 | options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK) |
| 109 | options.setPrettyFlow(true); |
| 110 | options.setIndent(2); |
| 111 | |
| 112 | def yaml = new Yaml(options) |
| 113 | Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8")) |
| 114 | |
| 115 | yaml.dump(outvar, outfile) |
| 116 | |
| 117 | outfile.close() |
| 118 | } |
| 119 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 120 | // ------------- PlaceHolders ---------------- |
| 121 | |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 122 | task prime { |
| 123 | // TODO this is a place-holder. |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | // ---------------- Useful tasks ---------------- |
| 127 | |
alshabib | fe09d77 | 2016-08-29 16:15:56 -0700 | [diff] [blame] | 128 | task fetch << { |
| 129 | logger.info 'Platform install has nothing to fetch' |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 130 | } |
| 131 | |
alshabib | fe09d77 | 2016-08-29 16:15:56 -0700 | [diff] [blame] | 132 | task buildImages << { |
| 133 | logger.info 'Platform install has nothing to build' |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | task publishImages { |
| 137 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } } |
| 138 | } |
| 139 | |
| 140 | task publish { |
| 141 | dependsOn publishImages |
| 142 | } |
| 143 | |
| 144 | tasks.addRule(new DockerFetchRule(project)) |
| 145 | tasks.addRule(new DockerPublishRule(project)) |
| 146 | tasks.addRule(new DockerTagRule(project)) |
| 147 | tasks.addRule(new GitSubmoduleUpdateRule(project)) |
| 148 | |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 149 | task prepPlatform(type: Exec) { |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 150 | dependsOn copyAnsibleInventory |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 151 | dependsOn writeYamlConfig |
Andy Bavier | adea0fd | 2016-07-06 05:26:26 -0400 | [diff] [blame] | 152 | |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 153 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 154 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-prep-platform.yml"] |
Andy Bavier | 6dbb1a3 | 2016-07-06 07:12:50 -0400 | [diff] [blame] | 155 | } |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 156 | |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 157 | task deployOpenStack (type: Exec) { |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 158 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 159 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-openstack.yml"] |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | task deployONOS (type: Exec) { |
| 163 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 164 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-onos.yml"] |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | task deployXOS (type: Exec) { |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 168 | |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 169 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 170 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-deploy-xos.yml"] |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | task setupAutomation (type: Exec) { |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 174 | |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 175 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 176 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-automation.yml"] |
Andy Bavier | 12262e7 | 2016-12-02 11:36:57 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | deployOpenStack.mustRunAfter prepPlatform |
| 180 | deployONOS.mustRunAfter deployOpenStack |
| 181 | deployXOS.mustRunAfter deployONOS |
| 182 | setupAutomation.mustRunAfter deployXOS |
| 183 | |
| 184 | task deployPlatform { |
| 185 | dependsOn prepPlatform |
| 186 | dependsOn deployOpenStack |
| 187 | dependsOn deployONOS |
| 188 | dependsOn deployXOS |
| 189 | dependsOn setupAutomation |
Andy Bavier | 1b8a537 | 2016-07-07 19:36:21 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 192 | task postDeployTests (type: Exec) { |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 193 | |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 194 | executable = "ansible-playbook" |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 195 | args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-post-deploy-playbook.yml"] |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 196 | } |
Zack Williams | 5860f30 | 2017-01-20 16:17:16 -0700 | [diff] [blame] | 197 | |