Marchelo23/mempool
0
1# =============================================================================2# Bitcoin Mempool Fee Predictor — Hugging Face Spaces Docker3# Multi-stage build for minimal final image4# =============================================================================5 6# --- Stage 1: Builder ---7FROM python:3.11-slim AS builder8 9ENV PYTHONDONTWRITEBYTECODE=1 \10 PYTHONUNBUFFERED=111 12WORKDIR /build13 14# Install build dependencies15RUN apt-get update && apt-get install -y --no-install-recommends \16 build-essential \17 && rm -rf /var/lib/apt/lists/*18 19# Install Python deps into wheels20COPY requirements.txt .21RUN pip wheel --no-cache-dir --no-deps --wheel-dir /build/wheels -r requirements.txt22 23 24# --- Stage 2: Runtime ---25FROM python:3.11-slim26 27LABEL maintainer="Marchelo23" \28 version="3.0.0" \29 description="Bitcoin Mempool Fee Prediction API — XGBoost 2.1 + LightGBM 4.5 Ensemble"30 31ENV PYTHONDONTWRITEBYTECODE=1 \32 PYTHONUNBUFFERED=1 \33 PYTHONPATH=/app \34 ENV=production \35 PORT=786036 37WORKDIR /app38 39# HF Spaces requires user with uid 100040RUN useradd -m -u 1000 user41 42# Runtime dependencies (libgomp1 needed for XGBoost/LightGBM)43RUN apt-get update && apt-get install -y --no-install-recommends \44 libgomp1 \45 curl \46 && rm -rf /var/lib/apt/lists/*47 48# Install wheels from builder49COPY --from=builder /build/wheels /wheels50RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels51 52# Copy application code53COPY --chown=user:user . /app54 55# Ensure directories exist56RUN mkdir -p data models/production logs predictions config \57 && chown -R user:user /app58 59USER user60 61EXPOSE 786062 63# Health check64HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \65 CMD curl -f http://localhost:7860/health || exit 166 67# Start the API on port 7860 (HF Spaces requirement)68CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]69 