fly.toml for easy deployment.
Prerequisites
Deployment steps
Create the app and volume
Run these commands once:The volume is mounted at
/data (configured in fly.toml) and stores:- Uploaded files (menu images, store logos)
- Any persistent data needed by the application
Set secrets
Configure environment variables as Fly.io secrets:Optional SMTP secrets for email:Optional checkout token secret:
Deploy
- Build the Docker image (multi-stage build)
- Push the image to Fly.io’s registry
- Create a new VM with your app
- Run health checks
- Route traffic to the new VM
Configuration reference
CampusBite’sfly.toml is optimized for low-traffic campus deployments:
fly.toml
Key settings
Your unique app name. Must be globally unique across Fly.io.
Region code for your primary deployment. Common options:
bom- Mumbai, Indiasin- Singaporeiad- Ashburn, Virginia (US East)lhr- London, UK
Directory for uploaded files. Maps to the mounted volume.
Port your app listens on (must match
PORT in Dockerfile).Automatically stops machines when not receiving traffic. Ideal for low-traffic campus apps.
Automatically starts machines when receiving traffic. Enables zero-config scaling.
Minimum machines to keep running. Set to
0 for cost savings on low-traffic apps. Increase to 1 for always-on availability.RAM allocated per VM. Options:
256mb, 512mb, 1gb, 2gb, 4gb, 8gb.Volume name (must match the volume created with
fly volumes create).Mount path inside the container. CampusBite expects
/data.Managing your deployment
View logs
Scale resources
Update secrets
SSH into your VM
Access MongoDB from Fly.io
If using MongoDB Atlas, ensure Fly.io IPs are whitelisted:-
Get your app’s outbound IP:
- Add the IPv4 and IPv6 addresses to Atlas Network Access → IP Access List
Continuous deployment
Deploy automatically on every push tomain:
Add token to GitHub secrets
Go to your repository → Settings → Secrets and variables → Actions → New repository secret:
- Name:
FLY_API_TOKEN - Value: (paste the token)
Troubleshooting
Deployment fails with “health checks failed”
Solution: Check logs for startup errors:- Missing required environment variables (JWT_SECRET, MONGODB_URI, etc.)
- MongoDB connection failure
- Port mismatch (app must listen on port 8080)
App crashes immediately after deploy
Solution: Verify all required secrets are set:JWT_SECRETJWT_REFRESH_SECRETMONGODB_URIFRONTEND_URL
Volume not mounting
Solution: Ensure volume name matchesfly.toml:
CORS errors
Solution: VerifyFRONTEND_URL matches your frontend deployment:
Cost optimization
Fly.io’s free tier includes:- Up to 3 shared-cpu-1x 256mb VMs
- 3GB persistent volume storage
- 160GB outbound data transfer
-
Use auto-stop/start: Already configured in
fly.toml -
Optimize volume size: Start with 1GB and increase if needed
-
Monitor usage: