/*
 * 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 = [
            'maas': [
                    'type':         'gitmodule',
                    'upstream':     '../maas',
                    'branch':       'master',
                    'tag':          null,
                    'componentDir': './components/maas'
            ],
            'cord-tester': [
                    'type':         'gitmodule',
                    'upstream':     '../cord-tester',
                    'branch':       'master',
                    'tag':          null,
                    'componentDir': './components/cord-tester'
            ],
            'cord-onos-publisher': [
                    'type':         'gitmodule',
                    'upstream':     '../cord-onos-publisher',
                    'branch':       'master',
                    'tag':          null,
                    'componentDir': './components/cord-onos-publisher'
            ],
            'nginx': [
                    'type':     'image',
                    'upstream': upstreamReg,
                    'name':     'nginx',
                    'digest':   'sha256:b555f8c64ab4e85405e0d8b03f759b73ce88deb802892a3b155ef55e3e832806'
            ],
            'swarm': [
                    'type':     'image',
                    'upstream': upstreamReg,
                    'name':     'swarm',
                    'digest':   'sha256:6ca9b40980e2fcdcd229900ec8933f3e92c14ead22c9404cb09736cb4f3a9248'
            ],
            'onos':  [
                    'type':     'image',
                    'upstream': upstreamReg,
                    'name':     'onosproject/onos',
                    'digest':   'sha256:0f65940cfc7759c0bf63c4e60d30c4ad31a2565fadfbb9d9160a27ef87edd8e2'
            ],
    ]

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

}

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}"
    }
}
