Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -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 | |
Zsolt Haraszti | 0b790aa | 2016-05-12 22:33:14 -0700 | [diff] [blame] | 17 | import org.opencord.gradle.rules.* |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 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 | // Upstream registry to simplify filling out the comps table below |
Zsolt Haraszti | a9f7250 | 2016-05-12 16:07:03 -0700 | [diff] [blame] | 41 | upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io' |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 42 | |
| 43 | // Target registry to be used to publish docker images needed for deployment |
Zsolt Haraszti | a9f7250 | 2016-05-12 16:07:03 -0700 | [diff] [blame] | 44 | targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000' |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 45 | |
| 46 | // The tag used to tag the docker images push to the target registry |
Zsolt Haraszti | a9f7250 | 2016-05-12 16:07:03 -0700 | [diff] [blame] | 47 | targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate' |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 48 | |
| 49 | // Component table |
| 50 | comps = [ |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 51 | 'maas': [ |
| 52 | 'type': 'gitmodule', |
| 53 | 'upstream': '../maas', |
| 54 | 'branch': 'master', |
| 55 | 'tag': null, |
| 56 | 'componentDir': './components/maas' |
| 57 | ], |
Zsolt Haraszti | fac9f19 | 2016-06-02 18:20:06 -0700 | [diff] [blame] | 58 | 'cord-tester': [ |
| 59 | 'type': 'gitmodule', |
| 60 | 'upstream': '../cord-tester', |
| 61 | 'branch': 'master', |
| 62 | 'tag': null, |
| 63 | 'componentDir': './components/cord-tester' |
| 64 | ], |
Zsolt Haraszti | 7fdeaf0 | 2016-06-03 09:12:28 -0700 | [diff] [blame] | 65 | 'cord-onos-publisher': [ |
| 66 | 'type': 'gitmodule', |
| 67 | 'upstream': '../cord-onos-publisher', |
| 68 | 'branch': 'master', |
| 69 | 'tag': null, |
| 70 | 'componentDir': './components/cord-onos-publisher' |
| 71 | ], |
Andy Bavier | fe2b407 | 2016-07-06 19:13:55 -0400 | [diff] [blame] | 72 | 'platform-install': [ |
| 73 | 'type': 'gitmodule', |
| 74 | 'upstream': '../platform-install', |
| 75 | 'branch': 'master', |
| 76 | 'tag': null, |
| 77 | 'componentDir': './components/platform-install' |
| 78 | ], |
David K. Bainbridge | d54ca70 | 2016-07-13 22:27:12 -0700 | [diff] [blame] | 79 | 'onosproject/onos': [ |
| 80 | 'type': 'image', |
| 81 | 'upstream': upstreamReg, |
| 82 | 'name': 'onosproject/onos', |
| 83 | 'digest': 'sha256:6c310b6bc798f745977973c8c883d3dd1eb250fd124ae4d627fd98a69efb5afc' |
| 84 | ], |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 85 | 'nginx': [ |
| 86 | 'type': 'image', |
| 87 | 'upstream': upstreamReg, |
| 88 | 'name': 'nginx', |
| 89 | 'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806' |
| 90 | ], |
| 91 | 'swarm': [ |
| 92 | 'type': 'image', |
| 93 | 'upstream': upstreamReg, |
| 94 | 'name': 'swarm', |
| 95 | 'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248' |
| 96 | ], |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 97 | ] |
| 98 | |
| 99 | // Deployment target config file (yaml format); this can be overwritten from the command line |
| 100 | // using the -PdeployConfig=<file-path> syntax. |
Zsolt Haraszti | a9f7250 | 2016-05-12 16:07:03 -0700 | [diff] [blame] | 101 | deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml' |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 102 | |
| 103 | } |
| 104 | |
alshabib | 00c4b5d | 2016-06-17 17:26:10 -0700 | [diff] [blame] | 105 | // ------------- PlaceHolders ---------------- |
| 106 | |
| 107 | task updateDocker (type: Exec) { |
| 108 | commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg" |
| 109 | } |
| 110 | |
| 111 | task prime { |
| 112 | // TODO this is a place-holder. |
| 113 | dependsOn updateDocker |
| 114 | doFirst { |
| 115 | println "Using deployment config: $deployConfig" |
| 116 | File configFile = new File(deployConfig) |
| 117 | def yaml = new Yaml() |
| 118 | def config = yaml.load(configFile.newReader()) |
| 119 | println "Config: $config" |
| 120 | println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}" |
| 121 | } |
| 122 | } |
| 123 | |
alshabib | 00c4b5d | 2016-06-17 17:26:10 -0700 | [diff] [blame] | 124 | // ---------------- Useful tasks ---------------- |
| 125 | |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 126 | task fetchUpstreamImages { |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 127 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } } |
| 128 | } |
| 129 | |
| 130 | task fetchGitSubmodules { |
| 131 | comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } } |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | task fetch { |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 135 | dependsOn fetchUpstreamImages |
| 136 | dependsOn fetchGitSubmodules |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | task publishImages { |
Zsolt Haraszti | a9f7250 | 2016-05-12 16:07:03 -0700 | [diff] [blame] | 140 | comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } } |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | task publish { |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 144 | dependsOn publishImages |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | tasks.addRule(new DockerFetchRule(project)) |
| 148 | tasks.addRule(new DockerPublishRule(project)) |
| 149 | tasks.addRule(new DockerTagRule(project)) |
Zsolt Haraszti | 3dbe616 | 2016-05-12 12:25:56 -0700 | [diff] [blame] | 150 | tasks.addRule(new GitSubmoduleUpdateRule(project)) |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 151 | |
Andy Bavier | beb89c0 | 2016-07-07 13:26:55 -0400 | [diff] [blame] | 152 | task deployBase { |
| 153 | // TODO this is a place-holder. |
| 154 | doFirst { |
| 155 | println "Using deployment config: $deployConfig" |
| 156 | File configFile = new File(deployConfig) |
| 157 | def yaml = new Yaml() |
| 158 | def config = yaml.load(configFile.newReader()) |
| 159 | println "Config: $config" |
| 160 | println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}" |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | task deployPlatform { |
Zsolt Haraszti | ec7df10 | 2016-05-05 13:34:18 -0700 | [diff] [blame] | 165 | // TODO this is a place-holder. |
| 166 | doFirst { |
| 167 | println "Using deployment config: $deployConfig" |
| 168 | File configFile = new File(deployConfig) |
| 169 | def yaml = new Yaml() |
| 170 | def config = yaml.load(configFile.newReader()) |
| 171 | println "Config: $config" |
| 172 | println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}" |
| 173 | } |
| 174 | } |
alshabib | b58aeab | 2016-06-17 16:47:02 -0700 | [diff] [blame] | 175 | |