# =============================================================================
# Formeleon - Multi-tenant Form Generator
# Author: Björn Runden <br@runden.net>
# File: Dockerfile
# Description: Docker container configuration for Formeleon application.
# =============================================================================

# Use official Python runtime as parent image
# Use official Python 3.13 runtime as parent image
FROM python:3.13-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    FLASK_ENV=production \
    FLASK_APP=app.py

# Set working directory
WORKDIR /app

# Install system dependencies (einschließlich curl für Healthcheck)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libpq-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create uploads directory
RUN mkdir -p /tmp/formeleon_uploads && \
    touch /tmp/formeleon_uploads/.gitkeep

# Expose port
EXPOSE 5000

# Health check
HEALTHCHECK --interval=30s --timeout=3s \
    CMD curl -f http://localhost:5000/api/v1/status || exit 1

# Run the application with gthread workers for high concurrency
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "--threads", "2", "--worker-class", "gthread", "app:app"]

# For development (uncomment and use docker-compose)
# CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
