Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sbt.Keys._
- import sbt._
- import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
- lazy val resolversSettings = Seq(...)
- lazy val dependenciesSettings = Seq(...)
- lazy val commonSettings = Seq(...)
- lazy val dockerSettings = Seq(
- docker <<= docker.dependsOn(Keys.`package`.in(Compile, packageBin)),
- dockerfile in docker := {
- val jarFile = Keys.`package`.in(Compile, packageBin).value
- val classpath = (managedClasspath in Compile).value
- val mainclass = mainClass.in(Compile, packageBin).value.get
- val libs = "/app/libs"
- val jarTarget = "/app/" + jarFile.name
- new Dockerfile {
- // Use a base image that contain Java
- from("java")
- // Expose port 8888
- expose(8888)
- // Copy all dependencies to 'libs' in the staging directory
- classpath.files.foreach { depFile =>
- val target = file(libs) / depFile.name
- stageFile(depFile, target)
- }
- // Add the libs dir from the
- copyRaw(libs, libs)
- // Add the generated jar file
- copy(jarFile, jarTarget)
- // The classpath is the 'libs' dir and the produced jar file
- val classpathString = s"$libs/*:$jarTarget"
- // Set the entry point to start the application using the main class
- cmd("java", "-cp", classpathString, mainclass)
- }
- },
- imageNames in docker := {
- val namespcae = Some("namespace")
- val repository = "repository"
- val tag = Some(version.value)
- val registry = Some("registry")
- Seq(
- ImageName(namespace = namespcae,
- repository = repository,
- tag = tag,
- registry = registry
- )
- )
- }
- )
- lazy val publishDocker = ReleaseStep(action = st => {
- val extracted = Project.extract(st)
- val ref: ProjectRef = extracted.get(thisProjectRef)
- extracted.runAggregated(sbtdocker.DockerKeys.dockerBuildAndPush in sbtdocker.DockerPlugin.autoImport.docker in ref, st)
- st
- })
- lazy val releaseSettings = Seq(releaseProcess := Seq[ReleaseStep](
- checkSnapshotDependencies,
- inquireVersions,
- runTest,
- setReleaseVersion,
- commitReleaseVersion,
- tagRelease,
- setNextVersion,
- commitNextVersion,
- publishDocker,
- pushChanges
- ))
- lazy val root = Project(
- id = "root",
- base = file("."),
- settings = commonSettings ++ releaseSettings ++ dockerSettings
- ).enablePlugins(DockerPlugin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement