fastpocket/Documentation/docs/NEW/Row I/Fly Deploy.md

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.

Click to watch the video

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.

  1. Set up the Stripe key:
    fly secrets set STRIPE_SECRET_KEY=your_stripe_key
    

Setting up secrets - 10

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:

  1. App Name: Change the app name to your desired name, e.g., icon.camp.
  2. 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.
  3. Host: Ensure the host is set to your app's name, e.g., icon.camp.fly.dev.
  4. Port: Maintain the same port used for PocketBase, which is 8090.
  5. 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
  6. 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

Configuring fly.toml - 41

Deploying the Application

To deploy your application, follow these steps:

  1. Run the fly launch command:
    fly launch --no-deploy
    
    This command initializes the deployment process.

Running fly launch - 190

  1. Check for successful configuration: Ensure the configuration is valid and matches the settings in your fly.toml file.

  2. 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.

Configuration validation - 253

Creating and Mounting Volumes

Next, create and mount the necessary volumes for your application:

  1. Create a volume:
    fly volumes create data_icon_camp --size 3
    
    This command creates a 3GB volume for storing data.

Creating volume - 306