Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Latest commit

 

History

History
221 lines (151 loc) · 7.85 KB

OLD-README.md

File metadata and controls

221 lines (151 loc) · 7.85 KB

Cloudstate Sample Shopping Cart Application

Sample application structure

The sample application consists of two services:

  • A stateless service frontend
  • A stateful entity-based service shopping-cart

Building container images

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.

Frontend service

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.

Shopping cart service

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.

Prerequisites

  • 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.

Building a container image

Option 1: Using Gradle Build Tool

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.

Option 2: Using Maven
  1. 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 image my-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>
  1. Run the following command to compile proto/java files and generates Docker image
cd shopping-cart
mvn package
  1. Run command docker images | head to make sure the Docker image is generated correctly.

  2. (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.

  1. 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

Deploying to Akka Serverless

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

Prerequisites

Login to Akka Serverless

$ akkasls auth login

Create a new Akka Serverless project

$ 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

Deploy the frontend service

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

Deploying the shopping cart service

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

Frontend service

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.

Expose the shopping-cart service

$ akkasls svc expose shopping-cart --enable-cors

Visit the deployed shopping-cart frontend

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

Maintenance notes

License

The license is Apache 2.0, see LICENSE.

Maintained by

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!

Disclaimer

DISCLAIMER.txt