erAgent.mill-jib-docker-worker_2.12.0.1.0.source-code.JibDockerWorkerImpl.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mill-jib-docker-worker_2.12 Show documentation
Show all versions of mill-jib-docker-worker_2.12 Show documentation
Dockerize java applications on Mill builds
The newest version!
package mill.jib.docker.worker
import java.nio.file.Path
import java.util.function.Consumer
import mill.jib.docker.api
import _root_.com.google.cloud.tools.jib.api.{Containerizer, DockerDaemonImage, JavaContainerBuilder, JibEvent, LogEvent, RegistryImage}
import scala.collection.JavaConverters._
class JibDockerWorkerImpl extends api.JibDockerWorkerApi {
def build(
image: api.Image,
tags: Seq[String],
baseImage: String,
mainClass: String,
deps: Seq[Path],
projectDeps: Seq[Path],
jvmFlags: Seq[String],
labels: Map[String, String]): Unit = {
val cont0 = image match {
case api.DockerDaemonImage(v) => Containerizer.to(DockerDaemonImage.named(v))
case api.RegistryImage(v, u, p) => Containerizer.to(RegistryImage.named(v).addCredential(u, p))
}
val cont1 = tags.foldLeft(cont0)((acc, t) => acc.withAdditionalTag(t))
val cont2 = cont1
.setApplicationLayersCache(Containerizer.DEFAULT_BASE_CACHE_DIRECTORY)
.addEventHandler(
classOf[LogEvent],
(t: LogEvent) => System.err.println(s"[${t.getLevel.name()}] ${t.getMessage}"))
JavaContainerBuilder
.from(baseImage)
.setMainClass(mainClass)
.addDependencies(deps.asJava)
.addProjectDependencies(projectDeps.asJava)
.addJvmFlags(jvmFlags.asJava)
.toContainerBuilder
.setLabels(labels.asJava)
.containerize(cont2)
}
}