Spaces:
Running
Running
| # ======================== | |
| # Stage 1 - Builder | |
| # ======================== | |
| FROM python:3.11-slim AS builder | |
| # Install build dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| gcc \ | |
| g++ \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # Copy only requirements first (better caching) | |
| COPY requirements.txt . | |
| # Install dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # ======================== | |
| # Stage 2 - Final Runtime Image | |
| # ======================== | |
| FROM python:3.11-slim | |
| # Install minimal runtime dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user | |
| RUN useradd --create-home --shell /bin/bash appuser | |
| WORKDIR /app | |
| # Copy installed packages and application code | |
| COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages | |
| COPY --from=builder /usr/local/bin /usr/local/bin | |
| COPY . /app | |
| # Set permissions | |
| RUN chown -R appuser:appuser /app | |
| USER appuser | |
| # Expose port | |
| EXPOSE 7860 | |
| # Set the working directory to the backend folder | |
| WORKDIR /app | |
| # Command to run the FastAPI app | |
| CMD ["sh", "-c", "uvicorn api.app:app --host 0.0.0.0 --port 7860"] |