apply plugin: "java"
apply plugin: "eclipse"
apply plugin: 'idea'
apply plugin: "org.springframework.boot" 
apply plugin: "com.bmuschko.docker-remote-api"

import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage

jar {
	baseName = "e-example-ms-demo"
}

springBoot  {
    mainClass = "com.loy.CloudDemoApplicationMain"
}

bootRepackage {
    mainClass = "com.loy.CloudDemoApplicationMain"
}

dependencies {
	 compile ("com.17jee:e-security-jwt:${eversion}")
	 compile ("com.17jee:e-cloud-authorize:${eversion}")
	 compile project(":demo:demo-service")
	 compile ("com.17jee:e-data-permission-impl:${eversion}")
	 compile ("com.17jee:e-cache-hibernate-ehcache:${eversion}")
	 runtime("mysql:mysql-connector-java:${mysqlVersion}")
	 runtime ("com.h2database:h2:1.4.193")
	 compile "io.springfox:springfox-swagger-ui:${springfoxSwaggerVersion}"
}
task erun(type:Exec, dependsOn: build) {
    workingDir "${project.buildDir}/libs"
    commandLine "java", "-Dfile.encoding=${fileEncoding}", "-jar","${project.name}-${version}.jar"
}

task copyJar(type: Copy) {
    dependsOn   "build"
    from        "build/libs/${jar.baseName}-${version}.jar"
    into        "build/docker"
    //rename { String fileName ->
    //    fileName.replace("-${version}", "-docker-${version}")
    //}
    
    from        "src/main/docker"
    into        "build/docker"
    
}
task buildDockerImage(type: DockerBuildImage) {
    dependsOn   copyJar
    if (System.env.DOCKER_HOST) {
        url = "$System.env.DOCKER_HOST".replace("tcp","https")
        if (System.env.DOCKER_CERT_PATH) {
            certPath = new File(System.env.DOCKER_CERT_PATH)
        }
    }
    else {
        url = 'unix:///var/run/docker.sock'
    }
    
    inputDir = file('build/docker')
    tag = 'com.loy/demo'
}