Fly.io Deployment
Automated CI/CD deployment to Fly.io. Push to master and your app deploys in ~2 minutes.
One-Time Setup
1. Create Fly.io Account
Sign up at https://fly.io and install the CLI:
bash
# macOS
brew install flyctl
# Linux/WSL
curl -L https://fly.io/install.sh | shLogin:
bash
flyctl auth login2. Create Your App
bash
flyctl apps create your-app-name3. Create Postgres Database
bash
# Create database
flyctl postgres create --name your-app-name-db --region iad --initial-cluster-size 1 --vm-size shared-cpu-1x --volume-size 1
# Attach to your app (sets DATABASE_URL automatically)
flyctl postgres attach your-app-name-db -a your-app-name4. Set Secrets
bash
# Required secrets
flyctl secrets set -a your-app-name \
SECRET_KEY="$(openssl rand -hex 32)" \
SECURITY_PASSWORD_SALT="$(openssl rand -hex 32)" \
SECURITY_TOTP_SECRETS="$(openssl rand -hex 32)"
# Fix database URL (Fly uses postgres://, SQLAlchemy needs postgresql://)
# Get the DATABASE_URL from: flyctl secrets list -a your-app-name
# Then set SQLALCHEMY_DATABASE_URI with postgresql:// prefix:
flyctl secrets set -a your-app-name \
SQLALCHEMY_DATABASE_URI="postgresql://user:pass@your-app-name-db.flycast:5432/your-app-name?sslmode=disable"5. Update fly.toml
Edit fly.toml and change the app name:
toml
app = 'your-app-name' # Change this6. Add GitHub Secret
Create deploy token:
bashflyctl tokens create deploy -x 999h -a your-app-nameAdd to GitHub:
- Go to your repo → Settings → Secrets and variables → Actions
- New repository secret:
FLY_API_TOKEN= (paste token)
7. Deploy
Go to Actions tab in your GitHub repo → "Deploy to Fly.io" → "Run workflow"
Your app will be live at: https://your-app-name.fly.dev
Optional: Auto-deploy on push
Edit .github/workflows/deploy-fly.yml and uncomment the push trigger:
yaml
on:
workflow_dispatch:
push:
branches: [master]Post-Deployment
Create Admin User
SSH into your app and create the admin:
bash
flyctl ssh console -a your-app-name
python -c "from run import app; from enferno.commands import create_db, install; app.app_context().push(); create_db(); install()"Or run interactively:
bash
flyctl ssh console -a your-app-name -C "flask create-db && flask install"Optional: Add Redis
For sessions and Celery background tasks:
bash
flyctl redis create --name your-app-name-redis --region iad --no-replicasThen set the Redis secrets:
bash
flyctl secrets set -a your-app-name \
REDIS_URL="redis://..." \
CELERY_BROKER_URL="redis://..." \
CELERY_RESULT_BACKEND="redis://..."Troubleshooting
View Logs
bash
flyctl logs -a your-app-nameSSH into Container
bash
flyctl ssh console -a your-app-nameCheck App Status
bash
flyctl status -a your-app-nameRedeploy Manually
bash
flyctl deploy -a your-app-name