blob: 519db667342d8c769525d34d55b2430c7289873c [file] [log] [blame]
Andy Bavieradea0fd2016-07-06 05:26:26 -04001/*
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 // Component table
50 comps = [
51 ]
52
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
57}
58
59// ------------- PlaceHolders ----------------
60
61task updateDocker (type: Exec) {
62 commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
63}
64
65task prime {
66 // TODO this is a place-holder.
67 dependsOn updateDocker
68 doFirst {
69 println "Using deployment config: $deployConfig"
70 File configFile = new File(deployConfig)
71 def yaml = new Yaml()
72 def config = yaml.load(configFile.newReader())
73 println "Config: $config"
74 println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
75 }
76}
77
78// ---------------- Useful tasks ----------------
79
80task fetchUpstreamImages {
81 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
82}
83
84task fetchGitSubmodules {
85 comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } }
86}
87
88task fetch {
89 dependsOn fetchUpstreamImages
90 dependsOn fetchGitSubmodules
91}
92
93task publishImages {
94 comps.each { name, spec -> if (spec.type == 'image') { dependsOn "publish" + name } }
95}
96
97task publish {
98 dependsOn publishImages
99}
100
101tasks.addRule(new DockerFetchRule(project))
102tasks.addRule(new DockerPublishRule(project))
103tasks.addRule(new DockerTagRule(project))
104tasks.addRule(new GitSubmoduleUpdateRule(project))
105
106task deploy {
107 // TODO this is a place-holder.
108 doFirst {
109 println "Using deployment config: $deployConfig"
110 File configFile = new File(deployConfig)
111 def yaml = new Yaml()
112 def config = yaml.load(configFile.newReader())
113 println "Config: $config"
114 println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
115 }
116}
117