FROM python:3.12-slim AS builder
WORKDIR /build
RUN apt-get update \
    && apt-get install -y --no-install-recommends build-essential \
    && rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt

FROM python:3.12-slim
WORKDIR /app
RUN apt-get update \
    && apt-get install -y --no-install-recommends ffmpeg \
    && rm -rf /var/lib/apt/lists/*
COPY --from=builder /wheels /wheels
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
COPY app ./app
COPY docker-entrypoint.sh /usr/local/bin/core-cast-entrypoint
RUN chmod 0755 /usr/local/bin/core-cast-entrypoint
ENV CORE_CAST_SETTINGS=/data/core-cast/settings.json \
    CORE_CAST_BIND=127.0.0.1 \
    CORE_CAST_PORT=8091
VOLUME ["/data/core-cast"]
EXPOSE 8091
CMD ["core-cast-entrypoint"]
