plugins {
  id 'java'
  id 'com.google.cloud.tools.jib'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
  mavenCentral()
}

dependencies {
  implementation files('libs/dependency-1.0.0.jar')
}


jib {
  from {
    def dockerHost = System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost"
    image = dockerHost + ':5000/distroless/java'
    auth {
      username = 'testuser'
      password = 'testpassword'
    }
  }
  to {
    image = System.getProperty("_TARGET_IMAGE")
    auth {
      username = System.getProperty("_TARGET_USERNAME")
      password = System.getProperty("_TARGET_PASSWORD")
    }
  }
  container {
    creationTime = 'USE_CURRENT_TIMESTAMP'
    args = ['An argument.']
    mainClass = 'com.test.HelloWorld'
    jvmFlags = ['-Xms512m', '-Xdebug']
    environment = [env1:'envvalue1', env2:'envvalue2']
    ports = ['1000/tcp', '2000-2003/udp']
    labels = [key1:'value1', key2:'value2']
    volumes = ['/var/log', '/var/log2']
  }
  extraDirectories {
    paths = file('src/main/custom-extra-dir')
    permissions = ['/foo':'755', '/bar/cat':'777']
  }
  outputPaths {
    digest = file("$buildDir/different-jib-image.digest")
    imageId = file("different-jib-image.id")
  }
  allowInsecureRegistries = true
}
