Skip to content

Commit

Permalink
sample: update native image for clustered local-drone-control-java (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlugter authored Oct 9, 2023
1 parent 1976d92 commit 6f13d3c
Show file tree
Hide file tree
Showing 14 changed files with 2,278 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ We are now going to deploy the `restaurant-drone-deliveries-service` to the crea

This step is for deploying:

* Java: https://github.com/akka/akka-projection/tree/main/samples/grpc/shopping-cart-service-java
* Scala: https://github.com/akka/akka-projection/tree/main/samples/grpc/shopping-cart-service-scala
* Java: https://github.com/akka/akka-projection/tree/main/samples/grpc/restaurant-drone-deliveries-service-java
* Scala: https://github.com/akka/akka-projection/tree/main/samples/grpc/restaurant-drone-deliveries-service-scala

Build and publish the docker image to docker.io:

Expand Down Expand Up @@ -147,7 +147,7 @@ kubectl apply -f kubernetes/deployment.yml
Create a Kubernetes `Service` and port forward to simplify access to the pods from your local machine:

YAML
: @@snip [deployment.yml](/samples/grpc/shopping-cart-service-scala/kubernetes/service.yml) { }
: @@snip [deployment.yml](/samples/grpc/restaurant-drone-deliveries-service-scala/kubernetes/service.yml) { }

```
kubectl apply -f kubernetes/service.yml
Expand Down Expand Up @@ -259,7 +259,7 @@ sbt -Ddocker.username=<username> -Ddocker.registry=docker.io Docker/publish
Java
: ```
mvn -DskipTests -Ddocker.registry=<username>/shopping-cart-service clean package docker:push
mvn -DskipTests -Ddocker.registry=<username>/local-drone-control clean package docker:push
```

Update the `image:` in the `deployment.yml` with the specific image version and location you published.
Expand Down Expand Up @@ -303,4 +303,4 @@ List the orders that was propagated to the local control service, you should see

```
grpcurl -plaintext 127.0.0.1:8080 local.drones.DeliveriesQueueService.GetCurrentQueue
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
actorSystemName: local-drone-control-service
spec:
containers:
- name: restaurant-drone-deliveries-service
- name: local-drone-control-service
# use specific image version from docker publish
image: johanandren/local-drone-control:20230922-090652-37e49e0
# these will need to be increased/tuned for production environments!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && \

WORKDIR /opt/build
COPY . .
ARG profile=native
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && \
mvn -DskipTests=true -Pnative compile package
mvn -DskipTests=true -Pnative -P$profile package

FROM gcr.io/distroless/java-base-debian11:nonroot
COPY --from=builder /opt/build/target/local-drone-control /bin/
Expand Down
24 changes: 21 additions & 3 deletions samples/grpc/local-drone-control-java/native-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource usage, faster starts, and smaller deployments.
[GraalVM Native Image]: https://www.graalvm.org/latest/reference-manual/native-image/


## Native build
## Native build for single-node service

Note: to build locally with the `native-maven-plugin` you need to first [set up GraalVM].

Expand All @@ -15,14 +15,32 @@ Note: to build locally with the `native-maven-plugin` you need to first [set up
To create a native image for the current build platform and architecture:

```
mvn -DskipTests=true -Pnative compile package
mvn -DskipTests=true -Pnative package
```


## Docker build
## Native build for multi-node service

To create a native image to run as a multi-node Akka Cluster with PostgreSQL:

```
mvn -DskipTests=true -Pnative -Pclustered package
```


## Docker build for single-node service

To build a native image, within Docker, to be deployed as a Docker container:

```
docker build -f native-image/Dockerfile -t local-drone-control .
```


## Docker build for multi-node service

To build a native image to be deployed as a Docker container for a multi-node Akka Cluster with PostgreSQL:

```
docker build -f native-image/Dockerfile --build-arg profile=clustered -t local-drone-control .
```
19 changes: 19 additions & 0 deletions samples/grpc/local-drone-control-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.maven.plugin.version}</version>
<configuration>
<mainClass>local.drones.ClusteredMain</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -391,6 +399,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.39.1</version>
<executions>
<execution>
<id>build-docker-image</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public State(
}
}

public static final class WaitingDelivery {
public static final class WaitingDelivery implements CborSerializable {
public final String deliveryId;
public final Coordinates from;
public final Coordinates to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public ReportPosition(Position position, ActorRef<Done> replyTo) {
public static final class GetCurrentPosition implements Command {
public final ActorRef<StatusReply<Position>> replyTo;

@JsonCreator
public GetCurrentPosition(ActorRef<StatusReply<Position>> replyTo) {
this.replyTo = replyTo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package local.drones;

import akka.serialization.jackson.CborSerializable;
import java.util.Objects;

public final class Position {
public final class Position implements CborSerializable {
public final Coordinates coordinates;
public final double altitude;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"resources": {
"includes": [
{
"pattern": ".+\\.conf"
}
]
}
}
Loading

0 comments on commit 6f13d3c

Please sign in to comment.