FROM python:3.12-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app/src
ENV HF_HOME=/hf
ENV HF_HUB_CACHE=/hf/hub
ENV HUGGINGFACE_HUB_CACHE=/hf/hub
ENV TRANSFORMERS_CACHE=/hf/hub

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    libsndfile1 \
&& rm -rf /var/lib/apt/lists/*

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

COPY src/ ./src/
RUN mkdir -p "$HF_HUB_CACHE" && \
    python -m app.livekit.main download-files

RUN useradd -m -u 1000 agent && chown -R agent:agent /app /hf
USER agent

EXPOSE 8000 18081

ENTRYPOINT ["python", "-m"]
