All Downloads are FREE. Search and download functionalities are using the official Maven repository.

erAgent.mill-jib-docker-worker_2.12.0.1.0.source-code.JibDockerWorkerImpl.scala Maven / Gradle / Ivy

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)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy