backend/deploying-flask/SKILL.md
Prepare and deploy the Flask application to a production environment using Gunicorn, Docker, and Nginx.
npx skillsauth add 7a336e6e/skills deploying-flaskInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Deploy a hardened, production-ready Flask application served by a WSGI server (Gunicorn) behind a reverse proxy (Nginx), preferably containerized with Docker.
flask run).Ensure the application loads configuration from environment variables, not hardcoded files.
# config.py
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
DEBUG = False
TESTING = False
Never use the built-in Flask development server in production. Use Gunicorn.
Create a gunicorn_config.py:
workers = 4 # 2 * CPU cores + 1
bind = "0.0.0.0:8000"
accesslog = "-"
errorlog = "-"
timeout = 120
keepalive = 5
Create a Dockerfile optimized for size and security.
FROM python:3.11-slim-buster
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Run as non-root user
RUN useradd -m myuser
USER myuser
CMD ["gunicorn", "--config", "gunicorn_config.py", "app:create_app()"]
Use Nginx to handle SSL termination, static files, and request buffering.
# nginx.conf snippet
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://flask_app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
requirements.txt with exact versions.FLASK_ENV (or FLASK_DEBUG) to production (or 0)./health) should verify DB connectivity.flask run in production. It is single-threaded and not secure..env files to the repository.latest tag for base images; pin to a specific version (e.g., python:3.11-slim).Dockerfilegunicorn_config.pydocker-compose.yml (optional, for orchestration)requirements.txt with gunicorn../scaffolding-flask/SKILL.md../../shared/environment-config/SKILL.mddevelopment
Implement features using the Red-Green-Refactor cycle to ensure testability and correctness from the start.
data-ai
Manage the `tasks.md` ledger with strict locking and collision avoidance protocols to allow multiple agents to work in parallel safely.
development
The git-workflow skill defines branching conventions, commit message formats, and pull request standards that all agents must follow for consistent version control.
development
The environment-config skill standardizes how agents manage environment variables, secrets, and application configuration across local development and deployed environments.