Docs
Fly

Fly

Deploy your SaaS on Fly

SaaSKits and its docs are hosted on Fly. This is a guide to deploying your own SaaS on Fly.

Prerequisites

  • A Fly account
  • A domain name
  • A GitHub account
  • A GitHub repository with your SaaS code

Create Fly app

Go to Fly and create an account.

Install Fly CLI

Install Fly.

Note: Try flyctl instead of fly if the commands below won't work.

Login to Fly

fly auth login

Create Fly app

fly launch

You will be prompted with question.

Would you like to copy its configuration to the new app? - Answer Yes

You will be prompted with question.

Do you want to tweak these settings before proceeding? - Answer Y 

This will open a browser window with your app settings. You can change the name of your app and the region where it will be deployed.

Once you're done, click on "Save and deploy".

Add your .env variables

Go to your Fly app and click on the "Secrets" tab. Then click on "Add secret" and add your .env variables there.

We have created a simple utility that will generate fly secrets command for you.

You can generate it by running:

pnpm run set-fly-secrets
DATABASE_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
RESEND_API_KEY=
FROM_EMAIL=
HOST_URL=
SESSION_SECRET=
 
 
## Stripe
STRIPE_WEBHOOK_SECRET=
STRIPE_PUBLIC_KEY=
STRIPE_SECRET_KEY=

If you add a new .env variable, you'll need to redeploy your app for it to take effect.

Deploy your app

fly deploy

Create Stripe webhook

Post deployment you will need to create Stripe webhook.

Go to your Stripe dashboard and click on "Developers" and then "Webhooks". Then click on "Add endpoint" and add your webhook there.

In the "Endpoint URL" field, add your Fly app URL and then add /api/webhook to it.

On the same page, for "Events to send", select "Customer Subscription Created, Customer Subscription Updated, Customer Subscription Deleted."

Once you're done, click on "Add endpoint".

On the same page, click on "Click to reveal" next to "Signing secret" and copy the signing secret.

Go to your Fly app and click on the "Secrets" tab.

Either Add a new secret with the name STRIPE_WEBHOOK_SECRET and paste the signing secret there or update the existing STRIPE_WEBHOOK_SECRET secret with the signing secret.

SaaSKits repo by default provides GitHub Actions to deploy your SaaS on Fly. You can find them in the .github/workflows folder.

Deploying with GitHub Actions

To deploy your SaaS on Fly with GitHub Actions, you'll need to add the following secrets to your GitHub repo:

You can create a Fly API token by going to the Fly dashboard and clicking on your app and then clickin on Tokens.

Once you have your Fly API token, you can add it to your GitHub repo secrets.

Go to your GitHub repo and click on "Settings" and then "Secrets". Then click on "New repository secret" and add the Fly API token there.

FLY_API_TOKEN=

Voila! You can now deploy your SaaS on Fly by pushing to your GitHub repo.

Connect your domain

Go to your Fly app and click on the "Certificates" tab. Then click on "Add certificate" and add your domain there.

Once you have your domain added, you can go to your domain registrar and add the following DNS records:

A @
AAAA @
 
CNAME _acme-challenge

Once you have your DNS records added, wait a few minutes for them to propagate.

You can now go to your domain and see your SaaS live on Fly!