/conway-life-stream-server

Conway's Game of Life Streaming Server (Akka implementation) + CI/CD with Actions

Primary LanguageScala

conway-life-stream-server

ci-cd

Overview

A trivial implementation of Conway's Game of Life with the help of actors with publishing resulting state in WebSocket connection and in HTTP stream. Basically it creates something like this:

field

Articles

Used technologies

  • Akka
  • Akka Http
  • Akka Streams (part of Akka itself)

Reference documentation:

After its start the application will start to publish events as an infinite HTTP-stream from endpoint /stream or as WebSocket-stream from /ws.

Client

Could be found in another repo - conway-life-stream-web-client

Compilation and run

As a build tool I use gradle and gradle-wrapper, so you can easily compile and build application with ./gradlew build and run with ./gradlew run.

Tests

For the tests I used ScalaTest and Akka native libraries. The tests can be run by the command ./gradlew scalaTest.

CI/CD

For integration and deployment was used GitHub's framework - GitHub Actions. Workflow source is available there Active workflow could be found there.

Deployment

For deployment Kubernetes cluster from Azure was used - the cheapest one from the cloud providers. Nice source of info related to cloud provider price comparison - Managed Kubernetes Price Comparison (2020)

Deployment descriptors are available in deployment sub-folder.

Sample Azure deployment:

Create the resource group:

az group create --name conwayLifeResourceGroup --location eastus

Create a cluster (it could take some time):

az aks create --resource-group conwayLifeResourceGroup --name conwayLifeAKSCluster --node-count 1  --node-vm-size Standard_B2s  --generate-ssh-keys

Get credentials and check functionality:

az aks get-credentials --resource-group conwayLifeResourceGroup --name conwayLifeAKSCluster
kubectl get nodes

Don't forget to store the credentials to future use.

The initial deployment is done by the commands (in deployment sub-folder):

kubectl apply -f stream-server-deployment.yml
kubectl apply -f stream-server-service.yml
kubectl apply -f stream-server-loadbalancer.yml

The assigned IP can be found with the command:

kubectl describe service/stream-server-loadbalancer | egrep Ingress

Whereas the correctness of work with the command:

curl http://<IP>/health

or simple open that url in you browser. You should get something like this <h1>Everything is fine :)</h1>

Rolling update is done by the command: kubectl set image deployment/stream-server-deployment conway-life-stream-server=XXXX, where XXX is image name (i.e. fedormalyshkin/conway-life-stream-server)

Some implementation info

For this app used fresh enough feature of akka - typed actors (in fact not absolutely fresh, bet has been published officially recently).

Hierarchy of actors

hierarchy

Actor interaction

interaction