Skip to content

Commit

Permalink
feat: Native-image support (#1131)
Browse files Browse the repository at this point in the history
* Native image as needed for projection modules out of the box
* No user metadata needed for local-drone-control native image builds
* Bump Akka, Akka HTTP, Akka gRPC, Akka Management to native-image-out-of-the-box versions
* Actual runtime native-image CI tests for the Scala sample

---------
Co-authored-by: Peter Vlugter <59895+pvlugter@users.noreply.github.com>
  • Loading branch information
johanandren authored Mar 11, 2024
1 parent aa6f961 commit 7f8e17c
Show file tree
Hide file tree
Showing 40 changed files with 214 additions and 14,365 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ jobs:
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43

- name: Gather version
# some cleanup of the sbt output to get the version sbt will use when publishing below
run: |-
echo `git describe --tags | sed -e "s/v\(.*\)-\([0-9][0-9]*\).*/\\1-\\2-/"``git rev-parse HEAD | head -c8`-SNAPSHOT > ~/.version
cat ~/.version
sbt --no-colors "print akka-projection-core/version" | tail -n 1 | tr -d '\n' > ~/.version
echo [$(cat ~/.version)]
# useful for debugging: hexdump -c ~/.version
- name: Publish artifacts locally
run: |-
Expand Down Expand Up @@ -242,20 +244,26 @@ jobs:
# RES sample should be identical
diff samples/grpc/local-drone-control-scala/src/main/scala/charging/ChargingStation.scala samples/grpc/restaurant-drone-deliveries-service-scala/src/main/scala/charging/ChargingStation.scala
- name: Set up GraalVM 17
- name: Local drone control sample Scala native image build
run: |-
cd samples/grpc/local-drone-control-scala
sbt nativeImage -Dnative.mode=clustered -Dakka-projection.version=`cat ~/.version`
sbt nativeImage -Dakka-projection.version=`cat ~/.version`
# This will likely be quite noisy, logging failures to connect to restaurant-drone-deliveries service
target/native-image/local-drone-control &
DRONE_CONTROL_PID=$!
sbt "Test/runMain drones.DroneClientTestApp 127.0.0.1 8080" -Dakka-projection.version=`cat ~/.version`
kill -9 $DRONE_CONTROL_PID
- name: Set up GraalVM 21
# https://github.com/coursier/setup-action/releases
# v1.3.4
uses: coursier/setup-action@48280172a2c999022e42527711d6b28e4945e6f0
with:
jvm: graalvm-community:17.0.8

- name: Local drone control sample Scala native image build
run: |-
cd samples/grpc/local-drone-control-scala
# note the trixery ot re-use graal from path instead of resolving itself (which fails)
sbt "set nativeImageGraalHome := file(\"$JAVA_HOME\").toPath; nativeImage;" -Dakka-projection.version=`cat ~/.version`
jvm: graalvm-community:21.0.2

- name: Local drone control sample Java native image build
run: |-
cd samples/grpc/local-drone-control-java
mvn -DskipTests=true -Pnative package -nsu -Dakka-projection.version=`cat ~/.version`
mvn -DskipTests=true -Pnative -Pclustered package -nsu -Dakka-projection.version=`cat ~/.version`
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "akka.projection.internal.ProjectionSerializer",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"akka.actor.ExtendedActorSystem"
]
}
]
},
{
"name": "akka.projection.ProjectionBehavior$Internal$ProjectionManagementCommand"
},
{
"name": "akka.projection.ProjectionBehavior$Internal$CurrentOffset"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait TestDbLifecycle extends BeforeAndAfterAll { this: Suite =>
R2dbcProjectionSettings(sys.settings.config.getConfig(testConfigPath))
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
_.createStatement(s"delete from ${r2dbcSettings.journalTableWithSchema}")),
_.createStatement(s"delete from ${r2dbcSettings.journalTableWithSchema(0)}")),
10.seconds)
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class EventProducerPushSpec(testContainerConf: TestContainerConf)
R2dbcSettings(typedSystem.settings.config.getConfig("test.consumer.r2dbc"))
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
_.createStatement(s"delete from ${consumerSettings.journalTableWithSchema}")),
_.createStatement(s"delete from ${consumerSettings.journalTableWithSchema(0)}")),
10.seconds)
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static Replication<MyCommand> init(ActorSystem<?> system) {
}
}

@SuppressWarnings("deprecation")
public static void multiEventProducers(ActorSystem<?> system, ReplicationSettings<MyCommand> settings, String host, int port) {

Replication<Void> otherReplication = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "akka.projection.grpc.internal.ConsumerSerializer",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"akka.actor.ExtendedActorSystem"
]
}
]
},
{
"condition": {
"typeReachable": "akka.cluster.ddata.typed.scaladsl.DistributedData"
},
"name": "akka.projection.grpc.internal.DdataConsumerFilterStore$",
"fields": [
{
"name": "MODULE$"
}
]
},
{
"condition": {
"typeReachable": "akka.cluster.ddata.typed.scaladsl.DistributedData"
},
"name": "akka.projection.grpc.internal.DdataConsumerFilterStore$",
"methods": [
{
"name": "apply",
"parameterTypes": [
"akka.projection.grpc.consumer.ConsumerFilter$ConsumerFilterSettings",
"java.lang.String",
"akka.actor.typed.ActorRef"
]
}
]
},
{
"condition": {
"typeReachable": "akka.cluster.ddata.typed.scaladsl.DistributedData"
},
"name": "akka.projection.grpc.internal.DdataConsumerFilterStore$State"
},
{
"condition": {
"typeReachable": "akka.cluster.ddata.typed.scaladsl.DistributedData"
},
"name": "akka.projection.grpc.internal.DdataConsumerFilterStore$ConsumerFilterKey"
},
{
"condition": {
"typeReachable": "akka.cluster.ddata.typed.scaladsl.DistributedData"
},
"name": "akka.cluster.ddata.typed.scaladsl.DistributedData"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class EventSourcedEndToEndSpec
private def writeEvent(persistenceId: String, seqNr: Long, timestamp: Instant, event: String): Unit = {
log.debugN("Write test event [{}] [{}] [{}] at time [{}]", persistenceId, seqNr, event, timestamp)
val insertEventSql = sql"""
INSERT INTO ${journalSettings.journalTableWithSchema}
INSERT INTO ${journalSettings.journalTableWithSchema(0)}
(slice, entity_type, persistence_id, seq_nr, db_timestamp, writer, adapter_manifest, event_ser_id, event_ser_manifest, event_payload)
VALUES (?, ?, ?, ?, ?, '', '', ?, '', ?)"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ trait TestDbLifecycle extends BeforeAndAfterAll { this: Suite =>
try {
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
_.createStatement(s"delete from ${r2dbcSettings.journalTableWithSchema}")),
_.createStatement(s"delete from ${r2dbcSettings.journalTableWithSchema(0)}")),
10.seconds)
Await.result(
r2dbcExecutor.updateOne("beforeAll delete")(
_.createStatement(s"delete from ${r2dbcSettings.durableStateTableWithSchema}")),
_.createStatement(s"delete from ${r2dbcSettings.durableStateTableWithSchema(0)}")),
10.seconds)
if (r2dbcProjectionSettings.isOffsetTableDefined) {
Await.result(
Expand Down
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ object Dependencies {
val AkkaProjectionVersionInDocs = "1.5"

object Versions {
val akka = sys.props.getOrElse("build.akka.version", "2.9.1")
val akka = sys.props.getOrElse("build.akka.version", "2.9.2")
val akkaPersistenceCassandra = "1.2.0"
val akkaPersistenceJdbc = "5.3.0"
val akkaPersistenceR2dbc = "1.2.1"
val akkaPersistenceR2dbc = "1.2.3"
val alpakka = "7.0.0"
val alpakkaKafka = sys.props.getOrElse("build.alpakka.kafka.version", "5.0.0")
val slick = "3.4.1"
val scalaTest = "3.2.18"
val testContainers = "1.19.3"
val junit = "4.13.2"
val jacksonDatabind = "2.15.2" // this should match the version of jackson used by akka-serialization-jackson
val jacksonDatabind = "2.15.4" // this should match the version of jackson used by akka-serialization-jackson
}

object Compile {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")

// remember to bump in samples/grpc/ projects as well if changing
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.4.0")
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.4.1")

// Documentation
addSbtPlugin("com.lightbend.akka" % "sbt-paradox-akka" % "0.54")
Expand Down
10 changes: 5 additions & 5 deletions samples/grpc/iot-service-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<akka.version>2.9.1</akka.version>
<akka.version>2.9.2</akka.version>
<akka-projection.version>1.5.2</akka-projection.version>
<akka-persistence-r2dbc.version>1.2.2</akka-persistence-r2dbc.version>
<akka-management.version>1.5.0</akka-management.version>
<akka-persistence-r2dbc.version>1.2.3</akka-persistence-r2dbc.version>
<akka-management.version>1.5.1</akka-management.version>
<akka-diagnostics.version>2.1.0</akka-diagnostics.version>
<akka-grpc.version>2.4.0</akka-grpc.version>
<akka-grpc-maven-plugin.version>2.4.0</akka-grpc-maven-plugin.version>
<akka-grpc.version>2.4.1</akka-grpc.version>
<akka-grpc-maven-plugin.version>2.4.1</akka-grpc-maven-plugin.version>
<logback.version>1.3.6</logback.version>
<junit.version>4.13.1</junit.version>
<scala.binary.version>2.13</scala.binary.version>
Expand Down
8 changes: 4 additions & 4 deletions samples/grpc/iot-service-scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ run / javaOptions ++= sys.props
.fold(Seq.empty[String])(res => Seq(s"-Dconfig.resource=$res"))
Global / cancelable := false // ctrl-c

val AkkaVersion = "2.9.1"
val AkkaHttpVersion = "10.6.0"
val AkkaManagementVersion = "1.5.0"
val AkkaPersistenceR2dbcVersion = "1.2.2"
val AkkaVersion = "2.9.2"
val AkkaHttpVersion = "10.6.1"
val AkkaManagementVersion = "1.5.1"
val AkkaPersistenceR2dbcVersion = "1.2.3"
val AkkaProjectionVersion =
sys.props.getOrElse("akka-projection.version", "1.5.2")
val AkkaDiagnosticsVersion = "2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion samples/grpc/iot-service-scala/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resolvers += "Akka library repository".at("https://repo.akka.io/maven")

addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.4.0")
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.4.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.13")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
15 changes: 7 additions & 8 deletions samples/grpc/local-drone-control-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<akka.version>2.9.1</akka.version>
<akka.version>2.9.2</akka.version>
<akka-projection.version>1.5.2</akka-projection.version>
<akka-persistence-r2dbc.version>1.2.2</akka-persistence-r2dbc.version>
<akka-management.version>1.5.0</akka-management.version>
<akka-persistence-r2dbc.version>1.2.3</akka-persistence-r2dbc.version>
<akka-management.version>1.5.1</akka-management.version>
<akka-diagnostics.version>2.1.0</akka-diagnostics.version>
<akka-http.version>10.6.0</akka-http.version>
<akka-grpc.version>2.4.0</akka-grpc.version>
<akka-grpc-maven-plugin.version>2.4.0</akka-grpc-maven-plugin.version>
<akka-http.version>10.6.1</akka-http.version>
<akka-grpc.version>2.4.1</akka-grpc.version>
<akka-grpc-maven-plugin.version>2.4.1</akka-grpc-maven-plugin.version>
<logback.version>1.2.13</logback.version>
<prometheus.client.version>0.16.0</prometheus.client.version>
<junit.version>4.13.1</junit.version>
Expand Down Expand Up @@ -448,9 +448,8 @@
<buildArgs>
<buildArg>--no-fallback</buildArg>
<buildArg>--verbose</buildArg>
<buildArg>--enable-http</buildArg>
<buildArg>--enable-https</buildArg>
<buildArg>--install-exit-handlers</buildArg>
<buildArg>--initialize-at-build-time=ch.qos.logback</buildArg>
<buildArg>-Dlogback.configurationFile=logback-native-image.xml</buildArg>
</buildArgs>
</configuration>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7f8e17c

Please sign in to comment.