Spaces:
Sleeping
Sleeping
| # Stage 1 — Build stage (to install Python dependencies) | |
| FROM python:3.10-slim AS builder | |
| # Set environment vars | |
| ENV VIRTUAL_ENV=/opt/venv | |
| RUN python -m venv $VIRTUAL_ENV | |
| ENV PATH="$VIRTUAL_ENV/bin:$PATH" | |
| # System dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Stage 2 — Final minimal image | |
| FROM python:3.10-slim | |
| # Add non-root user | |
| RUN useradd -m appuser | |
| # Copy venv from builder | |
| COPY --from=builder /opt/venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Set working directory | |
| WORKDIR /home/appuser/app | |
| # Copy app files | |
| COPY --chown=appuser:appuser . . | |
| # Set user to non-root | |
| USER appuser | |
| # Streamlit config to run in HF Spaces | |
| ENV STREAMLIT_SERVER_PORT=7860 | |
| ENV STREAMLIT_SERVER_ENABLECORS=false | |
| ENV STREAMLIT_SERVER_HEADLESS=true | |
| # Expose port (optional — Spaces handles this) | |
| EXPOSE 7860 | |
| # Run Streamlit app | |
| CMD ["streamlit", "run", "app.py"] | |