🚧 This documentation is not complete yet as Lagon is in Alpha.
CLI

The easiest way to deploy and manage Functions is through our Command-line interface (opens in a new tab).

Installation

Lagon CLI is available for the following operating systems:

  • macOS (Intel and M1)
  • Linux (x64 and arm64)
  • Windows (x64)

We recommend installing the CLI globally, using the package manager of your choice. You will also need ESBuild (opens in a new tab) installed globally on your machine, as we use it to bundle your Function's code:

# NPM
npm install --global @lagon/cli esbuild
# Yarn
yarn global add @lagon/cli esbuild
# PNPM
pnpm install --global @lagon/cli esbuild

Usage

Once installed, execute the lagon CLI to see all the commands available.

lagon login

Before being able to deploy and manage Functions, you will need to log in. Make sure you have already created an account. If you try to execute a command that requires being logged in, you will be warned and the command will be aborted.

To proceed, run lagon login and follow the instructions.

lagon logout

If you want, you can log out at any time. For security, you will be asked to confirm that you want to log out.

To proceed, run lagon logout and follow the instructions.

lagon deploy

Create a new Function or a new Deployment in the given directory. Make sure you are logged in before proceeding. If you are executing the command for the first time:

  1. You will be prompted to select an Organization
  2. You will be able to link to an existing Function, or create a new one by specifying a name

If you then want to trigger a new Deployment, re-run the same command. By default, subsequent Deployments are created in preview mode. Specify --prod to deploy in production mode.

This command accepts the following arguments and options:

  • [PATH] is an optional path to a file or directory containing the Function. (Default: .)
  • --client, -c <CLIENT> allows you to specify a path to an additional file to bundle as a client-side script.
  • --public, -p <<PUBLIC_DIR>> allows you to specify a path to a directory containing assets to be served statically.
  • --production, --prod allows you to deploy the Function in production mode. (Default: false)

Examples:

# Deploy the current directory to Production
lagon deploy --prod
# Deploy the index.ts file
lagon deploy ./index.ts
# Deploy the my-project directory and override the public directory
lagon deploy ./my-project --public ./my-project/assets

lagon ls

List all the Deployments of the given directory. Make sure you are logged in before proceeding. This command accepts only one argument:

  • [DIRECTORY] is an optional path to a directory containing the Function. (Default: .)

Example:

# List Deployments in the current directory
lagon ls
# List Deployments of the my-project directory
lagon ls ./my-project

lagon promote

Promote the given Deployment to production. Make sure you are logged in before proceeding. This command accepts the following arguments:

  • <DEPLOYMENT_ID> the ID of the Deployment to promote.
  • [DIRECTORY] is an optional path to a directory containing the Function. (Default: .)

Example:

# Promote the cl...km Deployment in the current directory
lagon promote claxnlc230738q5pa7iximskm
# Promote the cl...km Deployment of the my-project directory
lagon promote claxnlc230738q5pa7iximskm ./my-project

lagon undeploy

Un-deploy a Deployment. Make sure you are logged in before proceeding. This command accepts the following arguments:

  • <DEPLOYMENT_ID> the ID of the Deployment to undeploy.
  • [DIRECTORY] is an optional path to a directory containing the Function. (Default: .)

Example:

# Undeploy the cl...km Deployment in the current directory
lagon undeploy claxnlc230738q5pa7iximskm
# Undeploy the cl...km Deployment of the my-project directory
lagon undeploy claxnlc230738q5pa7iximskm ./my-project

lagon rm

🚫

Deleting a Function also deletes permanently all of its Deployments, statistics and logs.

Delete completely a Function. You'll be asked to confirm before proceeding. Make sure you are logged in before proceeding. This command accepts only one argument:

  • [DIRECTORY] is an optional path to a directory containing the Function. (Default: .)

Example:

# Delete the current directory's Function
lagon rm
# Delete the my-project directory's Function
lagon rm ./my-project

lagon dev

Launch a local dev server, using the same Runtime as when deployed to the Cloud. You can either:

  • Use this command without arguments, to use the current directory configuration
  • Specify a path to a directory containing a Function and its configuration
  • Specify a path to a file containing a Function

This command accepts the following arguments and options:

  • [PATH] is an optional path to a directory or file containing the Function. (Default: .)
  • --client, -c <CLIENT> allows you to specify a path to an additional file to bundle as a client-side script.
  • --public, -p <<PUBLIC_DIR>> allows you to specify a path to a directory containing assets to be served statically.
  • --hostname <HOSTNAME> allows you to specify a custom hostname to start the server on. (Default: 127.0.0.1)
  • --port <PORT> allows you to specify a custom port to start the server on. (Default: 1234)
  • --env <FILE> allows you to specify a custom path to an environment file to inject environment variables. (Default: .env)
  • --allow-code-generation allows you to enable code generation from strings (eval / new Function)
  • --prod allows you to set process.env.NODE_ENV to "production" instead of "development"

Examples:

# Run a local dev server in the current directory
lagon dev
# Run a local dev server with a file entrypoint and some assets
lagon dev ./server.tsx --public ./assets
# Run a local dev server inside the my-project directory using a custom port
lagon dev ./my-project --port 56565
⚠️

Although the dev command uses the same Runtime as when deployed, the local HTTP server itself doesn't have the same optimizations. As such, you shouldn't run any production environment on it, or run any kind of load tests/benchmarks.

lagon build

For debugging purposes, you can build a Function and see its output without deploying it. Under the hood, lagon build does the same steps as lagon deploy, but skips the deployment part and instead writes the output to a local .lagon folder.

This command accepts the following arguments and options:

  • [PATH] is an optional path to a file or directory containing the Function. (Default: .)
  • --client, -c <CLIENT> allows you to specify a path to an additional file to bundle as a client-side script.
  • --public, -p <<PUBLIC_DIR>> allows you to specify a path to a directory containing assets to be served statically.

Examples:

lagon build ./server.tsx --client App.tsx --public ./assets
tree .lagon/
# .lagon/
#   index.js
#   App.js
#   assets/

lagon link

Link a local Function to a deployed one, without triggering a new Deployment. Make sure you are logged in before proceeding. This command accepts only one argument:

  • [DIRECTORY] is an optional path to a directory containing the Function. (Default: .)

Example:

lagon link ./index.ts

Self-hosting configuration

If you are self-hosting Lagon, you will need to update the default site URL to the one used by your installation. To do so, find the configuration file located in ~/.lagon/config.json:

{
  "token": "**************",
  "site_url": "https://dash.lagon.app" // Replace this field
}

Replace the site_url field with the one configured during the installation. To verify if it's working correctly, log in to your installation using lagon login.