Spaces:
Sleeping
Sleeping
| # Build Stage | |
| FROM python:3.10-slim as builder | |
| WORKDIR /app | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE 1 | |
| ENV PYTHONUNBUFFERED 1 | |
| # Install system dependencies required for building python packages | |
| # ffmpeg is needed for audio processing | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| gcc \ | |
| ffmpeg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install python dependencies | |
| COPY requirements.txt . | |
| RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt | |
| # Final Stage | |
| FROM python:3.10-slim | |
| WORKDIR /app | |
| # Install runtime dependencies (ffmpeg) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy wheels from builder | |
| COPY --from=builder /app/wheels /wheels | |
| COPY --from=builder /app/requirements.txt . | |
| # Install dependencies from wheels | |
| RUN pip install --no-cache /wheels/* | |
| # Copy application code | |
| COPY . . | |
| # Create a non-root user | |
| RUN addgroup --system app && adduser --system --group app | |
| USER app | |
| # Expose port | |
| EXPOSE 8000 | |
| # Run commands | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] | |