FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Install uv
RUN pip install --no-cache-dir uv

# Install Python dependencies (copy lockfile first for layer caching)
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev

# Add venv to PATH so gunicorn and other scripts are directly accessible
ENV PATH="/app/.venv/bin:$PATH"

# Copy application code
COPY . .

# Create instance directory for SQLite
RUN mkdir -p /app/instance

EXPOSE 5000

CMD gunicorn main:app --bind 0.0.0.0:${PORT:-5000} --workers 2 --timeout 300 --keep-alive 5
