Deploy an app
Send your app to an environment with luna deploy, see what a deploy changes before it happens, and confirm a change that could lose data.
Your lunas run the code you last deployed, and they keep their data across deploys. A deploy has to show what it changes in that data and refuse a change that would break it.
Deploy to production
luna deploy sends the app in this folder to an environment of its project. Name the environment with --env.
luna deploy --env production
Without --env, it deploys to the environment in .env.local, which luna env use writes. With none there, it deploys to production.
When the deploy is done, it prints the project, the environment and its URL. Under them it lists each luna type with its visibility, its handlers and the URL to call them at, then the publishable key.
A deploy refuses an environment that does not exist yet, and names the command that creates it. luna env create makes one, empty or with the code and data of another, as Manage environments shows.
What a deploy sends
luna deploy finds the app where luna.config.ts is: in this folder, or in its luna folder. It sends these files from there.
- Your code. Every
.ts,.mts,.cts,.js,.mjs,.cjs,.jsonand.pyfile, outside folders whose names start with a dot. - Your dependencies. The packages in
node_modulesthatpackage.jsonlists underdependencies, and the packages they need.devDependenciesstay behind. - Packages of lunas. Any installed package whose
package.jsonhas alunafield, as Share lunas as a package explains.
The Luna SDK itself is not sent, since Luna provides it. Each file goes up only if Luna does not have it yet, so a redeploy sends what changed.
An app and its dependencies can be up to 256 MiB. A package with a native .node addon is refused, and so is a node_modules that pnpm laid out with links.
Check types first
Before it sends anything, luna deploy runs your app’s own tsc when the app folder has a tsconfig.json and TypeScript is installed. For Python code, it runs Pyright or mypy when your project sets one up.
A check that finds problems stops the deploy, and nothing is sent. Pass --no-check to deploy anyway.
Preview a deploy
Pass --preflight to see what a deploy would change, without deploying.
luna deploy --env production --preflight
Every deploy runs this preflight first, so you see the same lines on a real deploy. Each line is one of these kinds.
| Line | Means |
|---|---|
| A change | A luna type, table, column, handler or other declaration is added, removed or changed |
warning: |
Data stays behind, such as the rows of a column you dropped |
confirm: |
The deploy asks before it goes ahead. --preflight marks these needs confirming: |
blocked: |
The deploy is refused |
When a luna type’s tables change, or it has an onMigrate hook, the preflight also tries the new version’s migration. It runs it on copies of up to 5 of that type’s lunas, and a migration that fails on any copy blocks the deploy. It also warns when sampled lunas hold messages or schedules for handlers the deploy removes or changes.
Confirm a change that could lose data
When a column disappears and another of the same type appears, Luna cannot tell a rename from a drop and an add. It adds the new column and stops using the old one, without copying the data, unless your onMigrate hook does.
In a terminal, the deploy asks Deploy anyway? [y/N]. Pass --yes to answer in advance.
luna deploy --env production --yes
Outside a terminal, a deploy that needs confirming stops with preflight: these changes need confirming, so nothing was deployed and exits with code 6. Deploy from CI shows how a pipeline handles that.
Changes a deploy refuses
Some changes would leave existing lunas unable to read their data. The preflight blocks them, and --yes does not get past it.
- Changing a luna type’s key fields.
- Adding a required column without a default, or making a column required.
- Changing a column’s type or a table’s primary key.
- Turning a stream’s
liveoption on or off.
All but the key fields and the stream go through once the luna type has an onMigrate hook that moves the data. New code that fails to load is blocked too. Change a schema shows how to write one.
How lunas move to a new version
Each deploy makes a new version of the environment, with a higher number than the last. The deploy prints it, and ctx.version holds it in a handler.
Your lunas move to it on their own, and each runs its onMigrate hook first. The life of a luna explains when each luna moves.
To go back to earlier code, deploy that code again. It becomes the next version.
Deploy options
| Option | Does |
|---|---|
--env <ENV> |
Deploys to this environment |
--project <PROJECT> |
Deploys to this project, by name or as organisation/project |
--dir <DIR> |
Deploys the app in another folder |
--yes |
Goes ahead with a change the preflight asks about |
--preflight |
Shows what deploying would do, without deploying |
--no-check |
Skips the type check |
--json |
Prints what was deployed as JSON |
--show-token |
Prints the environment’s secret token too |
--watch |
Deploys again on every save, never to production |
Next steps
- Deploy from CI runs the same deploy from a pipeline with an API token.
- Store secrets gives the new version the keys it reads.
- Restore to an earlier moment rewinds data if a deploy goes wrong.