Skip to main content

Deploying SerpBear to Fly.io

PERSISTENCE & CRON LIMITATIONS

1. No Guaranteed Free Tier: Fly.io now operates on a usage-based model. They currently waive the first $5/month of usage, but this is a courtesy and not a "forever free" plan.

2. Cron Job Issues: By default, Fly.io "Machines" auto-stop when there is no traffic. If the machine is stopped, SerpBear's internal cron jobs (keyword checks) will not run. To keep cron working, you must disable auto_stop_machines, which means the machine runs 24/7 and will consume your monthly $5 credit faster (~$2/mo for a 256MB machine).

Follow the steps below to deploy SerpBear using the modern Fly.io "Machines" architecture.

Step 1: Prerequisites

Ensure git and Node.js are installed. Then, install the latest flyctl.

Step 2: Clone the Repository

git clone https://github.com/towfiqi/serpbear.git
cd serpbear

Step 3: Initialize the Fly App

Run the launch command. When prompted, do not deploy yet, as we need to configure the volume first.

fly launch --name your-unique-name --region lax

  • Organization: Select your personal org.
  • Region: Choose the one closest to you (e.g., lax or lhr).
  • Setup Postgres/Redis: Select No.
  • Deploy now? Select No.

Step 4: Create a Persistent Volume

SerpBear uses SQLite. To prevent your data from being wiped on every restart, create a 1GB volume (the minimum size).

fly volumes create serpbear_data --size 1 --region lax

Step 5: Configure fly.toml

Open the generated fly.toml file. You need to make three specific changes:

  1. Mount the Volume: Add this at the bottom to link your volume to the app's data folder.
  2. Set the Port: Change internal_port to 3000.
  3. Disable Auto-Stop (For Cron): Change auto_stop_machines to false so the app stays awake to run keyword checks.
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = false # Required for Cron jobs to run 24/7
auto_start_machines = true
min_machines_running = 1

[mounts]
source = "serpbear_data"
destination = "/app/data"

Step 6: Set Secrets

SerpBear requires several environment variables for security and sessions. Run the following command (replace your-unique-name and the values accordingly):

fly secrets set \
USER=admin \
PASSWORD=yourpassword123 \
NEXT_PUBLIC_APP_URL=https://your-unique-name.fly.dev/ \
APIKEY=generate_a_long_random_string_here \
SECRET=generate_another_random_string_here \
SESSION_DURATION=24

Step 7: Deploy

Now you can push the app live:

fly deploy


Updating SerpBear

To update to the latest version of SerpBear in the future:

git pull origin main
fly deploy

Monitoring Cron Jobs

Because you disabled auto_stop_machines, your app will remain active. You can verify that the keyword checks are firing by checking your live logs:

fly logs


Would you like me to help you generate the random strings needed for the SECRET and APIKEY variables?