Deploying Ballerina Service on Choreo (iDasS) and Exposing as an API

This tutorial will provide some insights on how Choreo can be used to host a service (eg: Ballerina) in a production ready deployment

Ramindu De Silva
6 min readMar 7, 2024

Choreo is a internal developer platform as a service which provides capabilities and best practices of CI/CD, DevOps, serverless, Kubernetes, eBPF, API management, marketplaces, domain-driven design, microservices architecture, and more. This will takeout the burden of the organizations to manage and invest on the development platform and focus more on the development on the unique experience to the customers.

Ballerina is the ONLY programming language designed for integration which I will be using to create a service which integrates with a database, which is also hosted on Choreo.

This will contain multiple steps.

  1. Prerequisites
  2. Creating Ballerina service and adding to GitHub
  3. Building the service with the GitHub source code in Choreo and deploying and testing
  4. Publishing as an API
  5. Create applications, subscribe and invoke the API with the Try Out functionality in the Devportal

Prerequisites

  • Follow the guide to set up a Ballerina development environment and create ballerina service. You could use the Github repository as well.
  • If you are using the mentioned repository, it is calling a database to retrieve data.
  • Follow the documentation to create a MySQL database hosted on Choreo
  • Use the following script to populate the data that is required by the Ballerina service.

Creating Ballerina service and adding to GitHub

Once a Ballerina project is created to expose a service, you could commit the code to the GitHub. If needed, in the root file, it is possible to have multiple ballerina projects too. And when providing the Github URL, it is possible to mention which project will be used to create the Choreo component to host.

In this article, public(Subscription is needed to use a private repository to build a component out of it) Github repository will be used.

Building the service with the GitHub code in Choreo and deploying and testing

In order to deploy the the service, first login to the Choreo platform and create a project.

Then it is required to provide the below details. Even though only one service is going to be deployed, to provide more information on the platform, “Multi-Repo” option will be selected. Here, it is possible to select many repositories for the project.

From the list of components, “REST” should be selected, since we are exposing an REST API with our Ballerina service.

Once selected, it required to authorize the Github in order to access the repository.

Once Authorised, provide the component name select organisation name, repository and the branch. Finally Ballerina as the language of the source code is written. It is possible to use different language option if you are hosting a service written in the mentioned languages as well.

Since the given repository contained many Ballerina projects, it is needed to select by clicking on Edit, and selecting the correct Ballerina project. Once it is selected and clicked on Continue, the Create button will be enabled and it will be possible to create the component.

Once the project is is created, the following page will be visible, which you can select on the component and manage its build and deploy in the environments that you needed.

With the left side bar panel, the project now has to built, deploy and if needed to be tested by the swagger console provided.

After clicking on Build, the followup screen will provide you the interface to build the source code with the provided language. If the build is success, the next step is to deploy using the Deploy option in the left pane.

In the deploy section, there are configurable variables in Ballerina service as follows, which could be passwords, endpoints that can be changed by environments.

The deploy section will provide the capability to configure those variable before deploying the components. Once you click Configure & Deploy, the configurations list will be available to be entered. There after the Next button will proceed to the next panel which will provide you with the Deploy button to deploy in the development environment.

Once proceeded with the deployment, and if the service is deployed (Stop in the development), it is possble to Promote the component to Production. Or else it is possible to use the Console to test the service.

Once it is promoted, another deployment will be created for the service to run and can be managed using the console as well.

In the console, by providing the relevant values, it is possible to invoke the service with the preferred resource and the responses can be seen as well.

Once the testing has been done, it is possible to deploy the service as an API to be visible in he developer portal as well as manage it as well with permissions, security, etc.

Publishing as an API

With the Lifecycle tab, it is possible to publish the API so that the API is visible to the application developers in the organization via the DevPortal.

Create applications, subscribe and invoke the API with the Try Out functionality in the Devportal

Once the API is published, it will be available for the organization members with developer, API subscriber and External API subscriber roles. Refer to documentation for more information on the roles.

So, in order to subscribe to an API it is supposed to have an application. This application will contain all the necessary information to enforce authentication and authorization. In the devportal, it is need to click on Applications and then create an application (can be done by a user with developer, API subscriber and external API subscriber role) by giving a name and a description.

Once the application created, application keys can be generated for production and sandbox.

Note: If it is needed advance configuration such as multi-factor authentication, claims, etc of the application, it is possble to login to your organization in Asgardeo (https://console.asgardeo.io/t/ramindusademoorg) and configure.

Afterwards, its about subscribing to the API, generating the token and invoking an API

Once the token is copied from the above step, The API can be selected from the APIs section. Using the Try Out functionality, the subscribed application can be selected and the access token can be pasted to Execute to invoke the API.

Hope this tutorial provided some insights on how Choreo can be used to host a service (eg: Ballerina) in a production ready deployment.

--

--