Skip to content

A minimal, polyglot, microservice-oriented calculator

Notifications You must be signed in to change notification settings

qn-ng/microcalc

Repository files navigation

MicroCalc: A polyglot, microservice-oriented calculator

CI

ℹ Looking for a microservice / service mesh sample app ? You might want to have a look at this.

Services architecture

architecture

api

Deploy to Kubernetes (Istio required)

Requirements: helm

Commands:

  • Modify helm/microcalc/values.yaml and update your domain name
  • Execute the following commands to deploy microcalc
$ kubectl create namespace microcalc
$ kubectl label namespace microcalc -l istio-injection=enabled
$ helm template helm/microcalc | kubectl apply -n microcalc -f -

The application will be accessible at:

  • Parser service: http://APP_DOMAIN
    • GET /api/v1/status
    • POST /api/v1/calculate

Run acceptance tests (as Job):

$ kubectl run robot -n microcalc --image=foly/microcalc-robot --restart=OnFailure -l 'app=microcalc-robot'

$ export POD_NAME=$(kubectl get pod -l 'app=microcalc-robot' -n microcalc -o jsonpath --template='{.items[0].metadata.name}')
$ kubectl logs $POD_NAME -n microcalc

Local run

Requirements: docker, docker-compose

Commands: $ docker-compose up

The application will be accessible at:

Run acceptance tests:

$ docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm robot

robot

Usage guide

  • Parser service API
POST /api/v1/calculate HTTP/1.1
Content-Type: application/json
[...]

{
    "input": "1+1"
}

HTTP/1.1 200 OK
content-type: application/json
[...]

{
    "operands": [
        1,
        1
    ],
    "origins": [
        {
            "result": 1,
            "service": "name: parser, version: v1"
        },
        {
            "result": 1,
            "service": "name: parser, version: v1"
        }
    ],
    "result": 2,
    "service": "name: add, version: v1"
}