Spaces:
Sleeping
Sleeping
| FROM python:3.12-slim | |
| # Create non-root user | |
| RUN useradd -m -u 1000 user | |
| WORKDIR /code | |
| # Copy requirements first (better caching) | |
| COPY ./requirements.txt /code/requirements.txt | |
| # Install system dependencies (ffmpeg, git, build tools) | |
| USER root | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| git \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir --upgrade pip \ | |
| && pip install --no-cache-dir -r /code/requirements.txt \ | |
| && pip install --no-cache-dir gunicorn uvicorn | |
| # Fix permissions | |
| RUN chown -R user:user /code | |
| # Switch to non-root user | |
| USER user | |
| # Copy project files | |
| COPY --chown=user:user . /code | |
| # Add local bin to PATH | |
| ENV PATH="/home/user/.local/bin:${PATH}" | |
| # Environment variables | |
| ENV HOST=0.0.0.0 | |
| ENV PORT=7860 | |
| ENV WORKERS=1 | |
| ENV TIMEOUT=120 | |
| # Run setup (clone repo) once, then start Gunicorn | |
| CMD python main.py && \ | |
| gunicorn -k uvicorn.workers.UvicornWorker app:app \ | |
| --workers ${WORKERS} \ | |
| --bind ${HOST}:${PORT} \ | |
| --timeout ${TIMEOUT} | |