FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PORT=7860 \ HOME=/home/user # Create user RUN useradd -m -u 1000 user # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ libpq-dev \ ffmpeg \ git \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Upgrade pip RUN pip install --no-cache-dir --upgrade pip # Step 1: Install CPU-only Torch first (Heavy) # This prevents OOM by not resolving everything at once RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu # Step 2: Install remaining requirements COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy everything else COPY --chown=user:user . . # Final permissions check RUN chown -R 1000:1000 /app USER user EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]