| # FROM python:3.10-slim | |
| # # Add system dependencies for OpenCV + Tesseract OCR | |
| # RUN apt-get update && apt-get install -y \ | |
| # libgl1 \ | |
| # libglib2.0-0 \ | |
| # tesseract-ocr \ | |
| # && rm -rf /var/lib/apt/lists/* | |
| # # Create non-root user (Hugging Face best practice) | |
| # RUN useradd -m -u 1000 user | |
| # USER user | |
| # ENV PATH="/home/user/.local/bin:$PATH" | |
| # WORKDIR /app | |
| # # Copy requirements and install | |
| # COPY --chown=user requirements.txt . | |
| # RUN pip install --no-cache-dir -r requirements.txt | |
| # # Copy app code | |
| # COPY --chown=user . /app | |
| # # Expose port Hugging Face expects | |
| # EXPOSE 7860 | |
| # # Run FastAPI with Uvicorn | |
| # CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |
| # Dockerfile | |
| FROM python:3.10-slim | |
| # + ca-certificates (needed for Postgres TLS) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| WORKDIR /app | |
| # Python deps | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip \ | |
| && pip install --no-cache-dir -r requirements.txt | |
| # App code | |
| COPY --chown=user . /app | |
| # Perf + Ultralytics config dir | |
| ENV OMP_NUM_THREADS=1 \ | |
| OPENBLAS_NUM_THREADS=1 \ | |
| UVICORN_WORKERS=2 \ | |
| YOLO_CONCURRENCY=1 \ | |
| HTTP_MAX_CONNECTIONS=50 \ | |
| DB_POOL_MAX=10 \ | |
| AUTH_CACHE_TTL_SECONDS=45 \ | |
| YOLO_CONFIG_DIR=/tmp/Ultralytics | |
| RUN mkdir -p /tmp/Ultralytics | |
| EXPOSE 7860 | |
| # Run via import string so multi-workers work cleanly | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"] | |