FROM python:3.11-slim

SHELL ["/bin/bash", "-c"]

ARG PIP_INDEX_URL=
ARG USE_OFFLINE=0
ENV PIP_NO_CACHE_DIR=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app

WORKDIR /app

COPY requirements.txt ./
COPY offline_wheels/ /opt/offline_wheels/

RUN set -euxo pipefail \
    && if [[ "$USE_OFFLINE" == "1" ]]; then \
         python -m pip install --no-index --find-links /opt/offline_wheels -r requirements.txt; \
       else \
         python -m pip install --upgrade pip \
         && if [[ -n "$PIP_INDEX_URL" ]]; then \
              PIP_INDEX_URL="$PIP_INDEX_URL" python -m pip install -r requirements.txt; \
            else \
              python -m pip install -r requirements.txt; \
            fi; \
       fi

COPY app ./app

EXPOSE 3000

CMD ["gunicorn", "--bind", "0.0.0.0:3000", "app:create_app()"]
