# Multi-stage Docker build untuk FunCaptcha Server di HF Spaces # Optimasi untuk ukuran minimal dan performa maksimal FROM python:3.11-slim as base # Install system dependencies + tools untuk ONNX Runtime fix RUN apt-get update && apt-get install -y \ curl \ libglib2.0-0 \ libgomp1 \ gcc \ g++ \ make \ cmake \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Set working directory WORKDIR /app # Copy requirements dan installer scripts COPY requirements.txt . COPY install-onnx.py . # Make installer executable RUN chmod +x install-onnx.py # Install Python dependencies tanpa ONNX Runtime dulu RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir fastapi==0.104.1 uvicorn[standard]==0.24.0 opencv-python-headless==4.8.0.76 numpy==1.24.3 pillow==10.0.1 pyyaml==6.0.1 python-multipart==0.0.6 python-jose[cryptography]==3.3.0 structlog==23.2.0 && \ pip cache purge # Try aggressive ONNX Runtime installation (non-blocking) RUN python install-onnx.py || echo "⚠️ ONNX Runtime installation failed, continuing with degraded mode" # Copy aplikasi COPY . . # Set environment variables untuk optimasi + Aggressive ONNX Runtime fix ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV OMP_NUM_THREADS=1 ENV MKL_NUM_THREADS=1 ENV OPENBLAS_NUM_THREADS=1 ENV NUMEXPR_NUM_THREADS=1 ENV ORT_DISABLE_ALL_OPTIMIZATION=1 ENV ONNXRUNTIME_LOG_SEVERITY_LEVEL=3 ENV ORT_ENABLE_CPU_FP16=0 ENV ORT_DISABLE_CPU_EP_FALL_BACK=1 ENV ORT_FORCE_DISABLE_CPU_FP16=1 # Expose port EXPOSE 7860 # Health check untuk monitoring HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Run aplikasi CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]