Complete guide for deploying Singularity Edge to Fly.io with automatic GitHub deployments.
- Fly.io Account: Sign up at https://fly.io
- GitHub Repository: Push code to GitHub (e.g.,
singularity-ng/singularity-edge) - Fly.io CLI: Install via Nix shell (
nix develop) or manually
# Authenticate with Fly.io
flyctl auth login
# Create a new app (choose your app name)
flyctl launch --no-deploy
# Follow the prompts:
# - Choose app name: singularity-edge (or your preferred name)
# - Choose region: iad (Washington DC) or closest to you
# - Don't deploy yet: NThis creates fly.toml with your app configuration.
# Generate a deploy token
flyctl tokens create deploy
# Copy the token output- Go to your GitHub repository:
https://github.com/singularity-ng/singularity-edge - Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
FLY_API_TOKEN - Value: Paste the token from step 2
- Click Add secret
If you want faster CI builds:
# Create a Cachix account at https://app.cachix.org
# Create a cache (e.g., "singularity-edge")
# Get your auth token from Settings
# Add to GitHub Secrets:
# Name: CACHIX_AUTH_TOKEN
# Value: <your-cachix-token>The GitHub Actions workflow (.github/workflows/fly-deploy.yml) automatically:
-
Triggers on:
- Push to
mainbranch - Push to
productionbranch - Manual workflow dispatch
- Push to
-
Runs checks (optional):
- Code formatting verification
- Test suite
- Can be extended with more quality gates
-
Deploys to Fly.io:
- Uses
flyctl deploy --remote-only - Builds Docker image on Fly.io's builders
- Performs rolling deployment (zero-downtime)
- Auto-rollback on health check failures
- Uses
# Push your code to GitHub
git add .
git commit -m "feat: initial deployment setup"
git push origin main
# GitHub Actions will automatically deploy!
# Watch the deployment: https://github.com/singularity-ng/singularity-edge/actions# View deployment status
flyctl status
# View logs
flyctl logs
# Open the app
flyctl open
# View dashboard
flyctl dashboardIf you prefer manual deployments:
# Deploy from local machine
flyctl deploy
# Or deploy specific Dockerfile
flyctl deploy --dockerfile Dockerfile
# Deploy to specific region
flyctl deploy --region lhrSet secrets and environment variables:
# Set secret (encrypted)
flyctl secrets set SECRET_KEY_BASE="$(mix phx.gen.secret)"
# Set environment variable
flyctl config set PHX_HOST="your-custom-domain.com"
# List all secrets
flyctl secrets list
# List all config
flyctl config showDeploy globally for low latency:
# View available regions
flyctl platform regions
# Add regions (creates replicas)
flyctl scale count 3 --region iad,lhr,nrt
# Deploy to all regions
flyctl deploy# North America + Europe + Asia
flyctl scale count 6 --region iad,lax,lhr,fra,nrt,syd
# Global coverage (9 regions)
flyctl scale count 9 --region iad,lax,lhr,fra,ams,nrt,syd,sin,gruSingularity Edge uses Mnesia with RocksDB for distributed storage. When you deploy to multiple regions, nodes automatically cluster via libcluster.
-
Deploy to first region:
flyctl deploy --region iad
-
Scale to additional regions:
flyctl scale count 3 --region iad,lhr,nrt
-
Nodes automatically discover each other via Fly.io's 6PN network
-
Mnesia replicates data across all nodes automatically
# SSH into a running machine
flyctl ssh console
# Check connected nodes
bin/singularity_edge remote
# In the Elixir shell:
Node.list() # Should show other region nodes
SingularityEdge.Mnesia.info() # Shows replication status# Upgrade to 1GB RAM, 2 CPUs
flyctl scale vm shared-cpu-2x --memory 1024
# Upgrade to 2GB RAM, 4 CPUs
flyctl scale vm shared-cpu-4x --memory 2048
# Performance tier (dedicated CPU)
flyctl scale vm performance-2x --memory 4096# Scale to 3 machines in current region
flyctl scale count 3
# Scale specific region
flyctl scale count 5 --region iad
# Auto-scaling (coming soon in fly.toml)Health checks are configured in fly.toml:
[[http_service.checks]]
interval = "10s"
timeout = "2s"
grace_period = "30s"
path = "/api/health"If health checks fail, Fly.io automatically rolls back the deployment.
Mnesia data is stored in /app/data/mnesia. For persistence across deployments:
# Create a volume (persistent disk)
flyctl volumes create mnesia_data --size 10 --region iad
# Update fly.toml to mount the volume
# (Already configured in fly.toml)# Add custom domain
flyctl certs add your-domain.com
# Add wildcard certificate
flyctl certs add *.your-domain.com
# View certificate status
flyctl certs list
# Fly.io will automatically provision Let's Encrypt certificates# List recent releases
flyctl releases
# Rollback to specific version
flyctl releases rollback <version># View build logs
flyctl logs --app singularity-edge
# SSH into machine
flyctl ssh console
# Restart app
flyctl apps restart# Check health endpoint locally
curl https://your-app.fly.dev/api/health
# View detailed logs
flyctl logs --app singularity-edge
# Increase grace period in fly.toml
grace_period = "60s"# SSH into machine
flyctl ssh console
# Check Mnesia status
bin/singularity_edge remote
# In Elixir shell:
SingularityEdge.Mnesia.info()
:mnesia.system_info(:running_db_nodes)Fly.io free tier includes:
- Up to 3 shared-cpu-1x machines (256MB RAM)
- 3GB persistent storage
- 160GB outbound data transfer
Perfect for development and small deployments.
Small (< 1000 req/s):
- 3 machines (iad, lhr, nrt)
- shared-cpu-1x, 512MB RAM
- ~$15-20/month
Medium (1000-10000 req/s):
- 6 machines (global coverage)
- shared-cpu-2x, 1GB RAM
- ~$50-70/month
Large (> 10000 req/s):
- 9+ machines (full global)
- performance-2x, 2GB RAM
- ~$150-200/month
# Open web dashboard
flyctl dashboardVisit: https://your-app.fly.dev/admin/dashboard
Shows:
- Request metrics
- Node connectivity
- Backend pool health
- System resources
# Get app metrics
flyctl metrics
# View specific machine metrics
flyctl machine list
flyctl machine status <machine-id># .github/workflows/fly-deploy.yml
on:
push:
branches:
- main # Auto-deploy to staging
- production # Auto-deploy to productionCreate separate apps for staging and production:
# Staging
flyctl launch --name singularity-edge-staging --region iad
# Production
flyctl launch --name singularity-edge-prod --region iadUpdate GitHub Actions to deploy to different apps based on branch.
Add quality gates in .github/workflows/fly-deploy.yml:
- name: Run tests
run: nix develop --command just test
- name: Security audit
run: nix develop --command mix deps.audit