Consolidate-packages tool

The consolidate-packages tool allows you to create a single executable by consolidating multiple Ballerina services. These services can either be pulled from Ballerina Central or used directly from your local environment without needing to publish them to a remote repository.

Consolidate packages from the Ballerina Central

Define the consolidator package

Create a new package and add the consolidate-packages tool entry, along with the required services for consolidation, in the Ballerina.toml file, as shown in the example below. Services can be added or removed as needed by updating the values provided for the options.services array.

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

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

Consolidate locally published packages

In some projects, services are developed together but do not require publishing to a remote repository, as they are consumed within the same project. For these cases, the tool enables the consolidation of multiple packages into a single executable without requiring publication to any remote repository. The packages can be published to the local repository and consolidated using the steps below:

  1. Publish packages required to consolidate to the local repository using the bal push command.

    Copy
    $ bal push --repository local
    
  2. Include the packages as local dependencies in the Ballerina.toml of the consolidator package.

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

Using the CLI tool

The CLI tool helps automate the consolidation process, which is typically useful in CI/CD workflows.

Installation

Execute the command below to pull the tool.

Copy
$ 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,myorg/checkout

Create a consolidated package using locally published packages

Copy
$ bal consolidate-packages new --package-path hotel-app myorg/menu:0.1.0,myorg/ad:0.1.0 --repository=local

Note: The version is mandatory when specifying a package from the local repository

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,myorg/inventory

Add locally published packages

Copy
$ cd hotel-app
$ bal consolidate-packages add myorg/customer:0.1.0,myorg/inventory:0.1.0 --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/menu,myorg/ad

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