Skip to content
Luna
Esc
↑↓navigate↵open⌘Jpreview
On this page

Deploy from CI

Deploy from a pipeline with a scoped API token, tell the CLI where to deploy with environment variables, and act on its exit codes.

A pipeline cannot log in through a browser, and it should not deploy with your own account. Give it an API token that can deploy one project and nothing else.

Make an API token

luna tokens create makes a token for one project. deploy:write is the scope a deploy needs.

luna tokens create --project acme/notes --scope deploy:write --env production --name github-actions

The token is printed once, on standard output. Store it in your pipeline’s secrets, such as a GitHub Actions secret named LUNA_TOKEN.

Option Does
--scope <SCOPE> Adds a permission, and repeats for more
--env <ENV> Limits the token to one environment, and repeats for more
--expires-in <TIME> Stops the token after this long, such as 90d
--name <NAME> Names the token in luna tokens list

Add environments:write for a pipeline that runs luna env create, and secrets:write for one that sets secrets. Automate with API tokens lists every scope and shows how to rotate a token.

Tell the CLI where to deploy

A pipeline has no .env.local and no login, so it names everything in environment variables.

Variable Holds
LUNA_TOKEN The API token. Every command sends it instead of a login
LUNA_PROJECT The project, as organisation/project
LUNA_ORG The organisation, when LUNA_PROJECT holds the project’s name alone
LUNA_ENV The environment to deploy to. production when it is not set

A flag wins over its variable, so --env staging overrides LUNA_ENV for one command.

Decide on confirmations

Some deploys stop to ask, such as one where a column looks renamed. A pipeline cannot answer, so the deploy stops with preflight: these changes need confirming, so nothing was deployed and exit code 6.

Pass --yes to let such deploys through.

luna deploy --yes

A deploy the preflight blocks never goes through, with or without --yes. Deploy an app lists what blocks a deploy.

Act on exit codes

Every luna command ends with an exit code a script can act on.

Code Means
0 Done
1 Failed, including a deploy the preflight refused
2 The command was written wrongly
3 Not logged in: no token, or Luna refused it
4 Not allowed: the token lacks the scope or the environment
5 Not found
6 Needs --yes: a command asked before a change, and nobody could answer

A deploy that stops to ask about a change exits with 6, as luna env delete and luna restore do.

With --json, a command that fails also writes its error as JSON on standard error, with the fields message, exitCode, status and code.

A GitHub Actions workflow

This workflow deploys the luna folder of the repository to production on every push to main. Replace <INSTALL_LUNA_CLI> with the command that installs the luna CLI on the runner.

name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      LUNA_TOKEN: ${{ secrets.LUNA_TOKEN }}
      LUNA_PROJECT: acme/notes
      LUNA_ENV: production
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 24
      - name: Install the luna CLI
        run: <INSTALL_LUNA_CLI>
      - name: Install dependencies and the Luna SDK
        run: npm install --install-links "$(luna sdk ts --path)"
      - name: Deploy
        run: luna deploy
  • npm install --install-links installs the app’s dependencies with the SDK that matches the CLI. The deploy reads the app with that SDK and sends the dependencies.
  • luna deploy checks types when the app has a tsconfig.json, runs the preflight, then deploys. A command that fails stops the job with one of the exit codes above.

Next steps

Was this page helpful?