Deploy to Fly.io

  • Alexandro Martínez
    Author
    by Alexandro Martínez
    2 years ago
  • TLDR: Watch the video instead.

    Thanks to @ebm for posting a discussion on how to deploy to fly.

    1. Set the app name and primary region at fly.toml.

    app = "YOUR_APP_NAME"
    ...
    primary_region = "iad"

    IMPORTANT: The primary region should match your database (e.g. Supabase) region.

    1. Create the app using fly CLI:

    fly apps create YOUR_APP_NAME
    1. Set your secrets:

    You can see the examples at .env.fly.example.

    Note: Replace "TODO" with your values or delete the variable before running the command, otherwise empty variables cause the command to throw error.

    flyctl secrets set APP_NAME=YOUR_APP_NAME \
    SERVER_URL=https://YOUR_APP_NAME.fly.dev \
    DOMAIN_NAME=YOUR_APP_NAME.fly.dev \
    DATABASE_URL=postgres://{USER}:{PASSWORD}@{HOST}:{PORT}/{DATABASE} \
    API_ACCESS_TOKEN=1234567890 \
    SESSION_SECRET=abc123 \
    JWT_SECRET=abc123 \
    SUPABASE_API_URL=TODO \
    SUPABASE_KEY=TODO \
    SUPABASE_ANON_PUBLIC_KEY=TODO \
    STRIPE_SK=TODO \
    SUPPORT_EMAIL=TODO \
    POSTMARK_SERVER_TOKEN=TODO \
    POSTMARK_FROM_EMAIL=TODO \
    --app YOUR_APP_NAME
    
    1. Deploy the app:

    Make sure to remove "postinstall": "prisma generate" from package.json before deploying.

    fly deploy
    1. Optional: Scale

    fly scale vm shared-cpu-2x --app YOUR_APP_NAME

    If you don't scale enough, you may get crashes:

    image.png

    We respect your privacy.

    TLDR: We use cookies for language selection, theme, and analytics. Learn more.