The sample application consists of two services:
- A stateless service
frontend
- A stateful entity-based service
shopping-cart
All the latest container images are available publicly at lightbend-docker-registry.bintray.io/cloudstate-samples
. Feel free to build your own images from sources.
The frontend
service is a frontend web application written in TypeScript.
It is backed by a stateless
service that will serve the compiled JavaScript, html and images. This service makes grpc-web
calls directly to the other services to get the data that it needs.
You can use the pre-built lightbend-docker-registry.bintray.io/cloudstate-samples/frontend:latest
container image.
Alternatively, you can clone the cloudstateio/samples-ui-shoppingcart repository and follow the instructions there to build an image and deploy it to your own container image repository.
You can use the pre-built lightbend-docker-registry.bintray.io/cloudstate-samples/shopping-cart-java:latest
container image.
Alternatively, you can build an image from the sources in the shopping-cart
directory and push it to your own container image repository.
- Install JDK (Java Development Kit) version 8 or later.
- We recommend OpenJDK 1.8.0_252 or later. (Check with
java -version
) - SdkMan provides convenient way to install and manage multiple Software Development Kits including JDK.
- Alternatively, Windows, MacOS X, and Linux installer packages are available from AdoptOpenJDK.
- We recommend OpenJDK 1.8.0_252 or later. (Check with
Edit the jib
section of build.gradle
to specify your registry and the tag for the container image.
jib {
from {
image = "adoptopenjdk/openjdk8:debian"
}
to {
image = "<my-registry>/shopping-cart-java"
tags = [version]
}
container {
mainClass = "io.cloudstate.samples.shoppingcart.Main"
ports = ["8080"]
}
}
You might also want to set up authentication for your container registry. Please refer to Jib plugin documentation for further information.
NOTE: you can get a free public Docker registry by signing up at https://hub.docker.com
Build and push the container image to your container registry
./gradlew build jib
NOTE: This command builds and pushes the image directly to a container image repository bypassing local Docker (if it is present). However, it is possible to build the image using Docker with ./gradlew build jibDockerBuild
. Please refer to Jib plugin documentation for further information.
- Modify the Maven config file
shopping-cart/pom.xml
as shown below. Use the location of your Docker repository and the correct tag. If you use original setting without any change, it generates imagemy-docker-repo/shopping-cart-java:my-tag
<image>
<!-- Please change it to your Docker repository info -->
<name>my-docker-repo/shopping-cart-java:%l</name>
<build>
<!-- Base Docker image -->
<from>adoptopenjdk/openjdk8:alpine-jre</from>
<tags>
<!-- tag for generated image -->
<tag>my-tag</tag>
</tags>
- Run the following command to compile proto/java files and generates Docker image
cd shopping-cart
mvn package
-
Run command
docker images | head
to make sure the Docker image is generated correctly. -
(Optional) you can test your image loading in your local Docker by command
docker run my-docker-repo/shopping-cart-java:my-tag
You should see the server loads without error.
- Push your Docker image to your Docker repo. NOTE: you can get a free public Docker registry by signing up at https://hub.docker.com
The commands are
docker login
# re-tag image if needed
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker push
The following steps use akkasls
to deploy the application to Akka Serverless.
If you're writing Cloudstate services to deploy on your own Kubernetes cluster, the instructions for deploying the sample shopping cart application are in the deploy
directory
- Get Your Akka Serverless Account
- Install akkasls
$ akkasls auth login
$ akkasls projects new sample-shopping-cart "Shopping Cart Sample"
Wait until you receive an email approving your project!
List projects:
$ akkasls projects list
You should see the project listed:
NAME DESCRIPTION STATUS ID
sample-shopping-cart Shopping Cart Sample active 39ad1d96-466a-4d07-b826-b30509bda21b
You can change the current project:
$ akkasls config set project sample-shopping-cart
A pre-built container image of the frontend service is provided as lightbend-docker-registry.bintray.io/cloudstate-samples/frontend
.
If you have built your own container image, change the image in the following command to point to the one that you just pushed.
$ akkasls svc deploy frontend lightbend-docker-registry.bintray.io/cloudstate-samples/frontend
A pre-built container image of the shopping cart service is provided as lightbend-docker-registry.bintray.io/cloudstate-samples/shopping-cart-java
.
If you have built your own container image, change the image in the following command to point to the one that you just pushed.
$ akkasls svc deploy shopping-cart \
lightbend-docker-registry.bintray.io/cloudstate-samples/shopping-cart-java
Wait for the shopping cart service STATUS
to be ready
.
$ akkasls svc get
The frontend
service is a frontend web application written in TypeScript.
It is backed by a stateless service that will serve the compiled JavaScript, HTML and images. This service makes grpc-web
calls directly to the other services to get the data that it needs.
You can use the pre-built lightbend-docker-registry.bintray.io/cloudstate-samples/frontend:latest
container image.
Alternatively, you can clone the cloudstateio/samples-ui-shoppingcart repository and follow the instructions there to build an image and deploy it to your own container image repository.
$ akkasls svc expose shopping-cart --enable-cors
The sample shopping cart is live. The frontend lives on the hostname previously
generated when deploying the frontend. Append /pages/index.html
to the
provided hostname to see the shopping-cart frontend.
In the example above, the URL would be:
https://small-fire-5330.us-east1.apps.lbcs.io/pages/index.html
The license is Apache 2.0, see LICENSE.
This project is NOT supported under the Lightbend subscription.
This project is maintained mostly by @coreyauger and @cloudstateio.
Feel free to ping the maintainers above for code review or discussions. Pull requests are very welcome. Thanks in advance!