构建容器镜像
build.gradle.ktsplugins {
application
id("com.google.cloud.tools.jib") version "3.4.5"
}
jib{
from {
// 打包后210MiB;默认 eclipse-temurin:21-jre;jlink 容器大小优化 - blog.csdn.net/zypqqgc/article/details/142070527
image = "eclipse-temurin:24-jre-alpine"
}
to {
/*
tags = mutableSetOf(Instant.now().toString().replace(":", "_"))
image = "asia-east1-docker.pkg.dev/project-123456/temp-repo/new-tech"
auth {
username = "_json_key"
val txtFile=file("../../../../docs/cloud/project-123456-8ad030ce3d3e.json")
password = if (txtFile.exists()) txtFile.readText() else null
}
*/
tags = mutableSetOf("new-tech-"+Instant.now().toString().replace(":", "_"))
image = "dockerhubuser/private" // docker.io/dockerhubuser/private:new-tech-0.0.1b1
auth {
username = "dockerhubuser"
password = System.getenv("DOCKER_PASSWORD")?:"" // ALIYUN_DOCKER_PASSWORD
}
containerizingMode = "packaged" // jar包目标路径 /app/classpath/main-class.jar、/app/libs/jetty-server-12.0.16.jar
}
container {
jvmFlags = mutableListOf("-XX:MaxRAMPercentage=95","-XX:+UseZGC","-XX:+CrashOnOutOfMemoryError")
mainClass = application.mainClass.get() // 多个主类时才需指定
}
}