Skip to content

Latest commit

 

History

History
134 lines (105 loc) · 4.57 KB

File metadata and controls

134 lines (105 loc) · 4.57 KB

Ballerina Programming Language

Todo

V 0.991

Ballerina is an open source programming language and platform for cloud-era application programmers to easily write software that just works.

Prerequisites

See more

Todo

Todo

Validation tests (TDD: warriors & apigw)

When deploy the services on the cluster, verify that the following calls work:

  • should succeed only inside the cluster
curl GET http://wiarriors-service/api/v1/warriors
  • Outside the cluster with a valid apikey should succeed
curl GET http://techwatch.io/api/v1/apigw/warriors -H "apikey: Z2FtZTpnYW1lMQ==" 
  • Outside the cluster with a invalid apikey should fail
curl GET http://techwatch.io/api/apigw/v1/warriors -H "apikey: G02TheBeach==" 

[Step 0] Init project

# use ballerina init command inside the work directory   
ballerina init

[Step 1] Warriors service

  • Add the service as a ballerina module New -> Module new ballerina file

  • Create the service class New -> New Ballerina File, crete service class

  • Code the config and logic the service

[Step 2] API Gateway

Add the API Gateway service as a ballerina module, create the service class and code the config and logic of the API Gateway

[Step 3] Add Kubernetes config

The Kubernetes config of the internal service (do the same for warriors service)

@kubernetes:Service {
    name: "Warriors"
}
@kubernetes:Deployment {
    image: "warriors",    // remember the docker image should contain only simple letters
    name: "WarriorsService",
    replicas: 3,
    namespace: "wired-services",
    buildImage: false,
    labels: {team:"WIRED", scope:"SERVICE"},
    dockerHost: "tcp://192.168.99.103:2376",    // IP can be obtained via `minikube ip` command
    dockerCertPath: "~/.minikube/certs",    // Docker cert path should be configure here
    singleYAML: true
}

To build the docker image, add docker expose config, will build the docker image when run the ballerina build command

@docker:Expose{}

[Step 4] Build project

We need a Kubernetes cluster running, in this example we use minikube, install it and start the cluster:

minikube start
  • Logs Logs

And then build the project using command ballerina build <module>, will build the specified module or all modules if no specifications.

ballerina build warriors
  • Logs: Logs

  • Generated files: Generated files

  • Generated Dockerfile for api-gateway service: DockerFile

  • Generated deployment file for api-gateway service: deployment file

[Step 5] Deploy our services

The deployment commands are logged when run ballerina build.

  • Docker container
docker run -d -p 9090:9090 warriors:latest
  • Kubernetes deployment
kubectl apply -f <path-to-your-projec-dir>/target/kubernetes/warriors

[Step 6] Plugin Tools

The current version of the intellij plugin has bugs, the vsc plugin will be used to continue this work.

  • The plugin generates sequence diagrams from the source code in real-time diagram

  • The API desiner generates documentation from the source code but also allows the reverse generate a code from the disigner in real time. We can therefore develop services without writing any line of code,only by using the UI

  • API designer