Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 GitHub - rafeekpro/Flask-uWSGI-Nginx-Certbot-Docker: Create Flask app with uWSGI, Nginx, Certbot for SSL and all this withΒ docker
Nothing Special   »   [go: up one dir, main page]

Skip to content

rafeekpro/Flask-uWSGI-Nginx-Certbot-Docker

Repository files navigation

Flask + uWSGI + Nginx + Certbot Docker Application

CI/CD Pipeline Python Version Code style: black License: MIT

Production-ready Flask application with uWSGI, Nginx, and Let's Encrypt SSL certificates, all containerized with Docker.

πŸš€ Features

  • 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

πŸ“‹ Prerequisites

  • Docker & Docker Compose
  • Python 3.11+ (for local development)
  • Domain name (for SSL certificates)

πŸ› οΈ Quick Start

1. Clone the repository

git clone https://github.com/yourusername/yourrepo.git
cd yourrepo

2. Setup environment

cp .env.example .env
# Edit .env with your configuration

3. Start with Docker

# Build and start all services
docker-compose up --build -d

# View logs
docker-compose logs -f

4. Setup SSL certificates (Production)

# Edit domain in init-letsencript.sh
nano init-letsencript.sh

# Run certificate initialization
./init-letsencript.sh

πŸ’» Local Development

Setup development environment

# 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 tests

# 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

Code formatting and linting

# 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

πŸ“ Project Structure

.
β”œβ”€β”€ 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

πŸ”§ Configuration

Environment Variables

See .env.example for all available options:

  • FLASK_ENV: Application environment (production/development)
  • SECRET_KEY: Flask secret key for sessions
  • API_ADDRESS: External API endpoint
  • ALLOWED_ORIGINS: CORS allowed origins
  • DOMAIN: Your domain for SSL certificates
  • EMAIL: Email for Let's Encrypt notifications

Docker Services

  • memberxxl_app: Flask application on uWSGI
  • nginx: Reverse proxy and static file server
  • certbot: SSL certificate management

🚒 Deployment

Production Checklist

  • 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

Docker Hub Deployment

# 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

πŸ§ͺ CI/CD Pipeline

GitHub Actions workflow runs on every push and PR:

  1. Testing: Multiple Python versions, pytest with coverage
  2. Code Quality: Black, isort, flake8, mypy
  3. Security: Trivy, Bandit security scanning
  4. Docker: Build and push to registry (on master)

πŸ” Security

  • 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

πŸ“Š Monitoring

  • Health Check: /health endpoint for monitoring
  • Logging: Structured logs with rotation
  • Metrics: Ready for Prometheus/Grafana integration
  • Error Tracking: Sentry integration ready

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Development Standards

  • Follow PEP 8 and use Black formatter
  • Write tests for new features
  • Update documentation
  • Pass all CI checks

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Support

For issues and questions:


Made with ❀️ using modern Python and DevOps best practices

About

Create Flask app with uWSGI, Nginx, Certbot for SSL and all this withΒ docker

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
0