forked from softwaremill/elasticmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
356 lines (319 loc) · 13.2 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import com.amazonaws.services.s3.model.PutObjectResult
import com.softwaremill.Publish.Release.updateVersionInDocs
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import sbt.Keys.credentials
import sbt.internal.util.complete.Parsers.spaceDelimited
import sbtrelease.ReleaseStateTransformations._
import scoverage.ScoverageKeys._
import scala.sys.process.Process
val v2_12 = "2.12.12"
val v2_13 = "2.13.3"
lazy val uiDirectory = settingKey[File]("Path to the ui project directory")
lazy val updateYarn = taskKey[Unit]("Update yarn")
lazy val yarnTask = inputKey[Unit]("Run yarn with arguments")
val buildSettings = commonSmlBuildSettings ++ ossPublishSettings ++ Seq(
organization := "org.elasticmq",
scmInfo := Some(ScmInfo(url("https://github.com/softwaremill/elasticmq"), "scm:[email protected]:softwaremill/elasticmq.git")),
scalaVersion := v2_13,
crossScalaVersions := Seq(v2_13, v2_12),
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.3.0",
dependencyOverrides := akka25Overrides,
parallelExecution := false,
sonatypeProfileName := "org.elasticmq",
// workaround for: https://github.com/sbt/sbt/issues/692
fork in Test := true,
releaseProcess := {
val uploadAssembly: ReleaseStep = ReleaseStep(
action = { st: State =>
val extracted = Project.extract(st)
val (st2, _) = extracted.runTask(assembly in server, st)
val (st3, _) = extracted.runTask(s3Upload in server, st2)
st3
}
)
val uploadDocker: ReleaseStep = ReleaseStep(
action = { st: State =>
val extracted = Project.extract(st)
val (st2, _) = extracted.runTask(publish in Docker in server, st)
st2
}
)
val uploadNativeDocker: ReleaseStep = ReleaseStep(
action = { st: State =>
val extracted = Project.extract(st)
val (st2, _) = extracted.runTask(packageBin in GraalVMNativeImage in nativeServer, st)
val (st3, _) = extracted.runTask(publish in Docker in nativeServer, st2)
st3
}
)
Seq(
checkSnapshotDependencies,
inquireVersions,
// publishing locally so that the pgp password prompt is displayed early
// in the process
releaseStepCommand("publishLocalSigned"),
runClean,
runTest,
setReleaseVersion,
uploadDocker,
uploadNativeDocker,
uploadAssembly,
updateVersionInDocs(organization.value),
commitReleaseVersion,
tagRelease,
publishArtifacts,
releaseStepCommand("sonatypeBundleRelease"),
pushChanges
)
}
)
val jodaTime = "joda-time" % "joda-time" % "2.10.8"
val jodaConvert = "org.joda" % "joda-convert" % "2.2.1"
val config = "com.typesafe" % "config" % "1.4.1"
val scalalogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"
val logback = "ch.qos.logback" % "logback-classic" % "1.2.3"
val jclOverSlf4j = "org.slf4j" % "jcl-over-slf4j" % "1.7.30" // needed form amazon java sdk
val scalatest = "org.scalatest" %% "scalatest" % "3.2.3"
val awaitility = "org.awaitility" % "awaitility-scala" % "4.0.3"
val amazonJavaSdk = "com.amazonaws" % "aws-java-sdk" % "1.11.889" exclude ("commons-logging", "commons-logging")
val akkaVersion = "2.6.10"
val akkaHttpVersion = "10.2.1"
val akka2Actor = "com.typesafe.akka" %% "akka-actor" % akkaVersion
val akka2Slf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion
val akka2Streams = "com.typesafe.akka" %% "akka-stream" % akkaVersion
val akka2Testkit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test"
val akka2Http = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion
val sprayJson = "io.spray" %% "spray-json" % "1.3.6"
val akkaHttpSprayJson = "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion
val akka2HttpTestkit = "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % "test"
val scalaAsync = "org.scala-lang.modules" %% "scala-async" % "0.10.0"
val common = Seq(scalalogging)
val akka25Overrides =
Seq( // override the 2.4.x transitive dependency from Akka HTTP
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion
)
// see https://github.com/scala/scala-dist/pull/181/files
val s3Upload = TaskKey[PutObjectResult]("s3-upload", "Uploads files to an S3 bucket.")
lazy val root: Project = (project in file("."))
.settings(buildSettings)
.settings(name := "elasticmq-root")
.aggregate(commonTest, core, rest, server, nativeServer, ui)
lazy val commonTest: Project = (project in file("common-test"))
.settings(buildSettings)
.settings(name := "elasticmq-common-test")
.settings(Seq(libraryDependencies ++= Seq(scalatest, awaitility, logback), publishArtifact := false))
lazy val core: Project = (project in file("core"))
.settings(buildSettings)
.settings(
Seq(name := "elasticmq-core",
libraryDependencies ++= Seq(jodaTime, jodaConvert, akka2Actor, akka2Testkit) ++ common,
coverageMinimum := 94))
.dependsOn(commonTest % "test")
lazy val rest: Project = (project in file("rest"))
.settings(buildSettings)
.settings(name := "elasticmq-rest")
.aggregate(restSqs, restSqsTestingAmazonJavaSdk)
lazy val restSqs: Project = (project in file("rest/rest-sqs"))
.settings(buildSettings)
.settings(Seq(
name := "elasticmq-rest-sqs",
libraryDependencies ++= Seq(akka2Actor,
akka2Slf4j,
akka2Http,
akka2Streams,
sprayJson,
akkaHttpSprayJson,
akka2Testkit,
akka2HttpTestkit,
scalaAsync) ++ common
))
.dependsOn(core % "compile->compile;test->test", commonTest % "test")
lazy val restSqsTestingAmazonJavaSdk: Project =
(project in file("rest/rest-sqs-testing-amazon-java-sdk"))
.settings(buildSettings)
.settings(
Seq(
name := "elasticmq-rest-sqs-testing-amazon-java-sdk",
libraryDependencies ++= Seq(amazonJavaSdk, jclOverSlf4j) ++ common,
publishArtifact := false
)
)
.dependsOn(restSqs % "test->test")
lazy val server: Project = (project in file("server"))
.enablePlugins(JavaServerAppPackaging, DockerPlugin)
.settings(buildSettings)
.settings(generateVersionFileSettings)
.settings(uiSettings)
.settings(Seq(
name := "elasticmq-server",
libraryDependencies ++= Seq(logback, config),
unmanagedResourceDirectories in Compile += { baseDirectory.value / ".." / "ui" / "build" },
assembly := assembly.dependsOn(yarnTask.toTask(" build")).value,
mainClass in assembly := Some("org.elasticmq.server.Main"),
coverageMinimum := 52,
// s3 upload
s3Upload := {
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials, DefaultAWSCredentialsProviderChain}
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.{CannedAccessControlList, PutObjectRequest}
val bucketName = "softwaremill-public"
val creds = Credentials.forHost(credentials.value, bucketName + ".s3.amazonaws.com")
val awsCreds = creds match {
case Some(cred) => new AWSStaticCredentialsProvider(new BasicAWSCredentials(cred.userName, cred.passwd))
case None => new DefaultAWSCredentialsProviderChain
}
val client = AmazonS3ClientBuilder.standard().withCredentials(awsCreds).withRegion("eu-west-1").build()
val log = streams.value.log
val v = version.value
val source = (assemblyOutputPath in assembly).value
val targetObjectName = s"elasticmq-server-$v.jar"
log.info("Uploading " + source.getAbsolutePath + " as " + targetObjectName)
client.putObject(new PutObjectRequest(bucketName, targetObjectName, source)
.withCannedAcl(CannedAccessControlList.PublicRead))
},
/*
Format:
realm=Amazon S3
host=softwaremill-public.s3.amazonaws.com
user=[AWS key id]
password=[AWS secret key]
*/
credentials += Credentials(Path.userHome / ".s3_elasticmq_credentials"),
// docker
dockerExposedPorts := Seq(9324,9325),
dockerBaseImage := "openjdk:8u212-b04-jdk-stretch",
packageName in Docker := "elasticmq",
dockerUsername := Some("softwaremill"),
dockerUpdateLatest := true,
javaOptions in Universal ++= Seq("-Dconfig.file=/opt/elasticmq.conf"),
mappings in Docker ++= Seq(
(baseDirectory.value / "docker" / "elasticmq.conf") -> "/opt/elasticmq.conf"
),
publishLocal in Docker := (publishLocal in Docker).dependsOn(yarnTask.toTask(" build")).value,
dockerCommands += Cmd(
"COPY",
"--from=stage0",
s"--chown=${(daemonUser in Docker).value}:root",
"/opt/elasticmq.conf",
"/opt"
)
)
)
.dependsOn(core, restSqs, commonTest % "test")
val graalVmVersion = "20.3.0"
lazy val nativeServer: Project = (project in file("native-server"))
.enablePlugins(GraalVMNativeImagePlugin, DockerPlugin)
.settings(buildSettings)
.settings(uiSettings)
.settings(Seq(
name := "elasticmq-native-server",
libraryDependencies ++= Seq(
"org.graalvm.nativeimage" % "svm" % graalVmVersion % "compile-internal"
),
//configures sbt-native-packager to build app using dockerized graalvm
graalVMNativeImageGraalVersion := Some(graalVmVersion + "-java11"),
graalVMNativeImageOptions ++= Seq(
"--static",
"-H:IncludeResources=.*conf",
"-H:IncludeResources=version",
"-H:IncludeResources=.*\\.properties",
"-H:IncludeResources='org/joda/time/tz/data/.*'",
"-H:+ReportExceptionStackTraces",
"-H:-ThrowUnsafeOffsetErrors",
"-H:+PrintClassInitialization",
"--enable-http",
"--enable-https",
"--enable-url-protocols=https,http",
"--initialize-at-build-time",
"--report-unsupported-elements-at-runtime",
"--allow-incomplete-classpath",
"--no-fallback",
"--verbose"
),
mainClass in Compile := Some("org.elasticmq.server.Main"),
//configures sbt-native-packager to build docker image with generated executable
dockerBaseImage := "alpine:3.11",
mappings in Docker := Seq(
(baseDirectory.value / ".." / "server" / "docker" / "elasticmq.conf") -> "/opt/elasticmq.conf",
((target in GraalVMNativeImage).value / "elasticmq-native-server") -> "/opt/docker/bin/elasticmq-native-server"
) ++ sbt.Path.directory(baseDirectory.value / ".." / "ui" / "build"),
dockerEntrypoint := Seq("/sbin/tini", "--", "/opt/docker/bin/elasticmq-native-server", "-Dconfig.file=/opt/elasticmq.conf"),
dockerUpdateLatest := true,
dockerExposedPorts := Seq(9324,9325),
dockerCommands := {
val commands = dockerCommands.value
val index = commands.indexWhere {
case Cmd("FROM", args@_*) =>
args.head == "alpine:3.11" && args.last == "mainstage"
case _ => false
}
val (front, back) = commands.splitAt(index + 1)
// sbt-native-packager by default copies stage0:/opt/docker to the target container; we need to additionally
// copy the configuration file
val copyConfig = Cmd("COPY",
"--from=stage0",
"/opt/elasticmq.conf",
"/opt")
val copyUI = Cmd(
"COPY",
"/build/",
"/opt/docker"
)
val tiniCommand = ExecCmd("RUN", "apk", "add", "--no-cache", "tini")
front ++ Seq(tiniCommand, copyConfig, copyUI) ++ back
},
packageName in Docker := "elasticmq-native",
dockerUsername := Some("softwaremill"),
packageBin in GraalVMNativeImage := (packageBin in GraalVMNativeImage).dependsOn(yarnTask.toTask(" build")).value,
dockerUpdateLatest := true,
))
.dependsOn(server)
lazy val performanceTests: Project = (project in file("performance-tests"))
.settings(buildSettings)
.settings(
Seq(
name := "elasticmq-performance-tests",
libraryDependencies ++= Seq(amazonJavaSdk, jclOverSlf4j, logback) ++ common,
publishArtifact := false
))
.dependsOn(core, restSqs, commonTest % "test")
val generateVersionFileSettings = Seq(
resourceGenerators in Compile += Def.task {
val targetFile = (resourceManaged in Compile).value / "version"
IO.write(targetFile, version.value.toString)
Seq(targetFile)
}.taskValue
)
lazy val uiSettings = Seq(
uiDirectory := baseDirectory.value.getParentFile / "ui",
updateYarn := {
streams.value.log("Updating npm/yarn dependencies")
haltOnCmdResultError(Process("yarn install", uiDirectory.value).!)
},
yarnTask := {
val taskName = spaceDelimited("<arg>").parsed.mkString(" ")
updateYarn.value
val localYarnCommand = "yarn " + taskName
def runYarnTask() = Process(localYarnCommand, uiDirectory.value).!
streams.value.log("Running yarn task: " + taskName)
haltOnCmdResultError(runYarnTask())
}
)
lazy val ui = (project in file("ui"))
.settings(buildSettings)
.settings(uiSettings)
.settings(
test in Test := (test in Test).dependsOn(yarnTask.toTask(" test:ci")).value,
compile in Compile := {
yarnTask.toTask(" build").value
(compile in Compile).value
},
cleanFiles += baseDirectory.value / "build",
unmanagedResourceDirectories in Compile += baseDirectory.value / "build"
)
def haltOnCmdResultError(result: Int) {
if (result != 0) {
throw new Exception("Build failed.")
}
}