/*
 * 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 {

    // 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') : 'localhost:5000'

    // The tag used to tag the docker images push to the target registry
    targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'

    // Component table
    comps = [
    ]

    // 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'

}

// ------------- PlaceHolders ----------------

task updateDocker (type: Exec) {
    commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
}

task prime {
    // TODO this is a place-holder.
    dependsOn updateDocker
    doFirst {
        println "Using deployment config: $deployConfig"
        File configFile = new File(deployConfig)
        def yaml = new Yaml()
        def config = yaml.load(configFile.newReader())
        println "Config: $config"
        println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
    }
}

// ---------------- Useful tasks ----------------

task fetchUpstreamImages {
    comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
}

task fetchGitSubmodules {
    comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } }
}

task fetch {
    dependsOn fetchUpstreamImages
    dependsOn fetchGitSubmodules
}

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))
tasks.addRule(new DockerTagRule(project))
tasks.addRule(new GitSubmoduleUpdateRule(project))

task deploy {
    // TODO this is a place-holder.
    doFirst {
        println "Using deployment config: $deployConfig"
        File configFile = new File(deployConfig)
        def yaml = new Yaml()
        def config = yaml.load(configFile.newReader())
        println "Config: $config"
        println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
    }
}

