FROM python:3.10-slim

WORKDIR /app

ENV PYTHONUNBUFFERED=1

# Copy requirements first for better caching
COPY requirements.txt .

# Install Python packages with timeout
RUN pip install --no-cache-dir -r requirements.txt \
    --timeout=100 || pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

ENV FLASK_ENV=production
ENV FLASK_APP=run.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_RUN_PORT=5000

EXPOSE 5000

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "run:app"]