Spaces:
Runtime error
Runtime error
| # Use official Python image | |
| FROM python:3.9-slim as builder | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE 1 | |
| ENV PYTHONUNBUFFERED 1 | |
| ENV PIP_NO_CACHE_DIR 1 | |
| # Install system dependencies | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create and activate virtual environment | |
| RUN python -m venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --upgrade pip && \ | |
| pip install -r requirements.txt | |
| # --- Runtime stage --- | |
| FROM python:3.9-slim | |
| # Copy virtual environment from builder | |
| COPY --from=builder /opt/venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Create non-root user | |
| RUN useradd -m -u 1000 user && \ | |
| mkdir -p /app && \ | |
| chown user:user /app | |
| # Set working directory | |
| WORKDIR /app | |
| USER user | |
| # Copy application files | |
| COPY --chown=user:user . . | |
| # Expose Streamlit port | |
| EXPOSE 8501 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:8501/_stcore/health || exit 1 | |
| # Run application | |
| CMD ["streamlit", "run", "your_app.py", "--server.port=8501", "--server.address=0.0.0.0"] |