FROM python:3.12-slim

WORKDIR /app

# Install system dependencies including Git and WeasyPrint requirements
RUN apt-get update && apt-get install -y \
    git \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libgdk-pixbuf-2.0-0 \
    libffi-dev \
    shared-mime-info \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create necessary directories
RUN mkdir -p data logs uploads/events

# Make entrypoint script executable
RUN chmod +x /app/docker-entrypoint.py

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=wsgi.py
ENV FLASK_ENV=production
ENV LOG_LEVEL=debug

# Expose port
EXPOSE 5000

# Set the entrypoint script
ENTRYPOINT ["python", "/app/docker-entrypoint.py"]

# Run the application with Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "3", "--threads", "2", "--timeout", "60", "--log-level", "info", "--preload", "wsgi:application"]

