FROM python:3.13.7-slim-bookworm

ARG WHISPER_CPP_VERSION=v1.9.1

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       build-essential ca-certificates cmake curl ffmpeg git gosu \
    && git clone --branch "${WHISPER_CPP_VERSION}" --depth 1 \
       https://github.com/ggml-org/whisper.cpp.git /opt/whisper.cpp \
    && cmake -S /opt/whisper.cpp -B /opt/whisper.cpp/build \
       -DCMAKE_BUILD_TYPE=Release \
       -DGGML_NATIVE=ON \
       -DWHISPER_BUILD_TESTS=OFF \
       -DWHISPER_BUILD_SERVER=ON \
    && cmake --build /opt/whisper.cpp/build --config Release -j"$(nproc)" \
    && apt-get purge -y --auto-remove build-essential cmake git \
    && rm -rf /var/lib/apt/lists/* /root/.cache \
    && useradd --system --uid 10004 --home-dir /nonexistent --shell /usr/sbin/nologin whisper

WORKDIR /app
COPY router/stt_worker.py /app/stt_worker.py
COPY platform/docker/whisper/entrypoint.sh /usr/local/bin/mike-ai-whisper-entrypoint
RUN chmod 0755 /usr/local/bin/mike-ai-whisper-entrypoint

ENV WHISPER_HOST=0.0.0.0 \
    WHISPER_PORT=8084 \
    WHISPER_CLI=/opt/whisper.cpp/build/bin/whisper-cli \
    WHISPER_MODEL=/models/ggml-small.bin \
    WHISPER_SERVER_URL=http://127.0.0.1:8085 \
    WHISPER_THREADS=8 \
    WHISPER_LANGUAGE=de \
    FFMPEG_BIN=/usr/bin/ffmpeg

VOLUME ["/models"]
EXPOSE 8084
ENTRYPOINT ["/usr/local/bin/mike-ai-whisper-entrypoint"]
