CoolFace
Apppublic

thenuke02/cs2-analyzer

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
Dockerfile101 linesDownload Raw Back to root
1# =============================================================================2# OpenSight CS2 Analyzer - Multi-Stage Docker Build3# Optimized for Hugging Face Spaces deployment4# =============================================================================5 6# -----------------------------------------------------------------------------7# Stage 1: Build Stage8# Install dev tools, compile Rust extensions (demoparser2), build dependencies9# -----------------------------------------------------------------------------10FROM python:3.11-slim AS builder11 12WORKDIR /build13 14# Install build dependencies for compiling Rust extensions and native modules15RUN apt-get update && apt-get install -y --no-install-recommends \16    gcc \17    g++ \18    cargo \19    rustc \20    libffi-dev \21    && rm -rf /var/lib/apt/lists/*22 23# Create virtual environment24RUN python -m venv /opt/venv25ENV PATH="/opt/venv/bin:$PATH"26 27# Upgrade pip and install build tools28RUN pip install --no-cache-dir --upgrade pip wheel setuptools29 30# Copy requirements and install all dependencies from requirements.txt31# This is the single source of truth for dependencies32COPY requirements.txt .33 34# Install all dependencies from requirements.txt35# awpy includes demoparser2 which has Rust bindings that need compilation36RUN pip install --no-cache-dir -r requirements.txt37 38# =============================================================================39# CRITICAL: Verify essential packages are installed (fail build if missing)40# =============================================================================41RUN echo "Verifying critical packages..." && \42    pip show awpy || (echo "CRITICAL: awpy not installed!" && exit 1) && \43    pip show fastapi || (echo "CRITICAL: fastapi not installed!" && exit 1) && \44    pip show uvicorn || (echo "CRITICAL: uvicorn not installed!" && exit 1) && \45    pip show pandas || (echo "CRITICAL: pandas not installed!" && exit 1) && \46    pip show anthropic || (echo "CRITICAL: anthropic not installed!" && exit 1) && \47    echo "All critical packages verified"48 49# -----------------------------------------------------------------------------50# Stage 2: Runtime Stage51# Minimal image with only runtime dependencies52# -----------------------------------------------------------------------------53FROM python:3.11-slim AS runtime54 55WORKDIR /app56 57# Install only runtime system dependencies (no compilers)58RUN apt-get update && apt-get install -y --no-install-recommends \59    libgomp1 \60    && rm -rf /var/lib/apt/lists/* \61    && apt-get clean62 63# Copy virtual environment from builder64COPY --from=builder /opt/venv /opt/venv65 66# Set up environment67ENV PATH="/opt/venv/bin:$PATH"68ENV PYTHONPATH="/app/src"69ENV PYTHONDONTWRITEBYTECODE=170ENV PYTHONUNBUFFERED=171 72# Copy only necessary source files (not tests, docs, etc.)73COPY src/ ./src/74 75# Create temp directory with proper permissions76RUN mkdir -p /tmp/opensight && chmod 777 /tmp/opensight77 78# Create non-root user with UID 1000 for HF Spaces compatibility79# HF Spaces runs containers as user 1000:100080RUN useradd --create-home --shell /bin/bash --uid 1000 appuser81RUN chown -R appuser:appuser /app /tmp/opensight82USER 100083 84# Expose port 7860 for Hugging Face Spaces85EXPOSE 786086 87# Health check for container orchestration88HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \89    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 190 91# Run uvicorn with optimized settings:92# - 1 worker: Demo parsing is CPU-heavy, multiple workers would compete for CPU93# - log-level warning: Reduce verbose access logs in production94# - timeout-keep-alive 65: Slightly above typical load balancer timeout (60s)95CMD ["uvicorn", "opensight.api:app", \96     "--host", "0.0.0.0", \97     "--port", "7860", \98     "--workers", "1", \99     "--log-level", "warning", \100     "--timeout-keep-alive", "65"]101