FROM python:3.10-slim # --- Setup User and Environment --- RUN useradd -m -u 1000 user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ DEBIAN_FRONTEND=noninteractive WORKDIR /app # --- Root Dependencies (FFmpeg, patchelf, build tools & CRITICAL IMAGE LIBS) --- USER root RUN apt-get update && apt-get install -y \ build-essential \ pkg-config \ ffmpeg \ libsndfile1 \ libavformat-dev \ libavcodec-dev \ libavdevice-dev \ libavfilter-dev \ libswresample-dev \ libjpeg-dev \ libpng-dev \ zlib1g-dev \ git \ patchelf \ && rm -rf /var/lib/apt/lists/* # --- User Dependencies (Final Stable Stack) --- USER user # Copy requirements before install for better cache management COPY --chown=user ./requirements.txt ./requirements.txt # CRITICAL FIX: Pin pip to an older version (<24.1) to resolve pytorch-lightning 1.6.5 RUN pip install --no-cache-dir pip==24.0 && \ # 1. PyTorch ecosystem (Pinned to 2.1.0) pip install --no-cache-dir \ torch==2.1.0+cpu \ torchvision==0.16.0+cpu \ torchaudio==2.1.0+cpu \ --index-url https://download.pytorch.org/whl/cpu \ && \ # 2. Pyannote ecosystem (Stable stack to fix AudioMetaData) pip install --no-cache-dir \ pyannote.audio==2.1.1 \ pyannote.metrics==3.2 \ pytorch-lightning==1.6.5 \ huggingface-hub \ && \ # 3. WhisperX ecosystem (Stable stack to fix ctranslate2 conflict) pip install --no-cache-dir \ whisperx==3.3.0 \ ctranslate2==4.4.0 \ && \ # 4. Install remaining requirements pip install --no-cache-dir -r requirements.txt # --- Shared Library Patching (Fixes CTranslate2 ImportErrors) --- USER root # CRITICAL FIX: Target ALL shared object files to clear the execstack flag RUN find /home/user/.local/lib/python3.10/site-packages/ -name "*.so*" -exec patchelf --clear-execstack {} \; # Clean up patchelf RUN apt-get remove -y patchelf && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* # --- Final Setup --- USER user COPY --chown=user . /app EXPOSE 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]