FROM python:3.11-slim ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # 1. Install system dependencies (root) RUN apt-get update && apt-get install -y \ ffmpeg \ git \ && rm -rf /var/lib/apt/lists/* # 2. Install Python dependencies globally (root). COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 3. Create the unprivileged user and writable cache dir RUN useradd -m -u 1000 user && \ mkdir -p /home/user/.cache/huggingface && \ chown -R user:user /home/user/.cache # 4. Switch context to the unprivileged user USER user ENV HOME=/home/user ENV HF_HOME=/home/user/.cache/huggingface WORKDIR $HOME/app # 5. Pre-cache the 'base' model to avoid runtime downloads/timeouts RUN python -c "from faster_whisper import download_model; download_model('base')" # 6. Copy the application code COPY --chown=user . . EXPOSE 7860 CMD ["python", "backend.py"]