Sign inSign up

nerwander/flask-app-template

By nerwander

โ€ขUpdated 5 months ago

Flask Application Template with Docker Support

Image
0

341

nerwander/flask-app-template repository overview

โ Flask Application Template

A production-ready Flask application template with authentication, Docker support, and CI/CD infrastructure. This template provides a solid foundation for building web applications with modern deployment practices.

โ โœจ Features

  • Session-based Authentication: Secure login system with configurable credentials
  • Docker Support: Multi-stage Docker build for production deployment
  • Production Ready: Gunicorn WSGI server with optimized configuration
  • Health Checks: Built-in health endpoint for container orchestration
  • CI/CD Ready: GitHub Actions workflow templates included
  • Testing Framework: Unit tests and Docker container validation
  • Security: Non-root container execution, secure session management

โ ๐Ÿš€ Quick Start

โ Prerequisites
  • Docker and Docker Compose
  • Python 3.11+ (for local development)
  1. Clone the repository

    git clone <your-repo-url>
    cd flask-app-template
    
  2. Start the application

    docker-compose up --build -d
    
  3. Access the application

    • Open your browser to http://localhost:5000
    • Login with default credentials: user / password
โ Local Development
  1. Install dependencies

    pip install -r requirements.txt
    
  2. Run the application

    python app.py
    

โ โš™๏ธ Configuration

Configure the application using environment variables:

VariableDefaultDescription
APP_USERNAMEuserAuthentication username
APP_PASSWORDpasswordAuthentication password
SECRET_KEYyour-secret-key-change-this-in-productionFlask session secret
โ Docker Compose Configuration
environment:
  - APP_USERNAME=myuser
  - APP_PASSWORD=mypassword
  - SECRET_KEY=your-very-secure-secret-key

โ ๐Ÿ”ง API Endpoints

  • GET / - Main application page (requires authentication)
  • GET /login - Login page
  • POST /login - Authentication endpoint
  • GET /logout - Logout endpoint
  • GET /health - Health check endpoint
  • GET /api/data - Sample API endpoint (requires authentication)

โ ๐Ÿณ Docker Details

โ Multi-Stage Build
  • Builder stage: Compiles dependencies with build tools
  • Runtime stage: Minimal production image (~150MB)
  • Base: Python 3.11 slim for security and size optimization
โ Security Features
  • Non-root user execution
  • Read-only filesystem where possible
  • Minimal attack surface
  • Secure session management

โ ๐Ÿงช Testing

โ Run All Tests
./scripts/test-all
โ Individual Test Components
# Python unit tests
python -m pytest tests/ -v

# Import verification
python tests/test_imports.py

# Docker container tests
./test-docker/test-container.sh

โ ๐Ÿ“ Project Structure

โ”œโ”€โ”€ app.py                 # Main Flask application
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ Dockerfile            # Multi-stage Docker build
โ”œโ”€โ”€ docker-compose.yml    # Development compose file
โ”œโ”€โ”€ gunicorn.conf.py      # Production server configuration
โ”œโ”€โ”€ templates/            # HTML templates
โ”‚   โ”œโ”€โ”€ index.html       # Main page
โ”‚   โ””โ”€โ”€ login.html       # Login page
โ”œโ”€โ”€ tests/               # Test suite
โ”œโ”€โ”€ scripts/             # Automation scripts
โ””โ”€โ”€ test-docker/         # Container testing

โ ๐Ÿš€ Deployment

โ Production Deployment
  1. Set secure environment variables
  2. Use Docker Compose or container orchestration
  3. Configure reverse proxy (nginx, traefik, etc.)
  4. Set up SSL certificates
โ Environment Variables for Production
export APP_USERNAME="your-secure-username"
export APP_PASSWORD="your-secure-password"
export SECRET_KEY="your-very-long-random-secret-key"

โ ๐Ÿ”’ Security Best Practices

  • Change default credentials before deployment
  • Use a strong, random secret key
  • Deploy behind HTTPS
  • Regularly update dependencies
  • Monitor container logs

โ ๐Ÿ†˜ Support

This template provides a solid foundation for Flask applications. Customize it according to your specific needs:

  1. Add your application logic to app.py
  2. Update templates in templates/
  3. Add additional routes and functionality
  4. Extend the test suite
  5. Configure deployment for your environment

โ ๐Ÿ“ License

This template is provided as-is for educational and development purposes.

Tag summary

Content type

Image

Digest

sha256:49e28eb81โ€ฆ

Size

46.3 MB

Last updated

5 months ago

docker pull nerwander/flask-app-template