Using the Budibase CLI
Relevant source files
The following files were used as context for generating this wiki page:
The Budibase Command Line Interface (CLI), available as the @budibase/cli package, is a tool designed to help developers manage self-hosted Budibase installations and develop custom plugins. It provides a set of commands to initialize, run, and manage the Docker-based hosting environment, as well as build and publish custom component plugins for the Budibase builder.
The CLI is essential for developers who wish to extend the Budibase platform or manage their own infrastructure. It simplifies complex operations, such as setting up a docker-compose environment and packaging plugins, into a few straightforward commands.
Sources: packages/cli/README.md, packages/cli/src/index.ts:10-15
Installation
The CLI is a Node.js package and can be installed globally using npm.
npm i -g @budibase/cli
After installation, the CLI is available under the command budi.
Sources: packages/cli/README.md
Command Structure
The CLI is organized into two main command groups: hosting and plugins. All operations are performed by invoking budi followed by one of these commands and a subsequent sub-command.
Sources: packages/cli/src/index.ts:12-15
The following diagram illustrates the high-level command structure.
Sources: packages/cli/src/index.ts:12-15
Hosting Management (hosting)
The hosting command group is used to manage a self-hosted Budibase instance using Docker. These commands simplify the process of setting up and controlling the necessary Docker containers.
Sources: packages/cli/src/hosting/index.ts:13-18, packages/cli/README.md
Hosting Commands
The table below summarizes the available hosting sub-commands.
| Command | Description |
|---|---|
hosting init | Initializes a new Budibase hosting environment by creating a .budibase directory and configuration. |
hosting start | Starts the Budibase Docker containers based on the existing configuration. |
hosting stop | Stops the running Budibase Docker containers. |
hosting destroy | Stops and removes the Budibase Docker containers and related volumes. |
Sources: packages/cli/src/hosting/index.ts:14-17, packages/cli/README.md
Initializing the Environment (hosting init)
The budi hosting init command is an interactive process that sets up the necessary files for a self-hosted instance. It creates a .budibase directory which contains the docker-compose.yaml file for managing the services.
The initialization flow is as follows:
This diagram shows the interactive steps of the init command, from user prompts to file creation.
The init function prompts the user for two main pieces of information:
- Location: The directory where Budibase configuration files will be stored. This defaults to a hidden
.budibasedirectory in the specified path. - Port: The port on which the Budibase services will be exposed.
Sources: packages/cli/src/hosting/index.ts:20-47, packages/cli/src/constants.ts:1
Managing Services
The start, stop, and destroy commands are wrappers around docker-compose commands. They locate the docker-compose.yaml file within the .budibase directory and execute the corresponding action.
budi hosting startexecutesdocker-compose up -d.budi hosting stopexecutesdocker-compose stop.budi hosting destroyexecutesdocker-compose down -v.
These operations are handled by a utility function exec which spawns a child process to run the docker-compose commands.
Sources: packages/cli/src/hosting/index.ts:50-65, packages/cli/src/utils.ts:17-23
Plugin Management (plugins)
The plugins command group provides tools for custom component plugin developers. It helps with building the plugin source code and packaging it for distribution.
Sources: packages/cli/src/plugins/index.ts:10-14
Plugin Commands
The table below summarizes the available plugins sub-commands.
| Command | Description |
|---|---|
plugins build | Installs dependencies and builds the plugin source code. |
plugins publish | Builds and packages the plugin into a .tar.gz file for distribution. |
Sources: packages/cli/src/plugins/index.ts:11-12
Building a Plugin (plugins build)
The budi plugins build command prepares a plugin for use. It must be run from the root directory of a plugin project. The command performs two main actions:
- Runs
npm installto install the plugin's dependencies. - Runs
npm run buildto compile the plugin's source code.
This process is executed via the exec utility.
Sources: packages/cli/src/plugins/index.ts:16-22, packages/cli/src/utils.ts:17-23
Publishing a Plugin (plugins publish)
The budi plugins publish command packages a plugin for upload to Budibase. It first runs the build process and then creates a compressed archive of the plugin.
The sequence diagram below details the steps involved in publishing a plugin.
The process involves:
- Running the build steps (
npm installandnpm run build). - Reading the plugin's
schema.jsonto get metadata. - Creating a gzipped tarball (
.tar.gz) containing the built plugin files (plugin.min.js,schema.json).
Sources: packages/cli/src/plugins/index.ts:24-41
Configuration Files
The CLI primarily manages configuration through a dedicated directory and a docker-compose.yaml file.
.budibasedirectory: Created bybudi hosting init, this directory acts as the root for all self-hosting configuration files. Its name is defined by theBUDIBASE_DIRconstant.docker-compose.yaml: This file, located inside the.budibasedirectory, defines all the services, networks, and volumes required to run a full Budibase stack. Thehostingcommands directly manipulate the services defined in this file.
Sources: packages/cli/src/constants.ts:1, packages/cli/src/hosting/index.ts:40-45, packages/cli/src/utils.ts:12-15