-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sbt
463 lines (431 loc) · 19.4 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
import ReleaseTransformations.*
import sbtversionpolicy.withsbtrelease.ReleaseVersion
import play.sbt.PlayImport.specs2
import sbt.Keys.{libraryDependencies, mainClass}
import sbtassembly.AssemblyPlugin.autoImport.{assemblyJarName, assemblyMergeStrategy}
import sbtassembly.MergeStrategy
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
val projectVersion = "1.0-latest"
ThisBuild / publish / skip := true
releaseVersion := ReleaseVersion.fromAggregatedAssessedCompatibilityWithLatestRelease().value
releaseCrossBuild := true // true if you cross-build the project for multiple Scala versions
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
setNextVersion,
commitNextVersion
)
ThisBuild / scalaVersion := "2.13.16"
val compilerOptions = Seq(
"-deprecation",
"-Xfatal-warnings",
"-feature",
"-language:postfixOps",
"-language:implicitConversions",
"-release:11"
)
ThisBuild / scalacOptions ++= compilerOptions
val playJsonVersion = "3.0.4"
val specsVersion: String = "4.8.3"
val awsSdkVersion: String = "1.12.780"
val doobieVersion: String = "0.13.4"
val catsVersion: String = "2.13.0"
val okHttpVersion: String = "4.12.0"
val paClientVersion: String = "7.0.12"
val apacheThrift: String = "0.15.0"
val jacksonDatabind: String = "2.18.2"
val jacksonCbor: String = "2.18.2"
val jacksonScalaModule: String = "2.18.2"
val simpleConfigurationVersion: String = "1.5.7"
val googleOAuthClient: String = "1.37.0"
val nettyVersion: String = "4.1.117.Final"
val slf4jVersion: String = "1.7.36"
val logbackVersion: String = "1.5.16"
val standardSettings = Seq[Setting[_]](
// We should remove this when all transitive dependencies use the same version of scala-xml
// For now this isn't considered an issue due to the compatability between 1.2.x and 2.1.x of the library
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always,
resolvers ++= Seq(
"Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
"Guardian GitHub Snapshots" at "https://guardian.github.com/maven/repo-snapshots"
),
libraryDependencies ++= Seq(
"com.github.nscala-time" %% "nscala-time" % "3.0.0",
"com.softwaremill.macwire" %% "macros" % "2.6.5" % "provided",
specs2 % Test,
"org.specs2" %% "specs2-matcher-extra" % specsVersion % Test
),
// Workaround Mockito causes deadlock on SBT classloaders: https://github.com/sbt/sbt/issues/3022
Test / parallelExecution := false,
Test / testOptions += Tests.Argument(TestFrameworks.Specs2, "junitxml", "console")
)
lazy val commoneventconsumer = project
.settings(Seq(
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"com.amazonaws" % "aws-java-sdk-athena" % awsSdkVersion,
"org.playframework" %% "play-json" % playJsonVersion,
"org.specs2" %% "specs2-core" % specsVersion % "test",
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabind,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % jacksonCbor,
"com.fasterxml.jackson.module" % "jackson-module-scala_2.13" % jacksonScalaModule
),
))
lazy val commontest = project
.settings(Seq(
libraryDependencies ++= Seq(
specs2,
playCore,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabind,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % jacksonCbor,
"com.fasterxml.jackson.module" % "jackson-module-scala_2.13" % jacksonScalaModule
),
))
lazy val common = project
.dependsOn(commoneventconsumer)
.settings(LocalDynamoDBCommon.settings)
.settings(standardSettings: _*)
.settings(
libraryDependencies ++= Seq(
ws,
"org.typelevel" %% "cats-core" % catsVersion,
"joda-time" % "joda-time" % "2.13.0",
"org.playframework" %% "play-json" % playJsonVersion,
"org.playframework" %% "play-json-joda" % playJsonVersion,
"com.gu" %% "pa-client" % paClientVersion,
"com.amazonaws" % "aws-java-sdk-dynamodb" % awsSdkVersion,
"com.amazonaws" % "aws-java-sdk-cloudwatch" % awsSdkVersion,
"com.googlecode.concurrentlinkedhashmap" % "concurrentlinkedhashmap-lru" % "1.4.2",
"ai.x" %% "play-json-extensions" % "0.42.0",
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
"org.tpolecat" %% "doobie-specs2" % doobieVersion % Test,
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % Test,
"org.tpolecat" %% "doobie-h2" % doobieVersion % Test,
"com.gu" %% "mobile-logstash-encoder" % "1.1.8",
"com.gu" %% "simple-configuration-ssm" % simpleConfigurationVersion,
"io.netty" % "netty-handler" % nettyVersion,
"io.netty" % "netty-codec" % nettyVersion,
"io.netty" % "netty-codec-http" % nettyVersion,
"io.netty" % "netty-codec-http2" % nettyVersion,
"io.netty" % "netty-common" % nettyVersion,
"org.postgresql" % "postgresql" % "42.7.5",
"ch.qos.logback" % "logback-core" % logbackVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,
),
fork := true,
startDynamoDBLocal := startDynamoDBLocal.dependsOn(Test / compile).value,
Test / test := (Test / test).dependsOn(startDynamoDBLocal).value,
Test / testOnly := (Test / testOnly).dependsOn(startDynamoDBLocal).evaluated,
Test / testQuick := (Test / testQuick).dependsOn(startDynamoDBLocal).evaluated,
Test / testOptions += dynamoDBLocalTestCleanup.value,
// the following option is to allow tests using wsClient such as NotificationHubClientSpec
Test / testOptions += Tests.Argument(TestFrameworks.Specs2, "sequential", "true")
)
lazy val commonscheduledynamodb = project
.settings(LocalDynamoDBScheduleLambda.settings)
.settings(List(
libraryDependencies ++= List(
"com.amazonaws" % "aws-java-sdk-dynamodb" % awsSdkVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabind,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % jacksonCbor,
"com.fasterxml.jackson.module" % "jackson-module-scala_2.13" % jacksonScalaModule,
specs2 % Test
),
Test / test := (Test / test).dependsOn(startDynamoDBLocal).value,
Test / testOnly := (Test / testOnly).dependsOn(startDynamoDBLocal).evaluated,
Test / testQuick := (Test / testQuick).dependsOn(startDynamoDBLocal).evaluated,
Test / testOptions += dynamoDBLocalTestCleanup.value
))
lazy val registration = project
.dependsOn(common, commontest % "test->test")
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
.settings(standardSettings: _*)
.settings(
fork := true,
routesImport ++= Seq(
"binders.querystringbinders._",
"binders.pathbinders._",
"models._"
),
libraryDependencies ++= Seq(
logback,
"org.tpolecat" %% "doobie-h2" % doobieVersion % Test
),
excludeDependencies ++= Seq(
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
Debian / packageName := name.value,
version := projectVersion
)
lazy val notification = project
.dependsOn(common)
.dependsOn(commonscheduledynamodb)
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
.settings(standardSettings: _*)
.settings(
fork := true,
routesImport ++= Seq(
"binders.querystringbinders._",
"binders.pathbinders._",
"models._"
),
libraryDependencies ++= Seq(
logback,
"com.amazonaws" % "aws-java-sdk-sqs" % awsSdkVersion
),
excludeDependencies ++= Seq(
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
Debian / packageName := name.value,
version := projectVersion
)
lazy val report = project
.dependsOn(common, commontest % "test->test")
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
.settings(standardSettings: _*)
.settings(
fork := true,
routesImport ++= Seq(
"binders.querystringbinders._",
"binders.pathbinders._",
"org.joda.time.DateTime",
"models._"
),
libraryDependencies ++= Seq(
logback
),
excludeDependencies ++= Seq(
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
Debian / packageName := name.value,
version := projectVersion
)
lazy val apiModels = {
import sbt.Keys.organization
import sbtrelease._
import ReleaseStateTransformations._
Project("api-models", file("api-models")).settings(Seq(
name := "mobile-notifications-api-models",
publish / skip := false,
libraryDependencies ++= Seq(
"org.playframework" %% "play-json" % playJsonVersion,
"org.specs2" %% "specs2-core" % specsVersion % "test",
"org.specs2" %% "specs2-mock" % specsVersion % "test",
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabind,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-cbor" % jacksonCbor,
"com.fasterxml.jackson.module" % "jackson-module-scala_2.13" % jacksonScalaModule
),
organization := "com.gu",
description := "Scala models for the Guardian Push Notifications API",
licenses := Seq(License.Apache2),
))
}
def lambda(projectName: String, directoryName: String, mainClassName: Option[String] = None): Project =
Project(projectName, file(directoryName))
.enablePlugins(AssemblyPlugin)
.settings(
organization := "com.gu",
resolvers ++= Seq(
"Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
"snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
),
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-lambda-java-core" % "1.2.3",
"org.slf4j" % "slf4j-api" % slf4jVersion,
"com.gu" %% "simple-configuration-core" % simpleConfigurationVersion,
"com.gu" %% "simple-configuration-ssm" % simpleConfigurationVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,
"net.logstash.logback" % "logstash-logback-encoder" % "8.0",
specs2 % Test
),
assemblyJarName := s"$projectName.jar",
assembly / assemblyMergeStrategy := {
case "META-INF/MANIFEST.MF" => MergeStrategy.discard
case _ => MergeStrategy.first
},
Test / run / fork := true,
scalacOptions := compilerOptions,
mainClass := mainClassName,
// Workaround Mockito causes deadlock on SBT classloaders: https://github.com/sbt/sbt/issues/3022
Test / parallelExecution := false
)
lazy val schedulelambda = lambda("schedule", "schedulelambda")
.dependsOn(commonscheduledynamodb)
.settings {
List(
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk-cloudwatch" % awsSdkVersion,
"com.amazonaws" % "aws-java-sdk-dynamodb" % awsSdkVersion,
"com.squareup.okhttp3" % "okhttp" % okHttpVersion,
"org.specs2" %% "specs2-core" % specsVersion % "test",
"org.specs2" %% "specs2-scalacheck" % specsVersion % "test",
"org.specs2" %% "specs2-mock" % specsVersion % "test",
"io.netty" % "netty-common" % nettyVersion,
"io.netty" % "netty-codec" % nettyVersion,
"io.netty" % "netty-codec-http" % nettyVersion,
"io.netty" % "netty-codec-http2" % nettyVersion
),
excludeDependencies ++= Seq(
ExclusionRule("org.playframework", "play-ahc-ws_2.13"),
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
)
}
lazy val football = lambda("football", "football")
.dependsOn(apiModels % "test->test", apiModels % "compile->compile")
.settings(
resolvers += "Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
libraryDependencies ++= Seq(
"org.scanamo" %% "scanamo" % "1.0.0-M12-1",
"org.scanamo" %% "scanamo-testkit" % "1.0.0-M12-1" % "test",
"com.gu" %% "content-api-client-default" % "33.0.0",
"com.amazonaws" % "aws-java-sdk-dynamodb" % awsSdkVersion,
"com.gu" %% "pa-client" % paClientVersion,
"com.squareup.okhttp3" % "okhttp" % okHttpVersion,
"org.specs2" %% "specs2-core" % specsVersion % "test",
"org.specs2" %% "specs2-mock" % specsVersion % "test",
"io.netty" % "netty-codec" % nettyVersion,
"io.netty" % "netty-codec-http" % nettyVersion,
"io.netty" % "netty-codec-http2" % nettyVersion,
"io.netty" % "netty-common" % nettyVersion,
),
excludeDependencies ++= Seq(
ExclusionRule("org.playframework", "play-ahc-ws_2.13"),
ExclusionRule("software.amazon.awssdk", "ec2"),
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
)
lazy val eventconsumer = lambda("eventconsumer", "eventconsumer", Some("com.gu.notifications.events.LocalRun"))
.dependsOn(commoneventconsumer)
.settings({
Seq(
description := "Consumes events produced when an app receives a notification",
libraryDependencies ++= Seq(
"org.playframework" %% "play-json" % playJsonVersion,
"com.amazonaws" % "aws-java-sdk-dynamodb" % awsSdkVersion,
"org.scala-lang.modules" %% "scala-java8-compat" % "1.0.2",
"io.netty" % "netty-codec-http2" % nettyVersion
),
)
})
lazy val sloMonitor = lambda("slomonitor", "slomonitor", Some("com.gu.notifications.slos.SloMonitor"))
.dependsOn(commoneventconsumer)
.settings({
Seq(
description := "Monitors SLO performance for breaking news notifications",
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-lambda-java-events" % "3.14.0",
"com.amazonaws" % "aws-java-sdk-cloudwatch" % awsSdkVersion,
"io.netty" % "netty-codec" % nettyVersion,
"io.netty" % "netty-codec-http" % nettyVersion,
"io.netty" % "netty-codec-http2" % nettyVersion,
),
Test / fork := true,
Test / envVars := Map("STAGE" -> "TEST")
)
})
lazy val latestVersionOfLambdaSDK = {
import scala.jdk.CollectionConverters._
import com.github.dockerjava.core.DefaultDockerClientConfig
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient
import com.github.dockerjava.core.DockerClientImpl
val imageName = "public.ecr.aws/lambda/java:latest"
val dockerCfg = DefaultDockerClientConfig.createDefaultConfigBuilder().build()
val dockerHttp = new ApacheDockerHttpClient.Builder()
.dockerHost(dockerCfg.getDockerHost())
.sslConfig(dockerCfg.getSSLConfig())
.build();
val docker = DockerClientImpl.getInstance(dockerCfg, dockerHttp)
docker.pullImageCmd(imageName).start().awaitCompletion()
val image = docker.inspectImageCmd(imageName).exec()
image.getRepoDigests().asScala.head
}
lazy val lambdaDockerCommands = dockerCommands := Seq(
Cmd ( "FROM", latestVersionOfLambdaSDK),
Cmd ( "LABEL", s"sdkBaseVersion=${latestVersionOfLambdaSDK}"),
ExecCmd( "COPY", "1/opt/docker/*", "${LAMBDA_TASK_ROOT}/lib/"),
ExecCmd( "COPY", "2/opt/docker/*", "${LAMBDA_TASK_ROOT}/lib/"),
Cmd ( "EXPOSE", "8080"), // this is the local lambda run time for testing
ExecCmd( "CMD", "com.gu.notifications.worker.ContainerLambdaTest::handleRequest"),
)
lazy val buildNumber = sys.env.get("BUILD_NUMBER").orElse(Some("DEV"))
lazy val ecrRepositorySettings =
sys.env.get("NOTIFICATION_LAMBDA_REPOSITORY_URL") match {
case Some(url) =>
val Array(repo, name) = url.split("/", 2)
Seq(
dockerRepository := Some(repo),
Docker / packageName := name
)
case None => Nil
}
lazy val notificationworkerlambda = lambda("notificationworkerlambda", "notificationworkerlambda", Some("com.gu.notifications.worker.TopicCounterLocalRun"))
.dependsOn(common)
.enablePlugins(DockerPlugin)
.enablePlugins(JavaAppPackaging)
.settings(ecrRepositorySettings: _*)
.settings(
lambdaDockerCommands,
dockerExposedPorts := Seq(9000), // exposed by the lambda runtime api inside the image
dockerAlias := DockerAlias(registryHost = dockerRepository.value, username = None, name = (Docker / packageName).value, tag = buildNumber),
libraryDependencies ++= Seq(
"com.turo" % "pushy" % "0.13.10",
"com.google.firebase" % "firebase-admin" % "9.2.0",
"com.google.protobuf" % "protobuf-java" % "4.29.3",
"com.google.protobuf" % "protobuf-java-util" % "4.29.3",
"com.amazonaws" % "aws-lambda-java-events" % "2.2.9",
"com.amazonaws" % "aws-java-sdk-sqs" % awsSdkVersion,
"com.amazonaws" % "aws-java-sdk-s3" % awsSdkVersion,
"com.amazonaws" % "amazon-sqs-java-messaging-lib" % "2.1.4",
"com.squareup.okhttp3" % "okhttp" % okHttpVersion,
"org.playframework" %% "play-json" % playJsonVersion,
"com.google.oauth-client" % "google-oauth-client" % googleOAuthClient,
),
excludeDependencies ++= Seq(
ExclusionRule("org.playframework", "play-ahc-ws_2.13"),
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
)
lazy val fakebreakingnewslambda = lambda("fakebreakingnewslambda", "fakebreakingnewslambda", Some("fakebreakingnews.LocalRun"))
.dependsOn(common)
.dependsOn(apiModels % "test->test", apiModels % "compile->compile")
.settings(
libraryDependencies ++= Seq(
"com.squareup.okhttp3" % "okhttp" % okHttpVersion,
),
excludeDependencies ++= Seq(
ExclusionRule("org.playframework", "play-ahc-ws_2.13"),
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
),
)
lazy val reportExtractor = lambda("reportextractor", "reportextractor", Some("com.gu.notifications.extractor.LocalRun"))
.dependsOn(common)
.settings(
excludeDependencies ++= Seq(
ExclusionRule("org.playframework", "play-ahc-ws_2.13"),
// As of Play 3.0, groupId has changed to org.playframework; exclude transitive dependencies to the old artifacts
// Hopefully this workaround can be removed once play-json-extensions either updates to Play 3.0 or is merged into play-json
ExclusionRule(organization = "com.typesafe.play")
)
)