flask_template_codex/DEPLOYMENT.md
2026-08-08 05:37:41 +02:00

2.2 KiB

Deployment Guide

Production Requirements

Use a supported Python version, Gunicorn, TLS termination, and a reverse proxy or managed platform. Never use flask run in production. Flask's official guidance recommends a dedicated WSGI server and commonly a reverse proxy: Flask deployment documentation.

Set environment variables outside the repository:

STEADY_ENV=production
SECRET_KEY=<long-random-secret>
DATABASE_URL=sqlite:////srv/steady/instance/steady.db
TRUSTED_HOSTS=steady.example.com
FEATURE_ADMIN=false

Generate a secret with python -c "import secrets; print(secrets.token_urlsafe(48))". Restrict the instance directory and environment to the service account. SQLite is suitable for a single-host deployment; use platform-managed storage and a database designed for concurrency before horizontal scaling.

Release Procedure

python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
flask --app app db upgrade
python -m pytest
gunicorn --config gunicorn.conf.py wsgi:app

Gunicorn binds to 127.0.0.1:8000 by default. Put TLS and request buffering in a trusted reverse proxy; do not expose the internal bind when the proxy is intended to be mandatory. Configure forwarded headers only for known proxy addresses rather than applying ProxyFix generically.

Operations

  • Probe /health for process availability; it intentionally does not test every dependency.
  • Back up the SQLite database using a consistent database-aware snapshot. Per-user JSON exports are portability backups, not a replacement for server backups.
  • Back up before migrations and test restore procedures regularly.
  • Rotate SECRET_KEY only with a plan to invalidate existing sessions.
  • Review logs without recording passwords, secrets, backup contents, or task descriptions.
  • Confirm HTTPS responses include HSTS and all responses include the configured security headers.
  • Keep FEATURE_ADMIN=false unless the guarded placeholder is explicitly required.

Rollback should restore both the prior application release and its compatible database backup. Do not run destructive schema downgrades without reviewing the generated migration and recovery plan.