blob: f4979baab49b64dc90aaf2397c5d7a430c65737a [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
* 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.
*/
/*
* 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
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.seedServer.ip
? config.seedServer.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'
cordTesterPath = project.hasProperty('cordTesterPath') ? project.getProperty('cordTesterPath') : './src/test/setup'
dockerPath = project.hasProperty('dockerPath') ? project.getProperty('dockerPath') : '/usr/bin'
cordTesterImages = [ 'cordtest/radius:candidate' : 'Dockerfile.radius', 'cordtest/quagga:candidate' : 'Dockerfile.quagga', 'cordtest/nose:candidate' : 'Dockerfile.tester' ]
}
List.metaClass.asParam = { prefix, sep ->
if (delegate.size() == 0) {
""
}
String result = "--" + prefix + "="
String p = ""
delegate.each {
result += p + "${it}"
p = sep
}
result
}
List.metaClass.p = { value, name ->
if (value != null && value != "") {
delegate << name + "=" + value
} else {
delegate
}
}
List.metaClass.p = { spec ->
if (spec != null && spec != "") {
delegate += spec
} else {
delegate
}
}
// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
// To be used to fetch upstream binaries, clone repos, etc.
task fetch {
//commandLine "$cordTesterPath/onos_pull.sh", 'latest'
}
// To be used to generate all needed binaries that need to be present on the target
// as docker images in the local docker runner.
task buildImages {
// ...
cordTesterImages.each { tag, dockerfile ->
println "Building Docker image ${tag} using ${dockerfile}"
exec {
executable "$dockerPath/docker"
args "build", "-t", "${tag}", "-f", "${dockerfile}", "."
}
}
}
task buildRadiusImage(type: Exec) {
commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/radius', '-f', 'Dockerfile.radius', '.'
}
task tagRadiusImage(type: Exec) {
dependsOn buildRadiusImage
commandLine "$dockerPath/docker", 'tag', 'cordtest/radius', "$targetReg/cordtest/radius:$targetTag"
}
task publishRadiusImage(type: Exec) {
dependsOn tagRadiusImage
commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/radius:$targetTag"
}
task buildQuaggaImage(type: Exec) {
commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/quagga', '-f', 'Dockerfile.quagga', '.'
}
task tagQuaggaImage(type: Exec) {
dependsOn buildQuaggaImage
commandLine "$dockerPath/docker", 'tag', 'cordtest/quagga', "$targetReg/cordtest/quagga:$targetTag"
}
task publishQuaggaImage(type: Exec) {
dependsOn tagQuaggaImage
commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/quagga:$targetTag"
}
task buildTesterImage(type: Exec) {
commandLine "$dockerPath/docker", 'build', '-t', 'cordtest/nose', '-f', 'Dockerfile.tester', '.'
}
task tagTesterImage(type: Exec) {
dependsOn buildTesterImage
commandLine "$dockerPath/docker", 'tag', 'cordtest/nose', "$targetReg/cordtest/nose:$targetTag"
}
task publishTesterImage(type: Exec) {
dependsOn tagTesterImage
commandLine "$dockerPath/docker", 'push', "$targetReg/cordtest/nose:$targetTag"
}
// Publish image(s) built during the build step into targetReg registry using the targetTag
// tag. See maas subproject for examples on how to do this.
task publishImages {
dependsOn publishTesterImage
dependsOn publishQuaggaImage
dependsOn publishRadiusImage
}
task publish {
dependsOn publishImages
}
task deployBase (type: Exec) {
executable = "ansible-playbook"
args = ["-i", config.seedServer.ip + ',']
if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
args = args << "--user=$config.seedServer.ansible_user"
}
if ( config.debug ) {
args = args << "-vvvv"
}
def extraVars = []
if (config.seedServer) {
extraVars = extraVars.p(config.seedServer.extraVars)
.p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
.p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
.p(config.seedServer.fabric_ip, "fabric_ip")
.p(config.seedServer.management_ip, "management_ip")
.p(config.seedServer.management_gw, "management_gw")
.p(config.seedServer.management_network, "management_network")
.p(config.seedServer.management_iface, "management_iface")
.p(config.seedServer.external_ip, "external_ip")
.p(config.seedServer.external_gw, "external_gw")
.p(config.seedServer.external_network, "external_network")
.p(config.seedServer.external_iface, "external_iface")
.p(config.seedServer.fabric_ip, "fabric_ip")
.p(config.seedServer.fabric_network, "fabric_network")
.p(config.seedServer.fabric_iface, "fabric_iface")
.p(config.seedServer.domain, "domain")
.p(config.seedServer.virtualbox_support, "virtualbox_support")
.p(config.seedServer.power_helper_user, "power_helper_user")
.p(config.seedServer.power_helper_host, "power_helper_host")
.p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
}
if (config.otherServers) {
extraVars = extraVars.p(config.otherServers.location, "prov_location")
.p(config.otherServers.rolesPath, "prov_role_path")
.p(config.otherServers.role, "prov_role")
}
if (config.docker) {
extraVars = extraVars.p(config.docker.registry, "docker_registry")
.p(config.docker.imageVersion, "docker_image_version")
}
def skipTags = [].p(config.seedServer.skipTags)
args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-deploy.yml"
}
task verify (type: Exec) {
executable = "ansible-playbook"
args = ["-i", config.seedServer.ip + ',']
if ( config.seedServer.ansible_user != null && config.seedServer.ansible_user != "" ) {
args = args << "--user=$config.seedServer.ansible_user"
}
if ( config.debug ) {
args = args << "-vvvv"
}
def extraVars = []
if (config.seedServer) {
extraVars = extraVars.p(config.seedServer.extraVars)
.p(config.seedServer.ansible_ssh_pass, "ansible_ssh_pass")
.p(config.seedServer.ansible_sudo_pass, "ansible_sudo_pass")
.p(config.seedServer.fabric_ip, "fabric_ip")
.p(config.seedServer.management_ip, "management_ip")
.p(config.seedServer.management_gw, "management_gw")
.p(config.seedServer.management_network, "management_network")
.p(config.seedServer.management_iface, "management_iface")
.p(config.seedServer.external_ip, "external_ip")
.p(config.seedServer.external_gw, "external_gw")
.p(config.seedServer.external_network, "external_network")
.p(config.seedServer.external_iface, "external_iface")
.p(config.seedServer.fabric_ip, "fabric_ip")
.p(config.seedServer.fabric_network, "fabric_network")
.p(config.seedServer.fabric_iface, "fabric_iface")
.p(config.seedServer.domain, "domain")
.p(config.seedServer.virtualbox_support, "virtualbox_support")
.p(config.seedServer.power_helper_user, "power_helper_user")
.p(config.seedServer.power_helper_host, "power_helper_host")
.p(config.seedServer.ansible_ssh_port, "ansible_ssh_port")
}
if (config.otherServers) {
extraVars = extraVars.p(config.otherServers.location, "prov_location")
.p(config.otherServers.rolesPath, "prov_role_path")
.p(config.otherServers.role, "prov_role")
}
if (config.docker) {
extraVars = extraVars.p(config.docker.registry, "docker_registry")
.p(config.docker.imageVersion, "docker_image_version")
}
def skipTags = [].p(config.seedServer.skipTags)
args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-tester-verify.yml"
}