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

erAgent.mill-jib-docker_2.12.0.1.0.source-code.JibDockerModule.scala Maven / Gradle / Ivy

The newest version!
package mill.jib.docker

import mill._
import mill.api.Logger
import mill.scalalib._
import mill.define.Task
import mill.jib.docker.api.{DockerDaemonImage, RegistryImage}
import mill.scalalib.{JavaModule, Lib}

trait JibDockerModule { outer: JavaModule =>
  trait DockerConfig extends mill.Module {
    /**
     * Tags that should be applied to the built image
     * In the standard registry/repository:tag format
     */
    def image: T[String] = T(outer.artifactName())

    def additionalTags: T[Seq[String]] = T(Seq.empty[String])

    def labels: T[Map[String, String]] = T(Map.empty[String, String])

    def baseImage: T[String] = "gcr.io/distroless/java:latest"

    def jvmFlags: T[Seq[String]] = T(Seq.empty[String])

    def ivyJars = T {
      resolveDeps(T.task{runIvyDeps() ++ transitiveIvyDeps()})()
    }

    private def artifactIdAndJarOf(m: JavaModule) = T.task {
      m.artifactId() -> m.jar()
    }

    def projectJars = T {
      Task.sequence(transitiveModuleDeps.map(m => artifactIdAndJarOf(m)))
    }

    def registryUsername: T[String] = ""
    def registryPassword: T[String] = ""

    def jibVersion: T[String] = "0.10.1"
    def jibClasspath: T[mill.api.Loose.Agg[PathRef]] = T {
      Lib.resolveDependencies(
        Seq(
          coursier.LocalRepositories.ivy2Local,
          coursier.MavenRepository("https://repo1.maven.org/maven2")
        ),
        Lib.depToDependencyJava(_),
        Seq(ivy"com.google.cloud.tools:jib-core:${jibVersion()}")
      )
    }

    def jibDockerWorkerClasspath = T {
      Lib.resolveDependencies(
        Seq(
          coursier.LocalRepositories.ivy2Local,
          coursier.MavenRepository("https://repo1.maven.org/maven2")
        ),
        Lib.depToDependency(_, "2.12.9"),
        Seq(ivy"io.github.CyberAgent::mill-jib-docker-worker:0.1.0")
      )
//      val workerKey = "MILL_SCOVERAGE_REPORT_WORKER_" + jibVersion().replace(".", "_")
//      mill.modules.Util.millProjectModule(
//        workerKey,
//        s"mill-jib-docker-worker",
//        repositories,
//        resolveFilter = _.toString.contains("mill-jib-docker-worker")
//      )
    }

    private def renamedProjectJars = T {
      val dest = T.ctx().dest
      projectJars().map { case (artifactId, jar) =>
        val d = dest / s"${artifactId}.jar"
        os.copy(jar.path, d)
        PathRef(d)
      }
    }

    private def toolsClasspath = T {
      jibDockerWorkerClasspath() ++ jibClasspath()
    }

    def buildLocal() = T.command {
      val l: Logger = T.ctx().log
      JibDockerWorkerApi
        .jibDockerWorker()
        .bridge(toolsClasspath().map(_.path))
        .build(
          DockerDaemonImage(image()),
          additionalTags(),
          baseImage(),
          outer.finalMainClass(),
          ivyJars().map(_.path.toNIO).toSeq,
          renamedProjectJars().map(_.path.toNIO).toSeq,
          jvmFlags(),
          labels())
    }

    def buildAndPush() = T.command {
      JibDockerWorkerApi
        .jibDockerWorker()
        .bridge(toolsClasspath().map(_.path))
        .build(
          RegistryImage(image(), registryUsername(), registryPassword()),
          additionalTags(),
          baseImage(),
          outer.finalMainClass(),
          ivyJars().map(_.path.toNIO).toSeq,
          renamedProjectJars().map(_.path.toNIO).toSeq,
          jvmFlags(),
          labels())
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy