Production-ready Flask application with uWSGI, Nginx, and Let's Encrypt SSL certificates, all containerized with Docker.
- Modern Python: Python 3.12 with type hints
- Security First: Talisman security headers, CORS configuration, SSL/TLS support
- Production Ready: uWSGI application server, Nginx reverse proxy
- Automated SSL: Let's Encrypt certificate management with Certbot
- CI/CD Pipeline: GitHub Actions with testing, linting, and security scanning
- Code Quality: Black, isort, flake8, mypy, pre-commit hooks
- Testing: Comprehensive test suite with pytest and coverage
- Monitoring: Structured logging, health checks, error tracking ready
- Docker: Multi-stage builds, security scanning, optimized images
- Docker & Docker Compose
- Python 3.11+ (for local development)
- Domain name (for SSL certificates)
git clone https://github.com/yourusername/yourrepo.git
cd yourrepo
cp .env.example .env
# Edit .env with your configuration
# Build and start all services
docker-compose up --build -d
# View logs
docker-compose logs -f
# Edit domain in init-letsencript.sh
nano init-letsencript.sh
# Run certificate initialization
./init-letsencript.sh
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r flask_app/requirements.txt
# Install pre-commit hooks
pre-commit install
# Run the application
cd flask_app
python app.py
# Run all tests with coverage
pytest
# Run specific test file
pytest tests/test_app.py
# Run with verbose output
pytest -v
# Generate HTML coverage report
pytest --cov-report=html
# Format code with Black
black flask_app/ tests/
# Sort imports
isort flask_app/ tests/
# Lint with flake8
flake8 flask_app/ tests/
# Type checking with mypy
mypy flask_app/
# Run all checks
pre-commit run --all-files
.
βββ flask_app/
β βββ app.py # Main application
β βββ requirements.txt # Python dependencies
β βββ uwsgi.ini # uWSGI configuration
β βββ frontend/
β βββ __init__.py
β βββ routes.py # Route definitions
β βββ api/
β βββ Content.py # API client
βββ tests/
β βββ conftest.py # Pytest configuration
β βββ test_app.py # Application tests
β βββ test_content.py # Content API tests
βββ data/
β βββ nginx/
β β βββ app.conf # Nginx configuration
β βββ certbot/ # SSL certificates
βββ .github/
β βββ workflows/
β βββ ci.yml # CI/CD pipeline
βββ docker-compose.yml # Docker services
βββ Dockerfile # Application container
βββ init-letsencript.sh # SSL setup script
βββ pyproject.toml # Python project config
βββ .pre-commit-config.yaml # Pre-commit hooks
βββ .env.example # Environment template
See .env.example
for all available options:
FLASK_ENV
: Application environment (production/development)SECRET_KEY
: Flask secret key for sessionsAPI_ADDRESS
: External API endpointALLOWED_ORIGINS
: CORS allowed originsDOMAIN
: Your domain for SSL certificatesEMAIL
: Email for Let's Encrypt notifications
- memberxxl_app: Flask application on uWSGI
- nginx: Reverse proxy and static file server
- certbot: SSL certificate management
- Set strong
SECRET_KEY
in.env
- Configure proper
ALLOWED_ORIGINS
- Update domain in
init-letsencript.sh
- Set
FLASK_ENV=production
- Configure monitoring (Sentry, New Relic, etc.)
- Setup backup strategy
- Configure firewall rules
- Enable automatic certificate renewal
# Build and tag image
docker build -t yourusername/flask-app:latest .
# Push to registry
docker push yourusername/flask-app:latest
# Deploy on server
docker-compose pull
docker-compose up -d
GitHub Actions workflow runs on every push and PR:
- Testing: Multiple Python versions, pytest with coverage
- Code Quality: Black, isort, flake8, mypy
- Security: Trivy, Bandit security scanning
- Docker: Build and push to registry (on master)
- Dependencies: Automated vulnerability scanning with Trivy
- Code: Static analysis with Bandit
- Headers: Security headers with Flask-Talisman
- HTTPS: Enforced in production with Let's Encrypt
- Docker: Non-root user, minimal base image
- Secrets: Environment variables, never in code
- Health Check:
/health
endpoint for monitoring - Logging: Structured logs with rotation
- Metrics: Ready for Prometheus/Grafana integration
- Error Tracking: Sentry integration ready
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open Pull Request
- Follow PEP 8 and use Black formatter
- Write tests for new features
- Update documentation
- Pass all CI checks
This project is licensed under the MIT License - see the LICENSE file for details.
- Flask - Web framework
- uWSGI - Application server
- Nginx - Web server
- Let's Encrypt - Free SSL certificates
- Docker - Containerization
For issues and questions:
- Open an issue
- Email: support@example.com
Made with β€οΈ using modern Python and DevOps best practices