Advertisement
Guest User

Untitled

a guest
May 28th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import sbt.Keys._
  2. import sbt._
  3. import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
  4.  
  5. lazy val resolversSettings = Seq(...)
  6.  
  7. lazy val dependenciesSettings = Seq(...)
  8.  
  9. lazy val commonSettings = Seq(...)
  10.  
  11. lazy val dockerSettings = Seq(
  12. docker <<= docker.dependsOn(Keys.`package`.in(Compile, packageBin)),
  13. dockerfile in docker := {
  14. val jarFile = Keys.`package`.in(Compile, packageBin).value
  15. val classpath = (managedClasspath in Compile).value
  16. val mainclass = mainClass.in(Compile, packageBin).value.get
  17. val libs = "/app/libs"
  18. val jarTarget = "/app/" + jarFile.name
  19.  
  20. new Dockerfile {
  21. // Use a base image that contain Java
  22. from("java")
  23. // Expose port 8888
  24. expose(8888)
  25.  
  26. // Copy all dependencies to 'libs' in the staging directory
  27. classpath.files.foreach { depFile =>
  28. val target = file(libs) / depFile.name
  29. stageFile(depFile, target)
  30. }
  31. // Add the libs dir from the
  32. copyRaw(libs, libs)
  33.  
  34. // Add the generated jar file
  35. copy(jarFile, jarTarget)
  36. // The classpath is the 'libs' dir and the produced jar file
  37. val classpathString = s"$libs/*:$jarTarget"
  38. // Set the entry point to start the application using the main class
  39. cmd("java", "-cp", classpathString, mainclass)
  40. }
  41. },
  42. imageNames in docker := {
  43. val namespcae = Some("namespace")
  44. val repository = "repository"
  45. val tag = Some(version.value)
  46. val registry = Some("registry")
  47. Seq(
  48. ImageName(namespace = namespcae,
  49. repository = repository,
  50. tag = tag,
  51. registry = registry
  52. )
  53.  
  54. )
  55. }
  56. )
  57.  
  58. lazy val publishDocker = ReleaseStep(action = st => {
  59. val extracted = Project.extract(st)
  60. val ref: ProjectRef = extracted.get(thisProjectRef)
  61.  
  62. extracted.runAggregated(sbtdocker.DockerKeys.dockerBuildAndPush in sbtdocker.DockerPlugin.autoImport.docker in ref, st)
  63.  
  64. st
  65. })
  66.  
  67. lazy val releaseSettings = Seq(releaseProcess := Seq[ReleaseStep](
  68. checkSnapshotDependencies,
  69. inquireVersions,
  70. runTest,
  71. setReleaseVersion,
  72. commitReleaseVersion,
  73. tagRelease,
  74. setNextVersion,
  75. commitNextVersion,
  76. publishDocker,
  77. pushChanges
  78. ))
  79.  
  80. lazy val root = Project(
  81. id = "root",
  82. base = file("."),
  83. settings = commonSettings ++ releaseSettings ++ dockerSettings
  84. ).enablePlugins(DockerPlugin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement