-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServicePlugin.scala
89 lines (79 loc) · 3.47 KB
/
ServicePlugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package xyz.driver.sbt
import com.typesafe.sbt.GitPlugin.autoImport._
import com.typesafe.sbt.SbtNativePackager.Universal
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.archetypes.JavaAppPackaging
import com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.Docker
import com.typesafe.sbt.packager.docker.{Cmd, DockerPlugin}
import java.time.Instant
import sbt.Keys._
import sbt.{Def, _}
import sbtbuildinfo.BuildInfoPlugin
import sbtbuildinfo.BuildInfoPlugin.autoImport._
/** Common settings to a service. */
object ServicePlugin extends AutoPlugin {
override def requires = BuildInfoPlugin && DockerPlugin && JavaAppPackaging && BashStartScriptPlugin
object autoImport {
val customCommands = taskKey[List[String]]("Additional commands that are run as part of docker packaging.")
}
import autoImport._
lazy val buildInfoSettings = Seq(
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, git.gitHeadCommit),
buildInfoPackage := organization.value,
buildInfoOptions += BuildInfoOption.BuildTime
)
lazy val dockerSettings = Seq(
name in Docker := name.value,
// Settings reference http://www.scala-sbt.org/sbt-native-packager/formats/docker.html
maintainer in Docker := "Driver Inc. <[email protected]>",
aggregate in Docker := true, // include subprojects,
dockerRepository := Some("gcr.io/driverinc-sandbox"),
dockerUpdateLatest := true, // automatically update the latest tag
dockerBaseImage := "openjdk:11",
dockerLabels := Map(
"build.timestamp" -> Instant.now().toString
) ++ git.gitHeadCommit.value.map("git.commit" -> _),
customCommands := Nil,
dockerCommands := dockerCommands.value.flatMap { // @see http://blog.codacy.com/2015/07/16/dockerizing-scala/
case cmd @ Cmd("FROM", _) => cmd :: customCommands.value.map(customCommand => Cmd("RUN", customCommand))
case other => List(other)
},
daemonUser in Docker := "root",
bashScriptExtraDefines += {
s"""|if [[ -f /etc/${name.value}/ssl/issuing_ca ]]; then
| keytool -import \\
| -alias driverincInternal \\
| -cacerts \\
| -file /etc/${name.value}/ssl/issuing_ca \\
| -storepass changeit -noprompt \\
| || exit 1
|else
| echo "No truststore customization." >&2
|fi
|""".stripMargin
},
javaOptions in Universal ++= Seq(
// -J params will be added as jvm parameters
// Leave some space for overhead, such as running a debug shell in a
// container under heavy load. This may need to be tweaked if heavy use of
// off-heap memory is made.
"-J-XX:MaxRAMPercentage=90"
)
)
override def projectSettings: Seq[Def.Setting[_]] =
LibraryPlugin.repositorySettings ++ buildInfoSettings ++ dockerSettings ++ Seq(
organization := "xyz.driver",
crossScalaVersions := List("2.12.7"),
scalaVersion := crossScalaVersions.value.last,
publish := {
streams.value.log
.warn(s"Project ${name.value} is a service and will therefore not be published to an artifactory.")
},
sources in (Compile, doc) := Seq.empty,
publishArtifact in (Compile, packageDoc) := false
)
override def buildSettings: Seq[Def.Setting[_]] =
addCommandAlias("start", "reStart") ++
addCommandAlias("stop", "reStop")
}