Consolidate-packages tool

Ballerina inherently supports microservices-style deployments, which are well-suited for microservice orchestration platforms like Kubernetes. However, if you prefer a server-based deployment model, this tool allows you to consolidate multiple services into a single process, making deployments more manageable and efficient.

Usage

Create or update a consolidator package

Create a new package and add the consolidate-packages tool entry as shown in the below example in the Ballerina.toml file with the services required to consolidate. Services can be added or removed as needed by updating the values provided for the options.services array. The tool will be automatically pulled during the package build.

Copy
[package]
org = "myorg"
name = "myapp"
version = "0.1.0"

[[tool.consolidate-packages]]
id = "consolidateSvc"
options.services = ["myorg/svc1", "myorg/svc2"]

Services required for consolidation can be from Ballerina Central, local repository, or both. In addition to the tool entries above, add a dependency entry for locally published packages as shown below:

Copy
[[dependency]]
org = "myorg"
name = "svc1"
version = "1.1.0"
repository = "local"

Using the CLI tool

Alternatively, the consolidate-packages CLI tool can be installed to create the package and add or remove services. This is typically useful in CI/CD pipelines.

Installation

Execute the command below to pull the tool.

bal tool pull consolidate-packages
Creating a new consolidator package
Copy
$ bal consolidate-packages new --package-path <path> <comma-separated-list-of-services> 

For example,

Copy
$ bal consolidate-packages new --package-path hotel-app myorg/order_service,myorg/payment_service 

To create a consolidated package with local packages,

Copy
$ bal consolidate-packages new --package-path hotel-app myorg/order_service,myorg/payment_service --repository=local
Adding new services to an existing package

Execute the following command from the package root directory.

Copy
$ bal consolidate-packages add <comma-separated-list-of-services>

For example,

Copy
$ cd hotel-app
$ bal consolidate-packages add myorg/customer_service,myorg/menu_service

To add local packages,

Copy
$ cd hotel-app
$ bal consolidate-packages add myorg/customer_service,myorg/menu_service --repository=local
Removing services from an existing package

Execute the following command from the package root directory.

Copy
$ bal consolidate-packages remove <comma-separated-list-of-services>

For example,

Copy
$ bal consolidate-packages remove myorg/payment_service

Run bal consolidate-services --help for more information about the commands.