blob: 1cbe5a411a30391d63593fbac0b8139d3fb908a1 [file] [log] [blame]
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.opencord.gradle.rules.*
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.DumperOptions
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.2.1"
}
}
apply plugin: "com.dorongold.task-tree"
evaluationDependsOn(':maas')
evaluationDependsOn(':onos-apps')
evaluationDependsOn(':orchestration:xos')
evaluationDependsOn(':platform-install')
allprojects {
apply plugin: 'base'
apply plugin: 'de.gesellix.docker'
//apply plugin: 'com.tmiyamon.config'
docker {
// dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
// dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
// certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
// authConfigPlain = [
// "username" : "joe",
// "password" : "some-pw-as-needed",
// "email" : "joe@acme.com",
// "serveraddress" : "https://index.docker.io/v1/"
// ]
}
}
ext {
// Deployment target config file (yaml format); this can be overwritten from the command line
// using the -PdeployConfig=<file-path> syntax.
deployConfig = project.hasProperty('deployConfig') ? project.getProperty('deployConfig') : './config/default.yml'
println "Using deployment config: $deployConfig"
File configFile = new File(deployConfig)
def yaml = new Yaml()
config = yaml.load(configFile.newReader())
// Upstream registry to simplify filling out the comps table below
upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'
// Target registry to be used to publish docker images needed for deployment
targetReg = project.hasProperty('targetReg')
? project.getProperty('targetReg')
: config.docker && config.docker.registry
? config.docker.registry
: config.headnode.ip
? config.headnode.ip + ":5000"
: 'localhost:5000'
// The tag used to tag the docker images push to the target registry
targetTag = project.hasProperty('targetTag')
? project.getProperty('targetTag')
: config.docker && config.docker.imageVersion
? config.docker.imageVersion
: 'candidate'
// Component table
comps = [
// ONOS 1.8.7 from DockerHub
'onosproject/onos': [
'type': 'image',
'upstream': upstreamReg,
'name': 'onosproject/onos',
'digest': 'sha256:7e6e79e8cc41419901ee6f9022abaf2be52098795e70cab0e1964126dae56f87'
],
'nginx': [
'type': 'image',
'upstream': upstreamReg,
'name': 'nginx',
'digest': 'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
],
'swarm': [
'type': 'image',
'upstream': upstreamReg,
'name': 'swarm',
'digest': 'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
],
'xosproject/vsg': [
'type': 'image',
'upstream': upstreamReg,
'name': 'xosproject/vsg',
'digest': 'sha256:18d1c6ef9767d8a41c9b51948776052d024d4e3294e5d1d6dde1a49112175d91'
],
'redis': [
'type': 'image',
'upstream': upstreamReg,
'name': 'redis',
'digest': 'sha256:0fe5a7afa2c2154f37c8ab56a9a6c5023cb0405cc0e85b34d8dcc1de6c3f143e'
],
'node': [
'type': 'image',
'upstream': upstreamReg,
'name': 'node',
'digest': 'sha256:5757581a8ff7e08041512a54aa3f573d33fecdce81d603e48a759956cd99bdd3'
],
'gliderlabs/consul-server': [
'type': 'image',
'upstream': upstreamReg,
'name': 'gliderlabs/consul-server',
'digest': 'sha256:37e194c7c941e37cf20b0cc5080541cfde9d31bf62a874905d0d51b3945f88c9'
],
'gliderlabs/registrator': [
'type': 'image',
'upstream': upstreamReg,
'name': 'gliderlabs/registrator',
'digest': 'sha256:6e708681dd52e28f4f39d048ac75376c9a762c44b3d75b2824173f8364e52c10'
]
]
}
// ---------------- Useful tasks ----------------
task writeInventory(type: Copy) {
from 'ansible/cord-inv'
into 'genconfig'
expand([
headnode_ip: config.headnode.ip,
headnode_user: config.headnode.ansible_user,
headnode_pass: config.headnode.ansible_ssh_pass,
headnode_port: config.headnode.ansible_ssh_port,
])
}
task writeYamlConfig {
def outvar = config.common
def outfilename = "genconfig/config.yml"
DumperOptions options = new DumperOptions()
options.setExplicitStart(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
options.setPrettyFlow(true);
options.setIndent(2);
def yaml = new Yaml(options)
Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
yaml.dump(outvar, outfile)
outfile.close()
}
task fetchUpstreamImages {
comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
}
task fetch {
dependsOn fetchUpstreamImages
}
task buildImages {
logger.info "Root project has nothing to build"
}
task publishImages {
comps.each { name, spec -> if (spec.type == 'image') {
dependsOn "publish" + name
}
}
}
task publish {
dependsOn publishImages
}
tasks.addRule(new DockerFetchRule(project))
tasks.addRule(new DockerPublishRule(project, project(':maas').prime))
tasks.addRule(new DockerTagRule(project))
task PIcreateConfig(type: Exec) {
dependsOn writeYamlConfig
dependsOn writeInventory
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"--extra-vars", "deploy_docker_tag="+targetTag,
"--extra-vars", "deploy_docker_registry=docker-registry:5000/",
"cord-config-playbook.yml" ]
}
task PIcopyCord(type: Exec) {
dependsOn PIcreateConfig
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"copy-cord-playbook.yml" ]
}
task PIcopyProfile(type: Exec) {
dependsOn PIcreateConfig
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"copy-profile-playbook.yml" ]
}
task PIprepPlatform(type: Exec) {
dependsOn PIcreateConfig
dependsOn PIcopyCord
dependsOn PIcopyProfile
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"prep-platform-playbook.yml" ]
}
task PIdeployOpenStack (type: Exec) {
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"--extra-vars", "deploy_docker_tag="+targetTag,
"--extra-vars", "deploy_docker_registry=docker-registry:5000/",
"deploy-openstack-playbook.yml" ]
}
task PIdeployONOS (type: Exec) {
workingDir "platform-install"
executable = "ansible-playbook"
args = [ "-i", "../genconfig/cord-inv",
"--extra-vars", "@../genconfig/config.yml",
"--extra-vars", "deploy_docker_tag="+targetTag,
"--extra-vars", "deploy_docker_registry=docker-registry:5000/",
"deploy-onos-playbook.yml" ]
}
task PIdeployXOS (type: Exec) {
def extra_vars = "--extra-vars deploy_docker_tag="+targetTag+" --extra-vars deploy_docker_registry=docker-registry:5000/"
def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml "+extra_vars+" launch-xos-playbook.yml"
executable = "ssh"
args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
}
task PIsetupAutomation (type: Exec) {
def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-automation-playbook.yml"
executable = "ssh"
args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
}
task PIrunDiag (type: Exec) {
def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml collect-diag-playbook.yml"
executable = "ssh"
args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
}
task postDeployTests (type: Exec) {
def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml pod-test-playbook.yml"
executable = "ssh"
args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
}
project(':maas').prime.dependsOn writeYamlConfig
project(':maas').prime.dependsOn writeInventory
project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
project(':onos-apps').deploy.dependsOn project(':maas').deployBase
project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
project(':onos-apps').deploy.dependsOn project(':maas').deployBase
// Ensure nginx:candidate exists
project(':orchestration:xos').buildImages.dependsOn rootProject."tagnginx"
// make PI config tasks run before maas deploy
project(':maas').deployBase.dependsOn PIcopyProfile
// For corebuilder
project(':platform-install').buildImages.dependsOn project(':orchestration:xos').buildImages
task PIdeployPlatform {
dependsOn PIcopyCord
dependsOn project(':onos-apps').deploy
dependsOn project(':maas').deployBase
dependsOn PIprepPlatform
dependsOn PIdeployOpenStack
dependsOn PIdeployONOS
dependsOn PIdeployXOS
dependsOn PIsetupAutomation
}
PIprepPlatform.mustRunAfter PIcopyCord
PIdeployOpenStack.mustRunAfter PIprepPlatform
PIdeployONOS.mustRunAfter PIdeployOpenStack
PIdeployXOS.mustRunAfter PIdeployONOS
PIsetupAutomation.mustRunAfter PIdeployXOS
PIdeployPlatform.mustRunAfter project(':onos-apps').deploy
PIdeployPlatform.mustRunAfter project(':maas').deployBase
task deploy {
dependsOn PIdeployPlatform
}