# Fly.io (/docs/cli/deploy/fly)

In a project with `deploy fly` (CLI 0.25.0 or newer), `pnpm clubedge deploy` uses [Fly's CLI](https://fly.io/docs/flyctl/install/) and your Fly login:

```sh
pnpm clubedge add deploy fly   # if the project deploys elsewhere today
pnpm clubedge deploy
```

Install Fly's CLI first: it is not on npm, so `deploy` can't download it for you.

## What it does [#what-it-does]

1. **Signs in** with `fly auth login`, which opens the browser when you are signed out. With `FLY_API_TOKEN` set, it skips this.
2. **Creates or reuses the app** in your personal organization. `fly launch` writes the app's name (the package name and a short suffix, since Fly names are global) and region into `fly.toml`; commit it.
3. **Creates the databases** unless your [env file](./index.mdx#your-own-databases) points them elsewhere: an unmanaged Postgres app, `<app>-db` (one `shared-cpu-1x` machine and a 1 GB volume), attached so it sets `DATABASE_URL`, and with `cache redis`, Upstash Redis `<app>-redis` as `REDIS_URL`.
4. **Imports the secrets:** `APP_URL` and `NEXT_PUBLIC_APP_URL` as `https://<app>.fly.dev`, a `BETTER_AUTH_SECRET` that later runs keep, `CLIENT_IP_HEADER=fly-client-ip`, where the [client's address](./index.mdx#client-addresses) is (CLI 0.42.0 or newer), and the [env file's](./index.mdx#provider-keys) values. The ones still unset are listed before the build.
5. **Runs `fly deploy`** with `NEXT_PUBLIC_APP_URL` as a build argument: Fly builds the `Dockerfile`, runs the migrations as the release command, and waits for the health checks on `/api/health`.

## Costs [#costs]

<Callout type="warn">
  Fly bills the app, Postgres, and Redis on your plan. Fly's Managed Postgres starts at $38 a month, so `deploy` uses unmanaged Postgres; for Managed Postgres, create it with `fly mpg create`, attach it with `fly mpg attach`, then run `deploy`.
</Callout>

## When a deploy fails [#when-a-deploy-fails]

`fly logs --app <app>` shows why: a failed migration in the release command, or a health check that never passed. Fix the cause and run `deploy` again, which reuses what exists.

To set up Fly.io without this command, see [Fly.io](../../starter/deploy/fly.mdx) in the deploy guide.
