FROM python:3.10-slim RUN apt-get update && apt-get install -y \ libsndfile1 \ ffmpeg \ sox \ curl \ git-lfs \ pkg-config \ libfreetype6-dev \ libpng-dev \ build-essential \ && rm -rf /var/lib/apt/lists/* RUN useradd -m appuser RUN mkdir -p \ /tmp/matplotlib \ /tmp/fontconfig \ /tmp/lhotse \ /app/uploads \ /app/processed_audio \ /app/assets \ /app/temp_files \ /app/static/outputs && \ chown -R appuser:appuser /app /tmp/matplotlib /tmp/fontconfig /tmp/lhotse WORKDIR /app ENV MPLCONFIGDIR=/tmp/matplotlib \ FONTCONFIG_PATH=/tmp/fontconfig \ LHOTSE_CACHE_DIR=/tmp/lhotse \ HF_HUB_ENABLE_HF_TRANSFER=1 \ PYTHONUNBUFFERED=1 # --- OPTIMIZATION: Copy ONLY requirements first to leverage Docker caching --- COPY --chown=appuser:appuser requirements.txt . USER appuser # 7. Install Python dependencies as non-root user USER appuser RUN pip install --upgrade pip && \ pip install Cython==0.29.36 && \ pip install --no-build-isolation youtokentome==1.0.6 && \ pip install --no-cache-dir --prefer-binary -r requirements.txt && \ python -m spacy download en_core_web_sm # --- OPTIMIZATION: Copy the rest of the code AFTER dependencies are installed --- COPY --chown=appuser:appuser . . HEALTHCHECK --interval=30s --timeout=10s \ CMD curl -f http://localhost:7860/health || exit 1 CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]