FROM python:3.12-slim

WORKDIR /app

# Install system dependencies including Git
RUN apt-get update && apt-get install -y \
    git \
    && 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

# 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

# Expose the port
EXPOSE 5058

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

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