Deploying on Fly.io
Install and launch
# install flyctl (see Fly's docs for your OS), then:
fly auth login
fly launch # detects the app, generates fly.toml and a Dockerfile if needed
fly deploy # builds the image and deploys machines
fly open
fly.toml
app = "pandadev-demo"
primary_region = "lhr"
[build]
[deploy]
release_command = "flask --app wsgi db upgrade"
[env]
FLASK_ENV = "production"
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 1
[[http_service.checks]]
interval = "15s"
timeout = "5s"
method = "GET"
path = "/api/health"
internal_portmust match the port your app listens on.release_commandruns once per deploy before new machines receive traffic: ideal for migrations.- Auto stop/start saves money by stopping idle machines; keep at least one running if cold starts matter.
Secrets
fly secrets set SECRET_KEY=$(python -c "import secrets;print(secrets.token_hex(32))") STRIPE_SECRET_KEY=sk_live_...
fly secrets list # names only, values are never shown
Setting secrets triggers a rolling restart.
Volumes
fly volumes create data --size 3 --region lhr
[mounts]
source = "data"
destination = "/data"
A volume is attached to one machine in one region and is not automatically replicated. Back it up, and prefer managed databases and object storage for important data.
Logs and access
fly logs
fly status
fly ssh console # shell inside a running machine
Exercise
Launch a Dockerised Flask app on Fly.io with a health check, a release command for migrations, secrets set with fly secrets, and a volume mounted for a SQLite-based demo; then switch the demo to a managed Postgres.
Check yourself
- What runs in
release_command, and when? - Why must
internal_portmatch your app? - What are the limits of a Fly volume?
आपकी प्रगति केवल इसी ब्राउज़र में सहेजी जाती है।
समीक्षा के लिए भेजें (10 अंक)