Skip to content

ballerina-platform/module-ballerina-c2c

Repository files navigation

Ballerina Code2cloud Extension

Code2cloud extension implementation for ballerina.

License Daily build Build master branch codecov

Features:

  • Kubernetes deployment support.
  • Kubernetes service support.
  • Kubernetes liveness probe support
  • Kubernetes readiness probe support
  • Kubernetes horizontal pod autoscaler support.
  • Docker image generation.
  • Dockerfile generation.
  • Kubernetes config map support.

Refer samples for more info.

The base image required for the module is published to Dockerhub

How to build

  1. Download and install JDK 21
  2. Export github personal access token & user name as environment variables.
        export packagePAT=<Token>
        export packageUser=<username>
  3. (optional) Specify the Java home path for JDK 21 ie;
        export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home
  4. Install Docker
  5. Get a clone or download the source from this repository (https://github.com/ballerina-platform/module-ballerina-c2c)
  6. Run the Gradle command gradle build from within the module-ballerina-c2c directory.
  7. Copy c2c-extension/build/c2c-extension-***.jar file to <BALLERINA_HOME>/bre/lib directory.
  8. Copy c2c-ballerina/build/target/c2c-ballerina-zip/bala/ballerina/cloud directory to <BALLERINA_HOME>/repo/bala/ballerina directory.
  9. Copy c2c-ballerina/build/target/c2c-ballerina-zip/cache/ballerina/cloud directory to <BALLERINA_HOME>/repo/cache/ballerina directory.

Enabling debug logs

  • Use the "BAL_DOCKER_DEBUG=true" environment variable to enable docker related debug logs when building the ballerina source(s).
  • Use the "BAL_KUBERNETES_DEBUG=true" environment variable to enable kubernetes related debug logs when building the ballerina source(s).

Usage Sample:

import ballerina/http;
import ballerina/log;

listener http:Listener helloEP = new(9090);

service /helloWorld on helloEP {
    resource function get sayHello() returns string {
        return "Hello, World from service helloWorld ! ";
    }
}

Build the program with --cloud=k8s or --cloud=docker build option.

$ bal build --cloud=k8s <source_file>.bal 

The Kubernetes and Docker artifacts will be created in following structure.

$> tree
├── docker
│   └── Dockerfile
|-kubernetes
    └── hello-world.yaml