FROM python:3.12-slim-bookworm

RUN apt-get update \
    && apt-get install -y --no-install-recommends ffmpeg 7zip git ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# unrpyc v2 decompiles .rpyc from Ren'Py 6.18 – 8 on Python 3
ARG UNRPYC_REF=3ae8334ed71a05535927dcc559663d3aca51215b
RUN git init /opt/unrpyc \
    && git -C /opt/unrpyc remote add origin https://github.com/CensoredUsername/unrpyc \
    && git -C /opt/unrpyc fetch --depth 1 origin ${UNRPYC_REF} \
    && git -C /opt/unrpyc checkout --detach FETCH_HEAD \
    && test "$(git -C /opt/unrpyc rev-parse HEAD)" = "${UNRPYC_REF}" \
    && printf '%s' "${UNRPYC_REF}" > /opt/unrpyc/REVISION \
    && rm -rf /opt/unrpyc/.git

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .

ENV PYTHONUNBUFFERED=1 DATA_DIR=/data
CMD ["sh", "-c", "alembic upgrade head && exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --proxy-headers --forwarded-allow-ips='*'"]
