forked from cloudstateio/cloudstate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
893 lines (840 loc) · 39.3 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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
import java.io.File
import java.util.Date
import sbt.Keys.{developers, scmInfo}
import sbt.url
inThisBuild(
Seq(
organization := "io.cloudstate",
version := dynverGitDescribeOutput.value.mkVersion(versionFmt, "latest"),
dynver := sbtdynver.DynVer.getGitDescribeOutput(new Date).mkVersion(versionFmt, "latest"),
scalaVersion := "2.12.11",
// Needed for the akka-grpc 0.8.4 snapshot
resolvers += Resolver.bintrayRepo("akka", "maven"), // TODO: Remove once we're switching to akka-grpc 0.8.5/1.0.0
organizationName := "Lightbend Inc.",
organizationHomepage := Some(url("https://lightbend.com")),
startYear := Some(2019),
licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt")),
homepage := Some(url("https://cloudstate.io")),
scmInfo := Some(
ScmInfo(
url("https://github.com/cloudstateio/cloudstate"),
"scm:[email protected]:cloudstateio/cloudstate.git"
)
),
developers := List(
Developer(id = "jroper", name = "James Roper", email = "[email protected]", url = url("https://jazzy.id.au")),
Developer(id = "viktorklang",
name = "Viktor Klang",
email = "[email protected]",
url = url("https://viktorklang.com"))
),
sonatypeProfileName := "io.cloudstate",
scalafmtOnCompile := true,
closeClassLoaders := false
)
)
// Make sure the version doesn't change each time it gets built, this ensures we don't rebuild the native image
// every time we build a docker image based on it, since we actually build 3 different docker images for the proxy
// command.
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
val dirtySuffix = if (out.isDirty()) "-dev" else ""
if (out.isCleanAfterTag) out.ref.dropV.value
else out.ref.dropV.value + out.commitSuffix.mkString("-", "-", "") + dirtySuffix
}
name := "cloudstate"
val GrpcJavaVersion = "1.22.1"
val GraalAkkaVersion = "0.5.0"
val AkkaVersion = "2.5.31"
val AkkaHttpVersion = "10.1.11"
val AkkaManagementVersion = "1.0.5"
val AkkaPersistenceCassandraVersion = "0.102"
val PrometheusClientVersion = "0.6.0"
val ScalaTestVersion = "3.0.5"
val ProtobufVersion = "3.9.0"
val GraalVersion = "20.0.0"
val DockerBaseImageVersion = "adoptopenjdk/openjdk11:debian"
val DockerBaseImageJavaLibraryPath = "${JAVA_HOME}/lib"
def excludeTheseDependencies = Seq(
ExclusionRule("io.netty", "netty"), // grpc-java is using grpc-netty-shaded
ExclusionRule("io.aeron"), // we're using Artery-TCP
ExclusionRule("org.agrona") // and we don't need this either
)
def common: Seq[Setting[_]] = Seq(
headerMappings := headerMappings.value ++ Seq(
de.heikoseeberger.sbtheader.FileType("proto") -> HeaderCommentStyle.cppStyleLineComment,
de.heikoseeberger.sbtheader.FileType("js") -> HeaderCommentStyle.cStyleBlockComment
),
// Akka gRPC overrides the default ScalaPB setting including the file base name, let's override it right back.
akkaGrpcCodeGeneratorSettings := Seq(),
excludeFilter in headerResources := HiddenFileFilter || GlobFilter("reflection.proto"),
javaOptions in Test ++= Seq("-Xms1G", "-XX:+CMSClassUnloadingEnabled", "-XX:+UseConcMarkSweepGC")
)
// Include sources from the npm projects
headerSources in Compile ++= {
val nodeSupport = baseDirectory.value / "node-support"
val jsShoppingCart = baseDirectory.value / "samples" / "js-shopping-cart"
Seq(
nodeSupport / "src" ** "*.js",
nodeSupport * "*.js",
jsShoppingCart * "*.js",
jsShoppingCart / "test" ** "*.js"
).flatMap(_.get)
}
lazy val root = (project in file("."))
// Don't forget to add your sbt module here!
// A missing module here can lead to failing Travis test results
.aggregate(
`protocols`,
`proxy-core`,
`proxy-cassandra`,
`proxy-postgres`,
`proxy-tests`,
`java-support`,
`scala-support`,
`java-shopping-cart`,
`java-pingpong`,
`akka-client`,
operator,
`tck`,
`graal-tools`,
docs
)
.settings(common)
val cloudstateProtocolsName = "cloudstate-protocols"
val cloudstateTCKProtocolsName = "cloudstate-tck-protocols"
lazy val protocols = (project in file("protocols"))
.settings(
name := "protocols",
publish / skip := true,
packageBin in Compile := {
val base = baseDirectory.value
val cloudstateProtos = base / s"$cloudstateProtocolsName.zip"
val cloudstateTCKProtos = base / s"$cloudstateTCKProtocolsName.zip"
def archiveStructure(topDirName: String, files: PathFinder): Seq[(File, String)] =
files pair Path.relativeTo(base) map {
case (f, s) => (f, s"$topDirName${File.separator}$s")
}
// Common Language Support Proto Dependencies
IO.zip(
archiveStructure(cloudstateProtocolsName,
(base / "frontend" ** "*.proto" +++
base / "protocol" ** "*.proto" +++
base / "proxy" ** "*.proto")),
cloudstateProtos
)
// Common TCK Language Support Proto Dependencies
IO.zip(archiveStructure(cloudstateTCKProtocolsName, base / "example" ** "*.proto"), cloudstateTCKProtos)
cloudstateProtos
},
cleanFiles ++= Seq(
baseDirectory.value / s"$cloudstateProtocolsName.zip",
baseDirectory.value / s"$cloudstateTCKProtocolsName.zip"
)
)
lazy val docs = (project in file("docs"))
.enablePlugins(ParadoxPlugin, ProtocPlugin)
.dependsOn(`java-support` % Test)
.settings(
common,
name := "Cloudstate Documentation",
paradoxTheme := Some(builtinParadoxTheme("generic")),
mappings in (Compile, paradox) ++= {
val javaApiDocs = (doc in (`java-support`, Compile)).value
// Run the npm docs build
val nodeSupportDir = (baseDirectory in ThisBuild).value / "node-support"
import sys.process._
val rc = Process("npm run jsdoc", nodeSupportDir).run(streams.value.log).exitValue()
if (rc != 0) sys.error(s"jsdoc failed with return code $rc")
val javaScriptApiDocs = nodeSupportDir / "apidocs"
((javaApiDocs ** "*") pair Path.relativeTo(javaApiDocs)).map {
case (file, path) => file -> s"user/lang/java/api/$path"
} ++
((javaScriptApiDocs ** "*") pair Path.relativeTo(javaScriptApiDocs)).map {
case (file, path) => file -> s"user/lang/javascript/api/$path"
}
},
paradoxProperties in Compile ++= Map(
"canonical.base_url" -> "https://cloudstate.io/docs/",
"javadoc.io.cloudstate.javasupport.base_url" -> ".../user/lang/java/api/",
"javadoc.link_style" -> "direct",
"extref.jsdoc.base_url" -> ".../user/lang/javascript/api/module-cloudstate.%s",
"cloudstate.version" -> "0.4.3", // hardcode, otherwise we'll end up with the wrong version in the docs
"cloudstate.java-support.version" -> "0.4.3",
"cloudstate.node-support.version" -> "0.0.1",
"cloudstate.go-support.version" -> "0.1.0",
"cloudstate.go.version" -> "1.13",
"cloudstate.kotlin-support.version" -> "0.4.3"
),
paradoxNavigationDepth := 3,
inConfig(Test)(
sbtprotoc.ProtocPlugin.protobufConfigSettings ++ Seq(
PB.protoSources += sourceDirectory.value / "proto",
PB.targets += PB.gens.java -> sourceManaged.value
)
)
)
lazy val proxyDockerBuild = settingKey[Option[(String, Option[String])]](
"Docker artifact name and configuration file which gets overridden by the buildProxy command"
)
def dockerSettings: Seq[Setting[_]] = Seq(
proxyDockerBuild := None,
dockerUpdateLatest := true,
dockerRepository := sys.props.get("docker.registry"),
dockerUsername := sys.props.get("docker.username").orElse(Some("cloudstateio")).filter(_ != ""),
dockerBaseImage := DockerBaseImageVersion,
// when using tags like latest, uncomment below line, so that local cache will not be used.
// dockerBuildOptions += "--no-cache",
dockerAlias := {
val old = dockerAlias.value
proxyDockerBuild.value match {
case Some((dockerName, _)) => old.withName(dockerName)
case None => old
}
},
dockerAliases := {
val old = dockerAliases.value
val single = dockerAlias.value
// If a tag is explicitly configured, publish that, otherwise if it's a snapshot, just publish latest, otherwise,
// publish both latest and the version
sys.props.get("docker.tag") match {
case some @ Some(_) => Seq(single.withTag(some))
case _ if isSnapshot.value => Seq(single.withTag(Some("latest")))
case _ => old
}
},
// For projects that we publish using Docker, disable the generation of java/scaladocs
publishArtifact in (Compile, packageDoc) := false
)
def buildProxyHelp(commandName: String, name: String) =
Help(
(s"$commandName <task>",
s"Execute the given docker scoped task (eg, publishLocal or publish) for the $name build of the proxy.")
)
def buildProxyCommand(commandName: String,
project: => Project,
name: String,
configResource: Option[String],
native: Boolean): Command = {
val cn =
if (native) s"dockerBuildNative$commandName"
else s"dockerBuild$commandName"
val imageName =
if (native) s"native-$name"
else name
val configResourceSetting = configResource match {
case Some(resource) => "Some(\"" + resource + "\")"
case None => "None"
}
Command.single(
cn,
buildProxyHelp(cn, name)
) { (state, command) =>
List(
s"""set proxyDockerBuild in `${project.id}` := Some(("cloudstate-proxy-$imageName", $configResourceSetting))""",
s"""set graalVMDockerPublishLocalBuild in ThisBuild := $native""",
s"${project.id}/docker:$command",
s"set proxyDockerBuild in `${project.id}` := None"
) ::: state
}
}
commands ++= Seq(
buildProxyCommand("DevMode", `proxy-core`, "dev-mode", Some("dev-mode.conf"), true),
buildProxyCommand("DevMode", `proxy-core`, "dev-mode", Some("dev-mode.conf"), false),
buildProxyCommand("NoStore", `proxy-core`, "no-store", Some("no-store.conf"), true),
buildProxyCommand("NoStore", `proxy-core`, "no-store", Some("no-store.conf"), false),
buildProxyCommand("InMemory", `proxy-core`, "in-memory", Some("in-memory.conf"), true),
buildProxyCommand("InMemory", `proxy-core`, "in-memory", Some("in-memory.conf"), false),
buildProxyCommand("Cassandra", `proxy-cassandra`, "cassandra", None, true),
buildProxyCommand("Cassandra", `proxy-cassandra`, "cassandra", None, false),
buildProxyCommand("Postgres", `proxy-postgres`, "postgres", None, true),
buildProxyCommand("Postgres", `proxy-postgres`, "postgres", None, false),
Command.single("dockerBuildAllNonNative", buildProxyHelp("dockerBuildAllNonNative", "all non native")) {
(state, command) =>
List("DevMode", "NoStore", "InMemory", "Cassandra", "Postgres")
.map(c => s"dockerBuild$c $command") ::: state
},
Command.single("dockerBuildAllNative", buildProxyHelp("dockerBuildAllNative", "all native")) { (state, command) =>
List("DevMode", "NoStore", "InMemory", "Cassandra", "Postgres")
.map(c => s"dockerBuildNative$c $command") ::: state
}
)
// Shared settings for native image and docker builds
def nativeImageDockerSettings: Seq[Setting[_]] = dockerSettings ++ Seq(
// If this is Some(…): run the native-image generation inside a Docker image
// If this is None: run the native-image generation using a local GraalVM installation
graalVMVersion := Some(GraalVersion),
graalVMNativeImageOptions ++= sharedNativeImageSettings({
graalVMVersion.value match {
case Some(_) => new File("/opt/docker/graal-resources/")
case None => baseDirectory.value / "src" / "graal"
}
}),
dockerEntrypoint := {
val old = dockerEntrypoint.value
val withLibraryPath = if (graalVMDockerPublishLocalBuild.value) {
old :+ s"-Djava.library.path=${DockerBaseImageJavaLibraryPath}"
} else old
proxyDockerBuild.value match {
case Some((_, Some(configResource))) => withLibraryPath :+ s"-Dconfig.resource=$configResource"
case _ => withLibraryPath
}
}
)
def sharedNativeImageSettings(targetDir: File) = Seq(
//"-O1", // Optimization level
"-H:ResourceConfigurationFiles=" + targetDir / "resource-config.json",
"-H:ReflectionConfigurationFiles=" + targetDir / "reflect-config.json",
"-H:DynamicProxyConfigurationFiles=" + targetDir / "proxy-config.json",
"-H:IncludeResources=.+\\.conf",
"-H:IncludeResources=.+\\.properties",
"-H:+AllowVMInspection",
"-H:-RuntimeAssertions",
"-H:+ReportExceptionStackTraces",
"-H:-PrintUniverse", // if "+" prints out all classes which are included
"-H:-NativeArchitecture", // if "+" Compiles the native image to customize to the local CPU arch
"-H:Class=" + "io.cloudstate.proxy.CloudStateProxyMain",
//"-J-Xmx10g", // native-image is hungry FIXME I don't believe this is properly applied even when --no-server is enabled!
//"--no-server", // Uncomment to not use the native-image build server, to avoid potential cache problems with builds
//"--debug-attach=5005", // Debugger makes a ton of sense to use to debug SubstrateVM
"--verbose",
"--report-unsupported-elements-at-runtime", // Hopefully a self-explanatory flag FIXME comment this option out once AffinityPool is gone
"--enable-url-protocols=http,https",
"--allow-incomplete-classpath",
"--no-fallback",
"--initialize-at-build-time"
+ Seq(
"org.slf4j",
"scala",
"akka.dispatch.affinity",
"akka.util",
"com.google.Protobuf",
"com.typesafe.config",
"java.lang.ref.SoftReference", // https://github.com/oracle/graal/issues/2345
"java.lang.invoke.MethodHandleImpl" // https://github.com/oracle/graal/issues/2345
).mkString("=", ",", ""),
"-H:ClassInitialization=com.typesafe.config.impl.ConfigImpl$EnvVariablesHolder:rerun",
"-H:ClassInitialization=com.typesafe.config.impl.ConfigImpl$SystemPropertiesHolder:rerun",
"-H:ClassInitialization=com.typesafe.config.impl.ConfigImpl$LoaderCacheHolder:rerun",
"--initialize-at-run-time" +
Seq(
// These are to make up for the lack of shaded configuration for svm/native-image in grpc-netty-shaded
"com.sun.jndi.dns.DnsClient",
"io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2CodecUtil",
"io.grpc.netty.shaded.io.netty.handler.codec.http2.DefaultHttp2FrameWriter",
"io.grpc.netty.shaded.io.netty.handler.codec.http.HttpObjectEncoder",
"io.grpc.netty.shaded.io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder",
"io.grpc.netty.shaded.io.netty.handler.ssl.util.ThreadLocalInsecureRandom",
"io.grpc.netty.shaded.io.netty.handler.ssl.ConscryptAlpnSslEngine",
"io.grpc.netty.shaded.io.netty.handler.ssl.JettyNpnSslEngine",
"io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine",
"io.grpc.netty.shaded.io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator",
"io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslServerContext",
"io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslClientContext",
"io.grpc.netty.shaded.io.netty.handler.ssl.util.BouncyCastleSelfSignedCertGenerator",
"io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslContext",
"io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel"
).mkString("=", ",", "")
)
lazy val `proxy-core` = (project in file("proxy/core"))
.enablePlugins(DockerPlugin, AkkaGrpcPlugin, JavaAgent, AssemblyPlugin, GraalVMPlugin, BuildInfoPlugin)
.dependsOn(`graal-tools` % Provided) // Only needed for compilation
.settings(
common,
name := "cloudstate-proxy-core",
buildInfoKeys := Seq[BuildInfoKey](name, version),
buildInfoPackage := "io.cloudstate.proxy",
libraryDependencies ++= Seq(
// Remove these explicit gRPC/netty dependencies once akka-grpc 0.7.1 is released and we've upgraded to using that
"io.grpc" % "grpc-core" % GrpcJavaVersion,
"io.grpc" % "grpc-netty-shaded" % GrpcJavaVersion,
// Since we exclude Aeron, we also exclude its transitive Agrona dependency, so we need to manually add it HERE
"org.agrona" % "agrona" % "0.9.29",
"com.typesafe.akka" %% "akka-remote" % AkkaVersion excludeAll (excludeTheseDependencies: _*),
// For Eventing support of Google Pubsub
"com.google.api.grpc" % "grpc-google-cloud-pubsub-v1" % "0.12.0" % "protobuf", // ApacheV2
"io.grpc" % "grpc-auth" % GrpcJavaVersion, // ApacheV2
"com.google.auth" % "google-auth-library-oauth2-http" % "0.15.0", // BSD 3-clause
"com.typesafe.akka" %% "akka-persistence" % AkkaVersion,
"com.typesafe.akka" %% "akka-persistence-query" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-cluster-sharding" % AkkaVersion excludeAll ((excludeTheseDependencies :+ ExclusionRule(
"org.lmdbjava",
"lmdbjava"
)): _*),
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion excludeAll (excludeTheseDependencies: _*),
"com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % AkkaManagementVersion excludeAll (excludeTheseDependencies: _*),
"com.google.protobuf" % "protobuf-java" % ProtobufVersion % "protobuf",
"com.google.protobuf" % "protobuf-java-util" % ProtobufVersion,
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion % Test,
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"io.prometheus" % "simpleclient" % PrometheusClientVersion,
"io.prometheus" % "simpleclient_common" % PrometheusClientVersion,
"org.slf4j" % "slf4j-simple" % "1.7.26"
//"ch.qos.logback" % "logback-classic" % "1.2.3", // Doesn't work well with SubstrateVM: https://github.com/vmencik/akka-graal-native/blob/master/README.md#logging
),
// Work around for https://github.com/akka/akka-grpc/pull/673
(PB.targets in Compile) := {
val old = (PB.targets in Compile).value
val ct = crossTarget.value
old.map(_.copy(outputPath = ct / "akka-grpc" / "main"))
},
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "proxy", baseDir / "frontend", baseDir / "protocol")
},
PB.protoSources in Test ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "frontend")
},
// For Google Cloud Pubsub API
PB.protoSources in Compile += target.value / "protobuf_external" / "google" / "pubsub" / "v1",
javaAgents += "org.mortbay.jetty.alpn" % "jetty-alpn-agent" % "2.0.9" % "runtime;test",
dockerSettings,
fork in run := true,
// In memory journal by default
javaOptions in run ++= Seq("-Dconfig.resource=dev-mode.conf"),
mainClass in assembly := Some("io.cloudstate.proxy.CloudStateProxyMain"),
assemblyJarName in assembly := "akka-proxy.jar",
test in assembly := {},
// logLevel in assembly := Level.Debug,
assemblyMergeStrategy in assembly := {
/*ADD CUSTOMIZATIONS HERE*/
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
},
nativeImageDockerSettings
)
lazy val `proxy-cassandra` = (project in file("proxy/cassandra"))
.enablePlugins(DockerPlugin, JavaAgent, GraalVMPlugin)
.dependsOn(`proxy-core`)
.settings(
common,
name := "cloudstate-proxy-cassandra",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-persistence-cassandra" % AkkaPersistenceCassandraVersion excludeAll (
(excludeTheseDependencies :+ ExclusionRule("com.github.jnr")): _* // Can't native-image this, so we don't need this either
),
"com.typesafe.akka" %% "akka-persistence-cassandra-launcher" % AkkaPersistenceCassandraVersion % Test
),
fork in run := true,
mainClass in Compile := Some("io.cloudstate.proxy.CloudStateProxyMain"),
nativeImageDockerSettings,
graalVMNativeImageOptions ++= Seq(
"-H:IncludeResourceBundles=com.datastax.driver.core.Driver"
)
)
lazy val `proxy-jdbc` = (project in file("proxy/jdbc"))
.dependsOn(`proxy-core`)
.settings(
common,
name := "cloudstate-proxy-jdbc",
libraryDependencies ++= Seq(
"com.github.dnvriend" %% "akka-persistence-jdbc" % "3.5.2"
),
fork in run := true,
mainClass in Compile := Some("io.cloudstate.proxy.CloudStateProxyMain")
)
lazy val `proxy-postgres` = (project in file("proxy/postgres"))
.enablePlugins(DockerPlugin, JavaAgent, GraalVMPlugin, AssemblyPlugin)
.dependsOn(`proxy-jdbc`)
.settings(
common,
name := "cloudstate-proxy-postgres",
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "42.2.6"
),
fork in run := true,
mainClass in Compile := Some("io.cloudstate.proxy.jdbc.CloudStateJdbcProxyMain"),
// If run by sbt, run in dev mode
javaOptions in run += "-Dcloudstate.proxy.dev-mode-enabled=true",
mainClass in assembly := (mainClass in Compile).value,
assemblyJarName in assembly := "akka-proxy-postgres.jar",
test in assembly := {},
// logLevel in assembly := Level.Debug,
assemblyMergeStrategy in assembly := {
/*ADD CUSTOMIZATIONS HERE*/
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
},
nativeImageDockerSettings,
graalVMNativeImageOptions ++= Seq(
"--initialize-at-build-time"
+ Seq(
"org.postgresql.Driver",
"org.postgresql.util.SharedTimer"
).mkString("=", ",", "")
)
)
lazy val `proxy-tests` = (project in file("proxy/proxy-tests"))
.dependsOn(`proxy-core`, `akka-client`, `java-pingpong`)
.settings(
common,
name := "cloudstate-proxy-tests",
fork in Test := System.getProperty("RUN_STRESS_TESTS", "false") == "true",
parallelExecution in Test := false,
baseDirectory in Test := (baseDirectory in ThisBuild).value,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % AkkaVersion % Test
)
)
val compileK8sDescriptors = taskKey[File]("Compile the K8s descriptors into one")
lazy val operator = (project in file("operator"))
.enablePlugins(JavaAppPackaging, DockerPlugin)
.settings(
common,
name := "cloudstate-operator",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"io.skuber" %% "skuber" % "2.4.0",
"ch.qos.logback" % "logback-classic" % "1.2.3" // Doesn't work well with SubstrateVM, use "org.slf4j" % "slf4j-simple" % "1.7.26" instead
),
dockerSettings,
dockerExposedPorts := Nil,
compileK8sDescriptors := {
val tag = version.value
doCompileK8sDescriptors(
baseDirectory.value / "deploy",
baseDirectory.value,
dockerRepository.value,
dockerUsername.value,
sys.props.get("docker.tag").getOrElse { if (isSnapshot.value) "latest" else tag },
streams.value
)
}
)
lazy val `java-support` = (project in file("java-support"))
.enablePlugins(AkkaGrpcPlugin, BuildInfoPlugin)
.settings(
name := "cloudstate-java-support",
common,
crossPaths := false,
publishMavenStyle := true,
publishTo := sonatypePublishTo.value,
buildInfoKeys := Seq[BuildInfoKey](name, version),
buildInfoPackage := "io.cloudstate.javasupport",
// Generate javadocs by just including non generated Java sources
sourceDirectories in (Compile, doc) := Seq((javaSource in Compile).value),
sources in (Compile, doc) := {
val javaSourceDir = (javaSource in Compile).value.getAbsolutePath
(sources in (Compile, doc)).value.filter(_.getAbsolutePath.startsWith(javaSourceDir))
},
// javadoc (I think java 9 onwards) refuses to compile javadocs if it can't compile the entire source path.
// but since we have java files depending on Scala files, we need to include ourselves on the classpath.
dependencyClasspath in (Compile, doc) := (fullClasspath in Compile).value,
javacOptions in (Compile, doc) ++= Seq(
"-overview",
((javaSource in Compile).value / "overview.html").getAbsolutePath,
"-notimestamp",
"-doctitle",
"Cloudstate Java Support"
),
libraryDependencies ++= Seq(
// Remove these explicit gRPC/netty dependencies once akka-grpc 0.7.1 is released and we've upgraded to using that
"io.grpc" % "grpc-core" % GrpcJavaVersion,
"io.grpc" % "grpc-netty-shaded" % GrpcJavaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,
"com.google.protobuf" % "protobuf-java" % ProtobufVersion % "protobuf",
"com.google.protobuf" % "protobuf-java-util" % ProtobufVersion,
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion % Test,
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"org.slf4j" % "slf4j-simple" % "1.7.26",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.9.3"
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8"),
javacOptions in (Compile, compile) ++= Seq("-source", "1.8", "-target", "1.8"),
akkaGrpcGeneratedSources in Compile := Seq(AkkaGrpc.Server),
akkaGrpcGeneratedLanguages in Compile := Seq(AkkaGrpc.Scala), // FIXME should be Java, but here be dragons
// Work around for https://github.com/akka/akka-grpc/pull/673
(PB.targets in Compile) := {
val old = (PB.targets in Compile).value
val ct = crossTarget.value
old.map(_.copy(outputPath = ct / "akka-grpc" / "main"))
},
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "protocol", baseDir / "frontend")
},
// We need to generate the java files for things like entity_key.proto so that downstream libraries can use them
// without needing to generate them themselves
PB.targets in Compile += PB.gens.java -> crossTarget.value / "akka-grpc" / "main",
inConfig(Test)(
sbtprotoc.ProtocPlugin.protobufConfigSettings ++ Seq(
PB.protoSources ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "example")
},
PB.targets := Seq(
PB.gens.java -> crossTarget.value / "akka-grpc" / "test"
)
)
)
)
lazy val `scala-support` = (project in file("scala-support"))
.enablePlugins(AkkaGrpcPlugin, BuildInfoPlugin)
.settings(
name := "cloudstate-scala-support",
common,
crossPaths := false,
publishMavenStyle := true,
publishTo := sonatypePublishTo.value,
buildInfoKeys := Seq[BuildInfoKey](name, version),
buildInfoPackage := "io.cloudstate.scalasupport",
// Generate javadocs by just including non generated Java sources
sourceDirectories in (Compile, doc) := Seq((javaSource in Compile).value),
sources in (Compile, doc) := {
val javaSourceDir = (javaSource in Compile).value.getAbsolutePath
(sources in (Compile, doc)).value.filter(_.getAbsolutePath.startsWith(javaSourceDir))
},
// javadoc (I think java 9 onwards) refuses to compile javadocs if it can't compile the entire source path.
// but since we have java files depending on Scala files, we need to include ourselves on the classpath.
dependencyClasspath in (Compile, doc) := (fullClasspath in Compile).value,
javacOptions in (Compile, doc) ++= Seq(
"-overview",
((javaSource in Compile).value / "overview.html").getAbsolutePath,
"-notimestamp",
"-doctitle",
"CloudState Scala Support"
),
libraryDependencies ++= Seq(
// Remove these explicit gRPC/netty dependencies once akka-grpc 0.7.1 is released and we've upgraded to using that
"io.grpc" % "grpc-core" % GrpcJavaVersion,
"io.grpc" % "grpc-netty-shaded" % GrpcJavaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,
"com.google.protobuf" % "protobuf-java" % ProtobufVersion % "protobuf",
"com.google.protobuf" % "protobuf-java-util" % ProtobufVersion,
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion % Test,
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"org.slf4j" % "slf4j-simple" % "1.7.26",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.9.3"
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8"),
akkaGrpcGeneratedSources in Compile := Seq(AkkaGrpc.Server),
akkaGrpcGeneratedLanguages in Compile := Seq(AkkaGrpc.Scala), // FIXME should be Java, but here be dragons
// Work around for https://github.com/akka/akka-grpc/pull/673
(PB.targets in Compile) := {
val old = (PB.targets in Compile).value
val ct = crossTarget.value
old.map(_.copy(outputPath = ct / "akka-grpc" / "main"))
},
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "protocol", baseDir / "frontend")
}
)
lazy val `java-shopping-cart` = (project in file("samples/java-shopping-cart"))
.dependsOn(`java-support`)
.enablePlugins(AkkaGrpcPlugin, AssemblyPlugin, JavaAppPackaging, DockerPlugin)
.settings(
name := "java-shopping-cart",
dockerSettings,
mainClass in Compile := Some("io.cloudstate.samples.shoppingcart.Main"),
PB.generate in Compile := (PB.generate in Compile).dependsOn(PB.generate in (`java-support`, Compile)).value,
akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java),
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "frontend", baseDir / "example")
},
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8"),
mainClass in assembly := (mainClass in Compile).value,
assemblyJarName in assembly := "java-shopping-cart.jar",
test in assembly := {},
// logLevel in assembly := Level.Debug,
assemblyMergeStrategy in assembly := {
/*ADD CUSTOMIZATIONS HERE*/
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
lazy val `java-pingpong` = (project in file("samples/java-pingpong"))
.dependsOn(`java-support`)
.enablePlugins(AkkaGrpcPlugin, AssemblyPlugin, JavaAppPackaging, DockerPlugin)
.settings(
name := "java-pingpong",
dockerSettings,
mainClass in Compile := Some("io.cloudstate.samples.pingpong.Main"),
PB.generate in Compile := (PB.generate in Compile).dependsOn(PB.generate in (`java-support`, Compile)).value,
akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java),
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "frontend", (sourceDirectory in Compile).value / "protos")
},
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8"),
mainClass in assembly := (mainClass in Compile).value,
assemblyJarName in assembly := "java-pingpong.jar",
test in assembly := {},
// logLevel in assembly := Level.Debug,
assemblyMergeStrategy in assembly := {
/*ADD CUSTOMIZATIONS HERE*/
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
lazy val `scala-shopping-cart` = (project in file("samples/scala-shopping-cart"))
.dependsOn(`scala-support`)
.enablePlugins(AkkaGrpcPlugin, DockerPlugin, JavaAppPackaging)
.settings(
name := "scala-shopping-cart",
dockerSettings,
PB.generate in Compile := (PB.generate in Compile).dependsOn(PB.generate in (`scala-support`, Compile)).value,
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "frontend", baseDir / "example")
},
mainClass in assembly := Some("io.cloudstate.samples.shoppingcart.Main"),
assemblyJarName in assembly := "scala-shopping-cart.jar",
test in assembly := {},
// logLevel in assembly := Level.Debug,
assemblyMergeStrategy in assembly := {
/*ADD CUSTOMIZATIONS HERE*/
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.last
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
lazy val `akka-client` = (project in file("samples/akka-client"))
.enablePlugins(AkkaGrpcPlugin)
.settings(
common,
name := "akka-client",
fork in run := true,
libraryDependencies ++= Seq(
// Remove these explicit gRPC/netty dependencies once akka-grpc 0.7.1 is released and we've upgraded to using that
"io.grpc" % "grpc-netty-shaded" % GrpcJavaVersion,
"io.grpc" % "grpc-core" % GrpcJavaVersion,
"com.typesafe.akka" %% "akka-persistence" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,
"com.google.protobuf" % "protobuf-java" % ProtobufVersion % "protobuf",
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
),
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "frontend", baseDir / "example")
}
)
lazy val `load-generator` = (project in file("samples/js-shopping-cart-load-generator"))
.enablePlugins(JavaAppPackaging, DockerPlugin)
.dependsOn(`akka-client`)
.settings(
common,
name := "js-shopping-cart-load-generator",
dockerSettings,
dockerExposedPorts := Nil
)
lazy val `tck` = (project in file("tck"))
.enablePlugins(AkkaGrpcPlugin)
.configs(IntegrationTest)
.dependsOn(`akka-client`)
.settings(
Defaults.itSettings,
common,
name := "tck",
libraryDependencies ++= Seq(
// Remove these explicit gRPC/netty dependencies once akka-grpc 0.7.1 is released and we've upgraded to using that
"io.grpc" % "grpc-netty-shaded" % GrpcJavaVersion,
"io.grpc" % "grpc-core" % GrpcJavaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.google.protobuf" % "protobuf-java" % ProtobufVersion % "protobuf",
"org.scalatest" %% "scalatest" % ScalaTestVersion,
"com.typesafe.akka" %% "akka-testkit" % AkkaVersion
),
PB.protoSources in Compile ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "proxy", baseDir / "protocol")
},
javaOptions in IntegrationTest := sys.props.get("config.resource").map(r => s"-Dconfig.resource=$r").toSeq,
parallelExecution in IntegrationTest := false,
executeTests in IntegrationTest := (executeTests in IntegrationTest)
.dependsOn(`proxy-core` / assembly, `java-shopping-cart` / assembly, `scala-shopping-cart` / assembly)
.value
)
lazy val `graal-tools` = (project in file("graal-tools"))
.enablePlugins(GraalVMPlugin)
.settings(
libraryDependencies ++= List(
"org.graalvm.nativeimage" % "svm" % GraalVersion,
// Adds configuration to let Graal Native Image (SubstrateVM) work
"com.github.vmencik" %% "graal-akka-actor" % GraalAkkaVersion,
"com.github.vmencik" %% "graal-akka-stream" % GraalAkkaVersion,
"com.github.vmencik" %% "graal-akka-http" % GraalAkkaVersion,
"com.typesafe.akka" %% "akka-actor" % AkkaVersion,
"com.typesafe.akka" %% "akka-protobuf" % AkkaVersion,
"com.google.protobuf" % "protobuf-java" % ProtobufVersion,
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion
)
)
def doCompileK8sDescriptors(dir: File,
targetDir: File,
registry: Option[String],
username: Option[String],
tag: String,
streams: TaskStreams): File = {
val targetFileName = if (tag != "latest") s"cloudstate-$tag.yaml" else "cloudstate.yaml"
val target = targetDir / targetFileName
val useNativeBuilds = sys.props.get("use.native.builds").forall(_ == "true")
val files = ((dir / "crds") * "*.yaml").get ++
(dir * "*.yaml").get.sortBy(_.getName)
val fullDescriptor = files.map(IO.read(_)).mkString("\n---\n")
val registryAndUsername = (registry.toSeq ++ username :+ "").mkString("/")
val substitutedDescriptor = "cloudstateio/(cloudstate-.*):latest".r.replaceAllIn(fullDescriptor, m => {
val artifact =
if (useNativeBuilds) m.group(1)
else m.group(1).replace("-native", "")
s"$registryAndUsername$artifact:$tag"
})
IO.write(target, substitutedDescriptor)
streams.log.info("Generated YAML descriptor in " + target)
target
}