Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample: update native image for clustered local-drone-control-java #1031

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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