256 KiB
How to Deploy a Self-Hosted Backend on fly.io
Deploying your self-hosted backend on fly.io can be a quick and efficient process. This guide will walk you through the steps required to get your backend up and running, using the example of setting up a backend for Fast Pocket. Fly.io is a great platform for hosting backends because it allows you to set up your backend swiftly and efficiently.
Setting Up Secrets
Before we begin deployment, it's crucial to set up a secret for our Stripe key, which has been previously generated. This ensures that our transactions are secure.
- Set up the Stripe key:
fly secrets set STRIPE_SECRET_KEY=your_stripe_key
Configuring the fly.toml File
The fly.toml
file contains all the configuration settings necessary for deploying to fly.io. Here are the key settings you need to modify:
- App Name: Change the app name to your desired name, e.g.,
icon.camp
. - Primary Region: Set the primary region to the closest region to where your app will be deployed. For example, if you want your app to be based in Australia, you might choose the region
syd
for Sydney. - Host: Ensure the host is set to your app's name, e.g.,
icon.camp.fly.dev
. - Port: Maintain the same port used for PocketBase, which is
8090
. - Stripe Billing and Cancel URLs: Set the URLs for Stripe billing and cancel actions. For instance:
STRIPE_BILLING_RETURN_URL
:https://icon.camp/account
STRIPE_CANCEL_URL
:https://icon.camp/pricing
STRIPE_SUCCESS_URL
:https://icon.camp/account
- Mount Source and Destination: Configure the source and destination for your fly.io volume. For example:
source
:data_icon_camp
destination
:/app/bin/pb_data
Deploying the Application
To deploy your application, follow these steps:
- Run the fly launch command:
This command initializes the deployment process.fly launch --no-deploy
-
Check for successful configuration: Ensure the configuration is valid and matches the settings in your
fly.toml
file. -
Attach a credit card if necessary: If the deployment fails, it may be due to not having a credit card attached to your fly.io account.
Creating and Mounting Volumes
Next, create and mount the necessary volumes for your application:
- Create a volume:
This command creates a 3GB volume for storing data.fly volumes create data_icon_camp --size 3