| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Dockerfile β BP Monitoring Pipeline (HF Spaces deployment) | |
| # Base: Python 3.11 slim | |
| # Port: 7860 (HF Spaces default) | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| FROM python:3.11-slim | |
| # Metadata | |
| LABEL maintainer="Data Engineering Team" | |
| LABEL description="BP Monitoring Pipeline β FastAPI ETL #1" | |
| LABEL version="1.0.0" | |
| # HF Spaces requires non-root user named 'user' with UID 1000 | |
| RUN useradd -m -u 1000 user | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies for SciPy / asyncpg | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| gcc \ | |
| libpq-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy dependency definitions first (layer caching) | |
| COPY pyproject.toml ./ | |
| # Install Python dependencies (exclude GPU extras in the API container) | |
| RUN pip install --no-cache-dir -e "." && \ | |
| pip install --no-cache-dir uvicorn[standard] | |
| # Copy source code | |
| COPY src/ ./src/ | |
| COPY migrations/ ./migrations/ | |
| COPY alembic.ini ./ | |
| # Change ownership to user | |
| RUN chown -R user:user /app | |
| USER user | |
| # Expose HF Spaces port | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ | |
| CMD python -c "import httpx; httpx.get('http://localhost:7860/health').raise_for_status()" | |
| # Start FastAPI | |
| CMD ["uvicorn", "src.interface.api.app:create_app", "--factory", \ | |
| "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |