FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    APP_DIR=/app

WORKDIR /app

RUN apt-get update \
    && apt-get install --no-install-recommends -y \
        gcc \
        libc6-dev \
        libgomp1 \
        linux-libc-dev \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt \
    && apt-get purge -y gcc libc6-dev linux-libc-dev \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/*

COPY app/ ./app/
COPY migrations/ ./migrations/
COPY alembic.ini ./alembic.ini

EXPOSE 5600

CMD ["/bin/sh", "-c", "alembic -c alembic.ini upgrade head && exec gunicorn --config app/runner/gunicorn_config.py app.runner.wsgi:application"]
