Skip to content

improving-ottawa/kalix-improving-template

Repository files navigation

Code Build Riddl Model Build Coverage Status License

SonarCloud

Code Smells Security Rating Maintainability Rating Bugs Vulnerabilities Quality gate

sbt-kalix-improving

Submodules

sbt (Kalix) and typescript based multiproject as a template for frontend with microservices backend

Design

Domain documentation that will (eventually) generate code for services

Common

Includes common objects used for creating protobuf messages

Utils

A library for common Scala functions & service extensions (Auth)

Services

This template includes 2 Kalix services to be customized as desired to create microservices The template offers example of how to create service types, either by deploying together (bounded-context) or as a separate deployable (service3)

  • bounded-context
    • Service 1 (Action w/ Event Sourced Entity that is consumed by NoDataView)
    • Service 2 (just an Action)
  • Service 3 (Value Entity w/ View)

Gateway

The Kalix Gateway will serve as the interface between the client & the microservices The Gateway contains integration tests for all services

UI

The front-end client PWA (typescript)

Extensions

Email & OIDC/JWK capabilities

Integration Tests

integration-testkit contains extensions to the Kalix testkit that allow for testing a multi-deployment system integration-testkit-tests contains the tests themselves

Scheduled Tasks

Includes ScheduledTaskAction, a trait implementing Start, Run, and RunForTest, which allows for enabling scheduled actions In the example, every 2 hours, DoNothingService1 implements a DoNothingAction call to Service1 and then reads from NoDataView

Pre-Build Dependency Installation

Protoc-gen-js

npm install --global protoc-gen-js

For more info, see link

GRPC-Web Plugin Generator

After downloading an appropriate image, execute

$ sudo mv ~/Downloads/protoc-gen-grpc-web-1.5.0-darwin-x86_64 \
/usr/local/bin/protoc-gen-grpc-web
$ chmod +x /usr/local/bin/protoc-gen-grpc-web

for Mac or a similar command for Lunix.

See grpc-web docs more thorough instructions

Backend

Running services locally

To run any of the Kalix services locally, use the following command:

sbt "{service-name}/runAll -Dlogback.configurationFile=logback-local.xml -Dconfig.resource=integration-test.conf"

So for example, to run the gateway service locally, run:

sbt "gateway/runAll -Dlogback.configurationFile=logback-local.xml -Dconfig.resource=integration-test.conf"

Local Testing

The integration tests can be run locally via the command sbt "integration-test/test"

How to publish and deploy the Kalix services to Kalix

In order to publish and deploy the Kalix services to the Kalix cloud, you'll need to perform the following:

  1. Setup Kalix auth and Kalix / docker integration locally.

  2. Create a Kalix auth token and export it in your shell environment.

    • Run kalix projects tokens create --description "Some token description" after authentication to create the token
    • Export the token via export KALIX_TOKEN="{the token data}" (Note: the environment variable name must match KALIX_TOKEN exactly!)
  3. Use sbt to build and publish container images for all deployable services.

    • Simply run sbt publishContainers
  4. Use sbt to deploy the built and published containers

    • Simply run sbt deployServices
  5. Use the "health-check" to verify that the services are running.

    • Run grpcurl -d '{}' api.off-the-top.io:443 com.ott.gateway.Gateway/HealthCheck from your shell if you have grpcurl installed
    • Alternatively, you can curl or browse: https://api.off-the-top.io/health-check

Note: there is also a compound command publishAndDeploy which will run steps #3 and #4 back to back for you.

Front End

Running locally

Make sure first to run the script proto-gen. Then use the command npm start to get the app running in browser.

Local testing with Keycloak

  1. Copy the local configuration template file from gateway/src/user-local.conf.template to gateway/src/user-local.conf Don't worry, it is in the .gitignore, so your local changes will not be pushed up to the git server!
  2. Follow the instructions in gateway/src/Test-Setup-Instructions.md
  3. Profit!

Running the (local testing) CORS proxy

Simply run this command:

sbt "gateway/test:runMain com.example.gateway.LocalCorsProxy"

...after the Gateway and related services are started.