Skip to Content

Environments, rollback and promote

Run a staging copy of a product from its own branch, serve an earlier release again, and move a release to production.

This page sets up a staging environment that deploys from a staging branch, then shows how to roll a target back and how a release reaches production. You need a project that already deploys from GitHub (see Deploy a backend).

What an environment is

An environment is a project of its own under the main one: sac-staging for sac's staging. So it has its own:

  • database, key-value, files and queues;
  • device topics (sac-staging/…) and camera paths;
  • secrets and variables;
  • people, roles and sign-in clients.

Nothing in it touches production. A backend reads which one it runs in from FLOOR_ENVIRONMENT (production, staging) and FLOOR_PROJECT (sac-staging), or from cx.project().

Each environment is linked to one branch, and a push to that branch deploys it. A branch deploys one environment only. Its addresses are made with it: each of the project's addresses as <environment>.<address>, so access-control.example.com/api serves at staging.access-control.example.com/api. floor.toml keeps naming production's addresses; Floor maps each target to the environment's own.

An environment runs only what it deploys. Delete one you don't need from Settings › Environments (delete its database and cache first).

1. Add the environment

In the console, open the project's Settings › Environments and add one with its name and branch. That's the whole setup there; skip to step 3.

From the CLI:

floor projects add-env sac staging

This makes the project sac-staging, with staging. in front of each of sac's hostnames. Pass --host (repeat it) to choose the addresses yourself.

2. Point DNS at Floor

Add a DNS record for each new address (staging.access-control.example.com) pointing at Floor's server, like production's. The gateway gets the certificates itself once the name resolves.

floor deployments link sac-staging acme/access-control --branch staging

Then list the branch in the workflow's push trigger, so a push to it runs the deploy:

on:
  push: { branches: [main, staging] }
  workflow_dispatch:

The workflow doesn't say which environment to deploy. Floor picks it from the branch when CI trades its OIDC token, and the deploy token it hands back is for that environment only.

4. Give it its variables, secrets and sign-in clients

Because it is a project of its own, the environment starts empty:

floor deployments set-var sac-staging VITE_MAPS_KEY pk_test_…
floor secrets set sac-staging GATE_VENDOR_TOKEN          # reads the value from stdin
floor db create sac-staging
floor roles set sac-staging "admin=Runs the site" "guard=Works the gates"
floor clients create sac-staging sac-dashboard-staging --name "SAC dashboard (staging)" --kind web \
  --redirect https://staging.access-control.example.com/auth/callback

Client ids are global, so the staging dashboard needs its own (sac-dashboard-staging). See Sign-in for roles and clients.

5. Push to the branch

git push origin staging

The run's log starts with Signed in as acme/access-control, deploying to sac-staging. From your machine, floor deploy --env staging does the same with your own sign-in.

In the console, the environment picker beside the project's name switches between production and each environment. An environment's pages carry a striped strip across the top, so you can tell them apart.

Roll back

Every ready deployment can serve again. Find the one you want and serve it:

floor deployments list sac --target api
floor deployments rollback sac 0193a4c2-…

In the console, a deployment's page has Roll back to <commit> for the one before it, and Serve again on any earlier deployment in its history.

  • How it swaps. A backend rolls back the same way it deploys: its migration step runs, it starts next to the current version, and the route switches once it answers its health path.
  • Its variables. It starts with the environment's variables as they are now.
  • What's kept. Floor keeps the files of each target's last 3 releases (and whatever serves), and the last 5 .floor files per project. Older than that, "serve again" says the files aren't kept: ship that release's .floor file again (CI keeps it as a run artifact for 14 days).
  • The schema stays newer. Migrations the database already has and the older version doesn't know are no error. So keep each release working on the next one's schema: add a column in one release, stop using the old one, drop it in a later one (Database).

To stop serving a target everywhere while keeping its history:

floor deployments retire sac dashboard

Promote a release to production

There is no command that copies a deployment from one environment to another. Two ways get a tested release to production:

  • Merge the branch. Merge staging into main; the push to main builds and deploys production. This is the usual way, because each environment's build gets its own build variables.

  • Ship the same file. A .floor file built for sac can be shipped to sac or any of its environments:

    floor deploy sac-1.5.0+3f2c1ab.floor              # to production
    floor deploy sac-1.5.0+3f2c1ab.floor --env staging

    A backend reads its variables when it starts, so its binary is the same everywhere. A site's build may have baked in staging's build variables (VITE_API_URL), so ship sites this way only when their build doesn't depend on the environment.

floor deployments promote exists for pull-request previews from before previews were retired, and only copies a ready preview to production.

Previews

Pull requests don't deploy. Previews made before this stay until their pull request closes, or until you remove them:

floor deployments remove-preview sac 42

The console's deploy pages

Everything here is on the project's own pages:

  • Code › Deploys: what's live per target, which deploy failed, then every deployment.
  • A deployment's page: what it deployed (commit, branch, author, the CI run), its history with roll back and serve again, and its deploy log, updated as it runs.
  • Settings › Environments: add an environment with its branch, see what each deploys from and where, and delete one.
  • Settings › Variables and secrets: the variables each environment's deploys get. Secret values are never shown again.
  • Settings › General › Repository: link and unlink the repository, and see whether the GitHub App reaches it.

On this page