# VoxCast Server — GPU transcription server.
# CUDA 12 + cuDNN 9 runtime base (CTranslate2 4.x needs cuDNN 9). CPU-only hosts
# can run the same image; the engine falls back to CPU automatically.
# NOTE: 12.4.x was never published for ubuntu24.04 (needed for python3.12);
# 12.6.3 is the oldest cuDNN-runtime tag on 24.04.
FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONPATH=/opt/voxcast/src \
    VOXCAST_DATA_DIR=/var/lib/voxcast \
    VOXCAST_SERVER_HOST=0.0.0.0 \
    VOXCAST_SERVER_PORT=8590

RUN apt-get update && apt-get install -y --no-install-recommends \
        python3.12 python3.12-venv python3-pip ffmpeg ca-certificates \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/voxcast
RUN python3.12 -m venv /opt/voxcast/venv
ENV PATH="/opt/voxcast/venv/bin:${PATH}"

# Install server deps first (better layer caching).
COPY compute_server/requirements.txt /opt/voxcast/compute_server/requirements.txt
RUN pip install --no-cache-dir -r /opt/voxcast/compute_server/requirements.txt

# The transcription engine + model manager are shared with the desktop client.
COPY src/ /opt/voxcast/src/
COPY compute_server/ /opt/voxcast/compute_server/

RUN mkdir -p /var/lib/voxcast
VOLUME /var/lib/voxcast
EXPOSE 8590

HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 \
    CMD python3.12 -c "import urllib.request,sys; \
        sys.exit(0) if urllib.request.urlopen('http://127.0.0.1:8590/healthz').status==200 else sys.exit(1)"

CMD ["python3.12", "/opt/voxcast/compute_server/server_main.py"]
