Viewing latest docs.
Switch version: v3

Deploy to Fly.io

Ship your Petal Pro app to production on Fly.io.

Before you start

There are a few things to think about before deploying — see Deployment fundamentals for the full checklist.

If you’re using Claude Code, the easiest path is to ask:

help me deploy this app to Fly.io

Claude knows the patterns from the CLAUDE.md files and will walk you through the steps below. The rest of this guide is the same flow, in case you want to do it yourself.

Dev commands

The everyday commands are plain mix:

iex -S mix phx.server # Start Phoenix with IEx attached
mix ecto.reset # Drop, create, migrate, and seed the database
sh scripts/stripe_webhooks.sh # Forward Stripe webhooks to localhost in a tmux session (needs the Stripe CLI and tmux)

Launch on Fly.io

Fly.io is the cheapest, easiest place to host a Phoenix app. Petal Pro is configured to deploy there with minimal fuss.

Install the Fly.io CLI, then sign in.

Create a new app with:

fly launch

ℹ️ Information: Fly will prompt you with default settings and ask if you want to tweak them. Hit Y — it opens a browser configuration UI.

In the configuration UI:

  • Give your app a name (you can’t change it later).
  • Under Database, choose Fly Postgres.
  • Pick the cheapest server size to start.
  • Leave Redis as none.
  • Hit Confirm.

The Dockerfile

Petal Pro v4 ships a production-ready Dockerfile in the repo root — you don’t need to generate one with mix phx.gen.release --docker. It’s a multi-stage build:

  • Builder stage: Elixir 1.19.5 / OTP 27.3.4 on Debian Bookworm. Compiles deps, runs the npm asset pipeline, produces an Elixir release.
  • Runner stage: Lean Debian Bookworm slim with only the compiled release — no Elixir or build tools in the production image.

fly launch detects the existing Dockerfile and uses it. If it tries to generate a new one, skip that step — the included Dockerfile already has nodejs and npm for the asset pipeline.

Environment variables

fly launch automatically creates these secrets:

  • SECRET_KEY_BASE
  • DATABASE_URL

The generated fly.toml also sets:

  • PHX_HOST
  • PORT

CLIENT_IP_HEADER

Not a secret, so it goes in fly.toml and not fly secrets set. Add one more line to that [env] block yourself:

fly.toml
[env]
PHX_HOST = "your-app.fly.dev"
PORT = "8080"
CLIENT_IP_HEADER = "fly-client-ip"

Petal Pro records the client’s address on sign-in (last_signed_in_ip), in the audit log and on Sentry events. Since 4.5.0 it ignores x-forwarded-for unless you tell it which proxy to trust, because anyone can write that header. Fly overwrites fly-client-ip on every request, so CLIENT_IP_HEADER = "fly-client-ip" is the one to trust. Leave it out and every sign-in records Fly’s proxy address instead of your user’s.

Required

# Email — required for auth flows (confirmation, password reset, etc.)
fly secrets set RESEND_API_KEY="re_..."

Optional

# Sentry error tracking — auto-activates when set, no code changes needed
fly secrets set SENTRY_DSN="https://..."
# Admin MCP API bearer token (for AI tool access)
fly secrets set MCP_ADMIN_TOKEN="your_secure_token"
# Slack notifications (new signups, billing events, daily digest)
fly secrets set SLACK_OAUTH_TOKEN="xoxb-..."
fly secrets set SLACK_CHANNEL_ID="C0123456789"

FORCE_SSL

Since 4.5.0, production forces https. Plain http gets redirected to https (301 for GET and HEAD, 307 for everything else), https responses get a one-year HSTS header, and cookies are marked Secure. Fly terminates TLS at its edge and passes the original scheme along in its fly-forwarded-proto header, which Petal Pro trusts, so on Fly there’s nothing to set.

FORCE_SSL is on when it’s unset, true or 1. Behind a proxy that sends no forwarded-proto header, every request redirects to itself unless you set FORCE_SSL=false. Turning it off also drops HSTS and the Secure flag.

Watch your health checks. An HTTP health check now gets a 301 unless it sends X-Forwarded-Proto: https or its path is excluded. The default fly launch config uses TCP checks, which are unaffected. If you added an HTTP check, give it the header. Petal Pro ships no health route, so /healthz here stands in for whatever path your own check hits:

fly.toml
[[http_service.checks]]
path = "/healthz"
[http_service.checks.headers]
X-Forwarded-Proto = "https"

Or exclude its path in the config :petal_pro, :force_ssl block of config/runtime.exs. Step 5 of the 4.4.0 to 4.5.0 upgrade guide has that snippet, plus the one entry you need to keep when you add an exclusion.

Auto-deploy on push to main

Petal Pro v4 includes a GitHub Actions workflow at .github/workflows/fly.yml. Out of the box it’s scoped to a demo branch (that’s how we deploy our public demo), so pushing to main deploys nothing until you change the trigger. Edit branches so it reads:

name: Deploy to Fly.io
on:
push:
branches:
- main

The rest of the file (concurrency, the flyctl steps) stays as it ships.

To enable it:

  1. fly tokens create deploy -x 999999h to generate a long-lived token
  2. In your GitHub repo: Settings → Secrets and variables → Actions
  3. Add a secret called FLY_API_TOKEN with the token value

cancel-in-progress: false queues deploys instead of cancelling them — so you don’t end up half-deployed if you push twice in a row.

Manual deploy

You can also deploy at any time with:

fly deploy

ℹ️ Information: If deployment fails, you may need to add a payment method — Fly only allows 1 machine per app on the free tier.

After deploying, run fly open to view it in the browser. You’re live.