# Deployments, promote and rollback

> Every deployment is immutable and keeps its own URL. Production can move to any of them in seconds: forward with Promote, back with Instant Rollback.

- Category: Deploy
- URL: https://www.forkrail.com/docs/deployments-and-rollbacks

## Deployment URLs

| URL | What it serves |
| --- | --- |
| `<project>-<id>.<domain>` | One deployment, forever (while it’s kept). |
| `<project>-git-<branch>.<domain>` | The newest ready preview of a branch. |
| `<project>.<domain>` and custom domains | Production. |

Each deployment is a published Lambda function version with its own files and routing rules, so it costs nothing while nobody opens it, and moving production between deployments never needs a rebuild.

## Promote, rollback or redeploy

| Action | Use it to | What happens |
| --- | --- | --- |
| **Instant rollback** | Undo a bad release | Production moves back to an earlier production deployment exactly as it was: code, environment variables and settings. Live in about five seconds. |
| **Promote** | Put a deployment live | A production deployment goes live instantly. A preview whose environment variables differ from production’s is published again with production’s first. |
| **Redeploy** | Pick up changed env vars or settings | A new deployment with the project’s current environment variables and settings, rebuilt from its source. |

```bash
forkrail ls my-app                      # deployments, newest first
forkrail rollback my-app                # back to the previous production deployment
forkrail rollback my-app --to <id>      # back to a given one
forkrail promote <id>                   # make a deployment production
forkrail redeploy <id>                  # rebuild with today's env vars and settings
forkrail redeploy <id> --prod           # ...as a production deployment
```

> **Promoting a preview:** A deployment keeps the environment variables it was built with. `forkrail promote` refuses a preview whose preview variables differ from production’s and names the variables (never their values). Use `forkrail redeploy <id> --prod`, which is what the dashboard’s Promote does in that case, or pass `--allow-preview-env` if you mean it. Next.js deployments are always rebuilt, since Next bakes variables into its build.

## Warm before it goes live

A new deployment has no running environments yet. Before production moves to it (a production deploy, a promote or a rollback), forkrail starts three environments in every region it runs in and lets your app start in each, without sending it a request (five with concurrent compute off). The first visitors then wait milliseconds instead of a cold start:

```text
==> warm-up in us-east-1: 3 of 3 environments ready in 1.6 s (3 new, the app started in 739 ms)
```

A warm-up never holds production back: if the app doesn’t start, the log warns and production moves anyway. A rollback moves production at once and warms meanwhile. To keep environments ready around the clock, see [keep warm](https://www.forkrail.com/docs/functions#keep-warm).

## Staged production deployments

Normally a production deployment goes live as soon as it’s ready. Turn off **Auto-assign custom domains** (Settings → Deployments) and every production deployment waits instead: it’s built with production’s variables, answers on its own URL for you to check, and goes live when you promote it.

```bash
forkrail project my-app --auto-assign-domains false   # true or default turns it back on
forkrail deploy --prod                                # staged: production is unchanged
forkrail promote <id>                                 # live in seconds, no rebuild

# Stage one deployment, whatever the setting
forkrail deploy --prod --skip-domain
```

Staged deployments are marked **Staged** in the deployments list, with a Promote button. Pushes to the production branch, redeploys and deploy hooks follow the setting too.

## How long deployments are kept

Like Vercel’s Deployment Retention, each kind of deployment has a period: **canceled**, **errored**, **preview** and **production**, 30 days each unless you change it (from `1d` up to ten years, or `unlimited`). Set the install’s default under Team Settings → Deployments, and a project’s own under its Settings → Deployments.

Some deployments are kept whatever their age: production, the project’s 10 newest, its 20 newest ready production deployments and 20 newest ready previews, the last 5 that served production (rollback targets), anything still building, the newest preview of every branch that still exists, and anything a domain points at.

```bash
forkrail retention --project my-app              # what the policy does with each deployment, and why
forkrail retention set --project my-app --preview 7d --production 1y --dry-run
forkrail retention set --production 1y            # the install's default
forkrail retention sweep --project my-app         # list what a run would delete; --yes to run it
```

### Delete and restore

Deleting is in two steps, as on Vercel. A deleted deployment stops answering at once and moves to the project’s **Recently deleted** list with everything still stored. Restore it within 30 days and it comes back exactly as it was, at its own URL. After that it’s deleted for good.

```bash
forkrail rm <id>                      # delete a deployment that isn't production
forkrail restore <id>                 # bring it back
forkrail rm --project my-app          # delete a whole project (asks for the name)
```

Deleting a project removes everything of it: its deployments, functions in every region, files, schedules, environment variables and domains. Request logs already written are kept.
