-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sbt
270 lines (223 loc) · 8.33 KB
/
build.sbt
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import sbt.Keys.*
import sbt.*
import sbtbuildinfo.BuildInfoKeys.{buildInfoKeys, buildInfoOptions, buildInfoPackage}
import sbtbuildinfo.{BuildInfoKey, BuildInfoOption}
import scala.sys.process.*
name := """service-chassis"""
organization := "allawala"
scalaVersion := "2.13.15"
scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xlint", // Enable recommended additional warnings.
"-Xlint:-byname-implicit", // To disable Block result was adapted via implicit conversion (method apply) taking a by-name parameter
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-release:21",
"-encoding", "UTF-8",
"-language:existentials",
"-language:higherKinds"
)
libraryDependencies ++= {
val akkaVersion = "2.9.5"
val akkaHttpVersion = "10.6.3"
val akkaHttpCirceVersion = "1.39.2"
val beanUtilsVersion = "1.9.4"
val bouncyCastleVersion = "1.78.1"
val circeVersion = "0.14.10"
val circeOpticsVersion = "0.15.0"
val circeGenericsVersion = "0.14.4"
val enumeratumVersion = "1.7.5"
val enumeratumCirceVersion = "1.7.5"
val ficusVersion = "1.5.2"
val guiceVersion = "7.0.0"
val scalaGuiceVersion = "7.0.0"
val jakartaXmlBindVersion = "4.0.2"
val jwtCirceVersion = "10.0.1"
val logbackVersion = "1.5.8"
val metricsVersion = "4.3.2"
val mockitoVersion = "5.14.1"
val scalaI18nVersion = "1.1.0"
val scalaLoggingVersion = "3.9.5"
val scalatestVersion = "3.2.19"
val scalatestMockitoVersion = "3.2.19.0"
val shiroVersion = "1.13.0"
val threeTenExtraVersion = "1.8.0"
Seq(
// Akka
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-pki" % akkaVersion,
// BeanUtils
"commons-beanutils" % "commons-beanutils" % beanUtilsVersion,
// BouncyCastle
"org.bouncycastle" % "bcprov-jdk15to18" % bouncyCastleVersion,
"org.bouncycastle" % "bcpkix-jdk15to18" % bouncyCastleVersion,
// Config
"com.iheart" %% "ficus" % ficusVersion,
// DI
"com.google.inject" % "guice" % guiceVersion,
"net.codingwell" %% "scala-guice" % scalaGuiceVersion,
// Enums
"com.beachape" %% "enumeratum" % enumeratumVersion,
"com.beachape" %% "enumeratum-circe" % enumeratumCirceVersion,
// Json
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-optics" % circeOpticsVersion,
"io.circe" %% "circe-generic-extras" % circeGenericsVersion,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceVersion excludeAll ExclusionRule(organization = "io.circe"),
// JWT
"com.github.jwt-scala" %% "jwt-circe" % jwtCirceVersion,
"jakarta.xml.bind" % "jakarta.xml.bind-api" % jakartaXmlBindVersion excludeAll ExclusionRule(organization = "jakarta.activation"),
// Logging
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
// Metrics
"nl.grons" %% "metrics4-scala" % metricsVersion,
// Shiro
"org.apache.shiro" % "shiro-core" % shiroVersion,
"org.apache.shiro" % "shiro-guice" % shiroVersion excludeAll ExclusionRule(organization = "com.google.inject.extensions"),
// Threeten Extras
"org.threeten" % "threeten-extra" % threeTenExtraVersion,
// i18n
"com.osinka.i18n" %% "scala-i18n" % scalaI18nVersion,
// Test Dependencies
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % "test",
"org.mockito" % "mockito-core" % mockitoVersion % "test",
"org.scalatest" %% "scalatest" % scalatestVersion % "test",
"org.scalatestplus" %% "mockito-5-12" % scalatestMockitoVersion % "test"
)
}
// plugins
enablePlugins(BuildInfoPlugin, GitVersioning, GitBranchPrompt, sbtdocker.DockerPlugin, JavaAppPackaging)
// BuildInfo plugin Settings
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, git.gitCurrentBranch, git.gitHeadCommit)
buildInfoPackage := "allawala"
buildInfoOptions += BuildInfoOption.BuildTime
// sbt git plugin settings
// turn on the version detection
git.useGitDescribe := true
git.baseVersion := "1.0.0"
// publish info
publishMavenStyle := true
publishTo := {
if (version.value.endsWith("SNAPSHOT")) {
Some("Service Chassis Snapshots" at "s3://s3-ap-southeast-2.amazonaws.com/maven.allawala.com/service-chassis/snapshots")
} else {
Some("Service Chassis Snapshots" at "s3://s3-ap-southeast-2.amazonaws.com/maven.allawala.com/service-chassis/releases")
}
}
lazy val removeDangling = taskKey[Unit]("Task to clean up dangling docker images")
removeDangling := {
// TODO get the dockerpath from env like ${DOCKER_HOME}
val dockerPath = "/usr/local/bin/docker"
val findDangling = s"$dockerPath images -f dangling=true -q"
val removeDangling = s"xargs $dockerPath rmi -f"
val deleted = findDangling.#|(removeDangling).!!
val s: TaskStreams = streams.value
if (deleted.isEmpty) {
s.log.info("No dangling images to delete")
} else {
s.log.info(s"The following dangling images were deleted\n$deleted")
}
}
// docker
// TODO review these options
docker / buildOptions := BuildOptions(
// cache = false,
removeIntermediateContainers = BuildOptions.Remove.Always
// pullBaseImage = BuildOptions.Pull.Always
)
docker / imageNames := {
val registry = "xxxxx.dkr.ecr.eu-central-1.amazonaws.com/xxxxx"
def withSha: ImageName = {
val tag = for {
sha <- git.gitHeadCommit.value
v = version.value
} yield s"$v-$sha"
ImageName(
registry = Some(registry),
repository = name.value,
tag = tag
)
}
def withoutSha: ImageName = {
ImageName(
registry = Some(registry),
repository = name.value,
tag = Some(version.value)
)
}
def latest: ImageName = ImageName(
registry = Some(organization.value),
repository = name.value,
tag = Some("latest")
)
// This assumes a multibranch pipeline structure and the presence of BRANCH_NAME env variable
val imageName = sys.env.get("BRANCH_NAME").map(_.toLowerCase) match {
case Some("develop") => withSha
case Some("master") => withoutSha
case _ => latest
}
Seq(imageName)
}
docker / dockerfile := {
val exposePort = 8080
// The assembly task generates a fat JAR file
val appDir: File = stage.value
val targetDir = "/opt"
new Dockerfile {
from("hseeberger/scala-sbt:11.0.14.1_1.6.2_2.12.15")
expose(exposePort)
entryPoint(s"$targetDir/bin/${executableScriptName.value}")
copy(appDir, targetDir)
}
}
// releasing with the gitflow plugin
import sbtrelease.*
import allawala.sbt.sbtrelease.gitflow.Steps.*
import sbtrelease.ReleaseStateTransformations.*
releaseProcess := Seq(
releaseStepCommand(ExtraReleaseCommands.initialVcsChecksCommand),
checkSnapshotDependencies,
checkGitFlowExists,
inquireVersions,
runTest,
gitFlowReleaseStart,
setReleaseVersion,
commitReleaseVersion,
publishArtifacts,
gitFlowReleaseFinish,
pushMaster,
setNextVersion,
commitNextVersion,
pushChanges
)
Compile / packageBin / mappings ~= { seq =>
seq.filter{
case (file, _) =>
val fileName = file.getName
!(fileName.equalsIgnoreCase("logback.xml") || fileName.startsWith("BuildInfo"))
}
}
// Dependency Graph tree
//dependencyDotFile := file("dependencies.dot") //render dot file to `./dependencies.dot`
initialCommands :=
"""
import akka.actor._
import akka.pattern._
import akka.util._
import scala.concurrent._
import scala.concurrent.duration._
""".stripMargin
resolvers += "Git Flow Snapshots" at "s3://s3-ap-southeast-2.amazonaws.com/maven.allawala.com/sbt-gitflow/snapshots"
resolvers += "Git Flow Releases" at "s3://s3-ap-southeast-2.amazonaws.com/maven.allawala.com/sbt-gitflow/releases"
resolvers += "Akka library repository".at("https://repo.akka.io/maven")
run / fork := true
// Running `sbt test` hangs without the following line, possibly due to https://github.com/sbt/sbt/issues/3022
Test / parallelExecution := false