/*
 * This file was generated by the Gradle 'init' task.
 *
 * This project uses @Incubating APIs which are subject to change.
 */

plugins {
    id 'org.jdrupes.vmoperator.java-application-conventions'
}

dependencies {
    implementation 'org.jgrapes:org.jgrapes.core:[1.19.0,2)'
    implementation 'org.jgrapes:org.jgrapes.io:[2.7.0,3)'
    implementation 'org.jgrapes:org.jgrapes.http:[3.1.0,4)'
    implementation 'org.jgrapes:org.jgrapes.util:[1.29.0,2)'
    implementation project(':org.jdrupes.vmoperator.util')
    
    implementation 'commons-cli:commons-cli:1.5.0'
    implementation 'org.freemarker:freemarker:[2.3.32,2.4)'
    implementation 'io.kubernetes:client-java:[18.0.0,19)'
    
    runtimeOnly 'com.electronwill.night-config:yaml:3.6.6'    
    runtimeOnly 'org.slf4j:slf4j-jdk14:[2.0.7,3)'
}

application {
    applicationName = 'vm-manager'
    applicationDefaultJvmArgs = ['-Xms50m',
        '-Djava.util.logging.manager=org.jdrupes.vmoperator.util.LongLoggingManager'
        ]
    // Define the main class for the application.
    mainClass = 'org.jdrupes.vmoperator.manager.Manager'
}

task buildImage(type: Exec) {
    dependsOn installDist
    inputs.files 'src/org/jdrupes/vmoperator/manager/Containerfile'
    
    commandLine 'podman', 'build', '-t', "${project.name}:${project.version}",\
        '-f', 'src/org/jdrupes/vmoperator/manager/Containerfile', '.'
}

task tagLatestImage(type: Exec) {
    dependsOn buildImage
    
    commandLine 'podman', 'tag', "${project.name}:${project.version}",\
        "${project.name}:latest"
}

task buildLatestImage {
    dependsOn buildImage
    dependsOn tagLatestImage
}

task pushImage(type: Exec) {
    dependsOn buildImage

    commandLine 'podman', 'push', '--tls-verify=false', \
        "localhost/${project.name}:${project.version}", \
        "${project.rootProject.properties['docker.registry']}" \
            + "/${project.name}:${project.version}"
}

task pushLatestImage(type: Exec) {
    dependsOn buildLatestImage

    commandLine 'podman', 'push', '--tls-verify=false', \
        "localhost/${project.name}:${project.version}", \
        "${project.rootProject.properties['docker.registry']}" \
            + "/${project.name}:latest"
}

task pushImages {
    dependsOn pushImage
    dependsOn pushLatestImage
}

