diff --git a/ai-service/Dockerfile b/ai-service/Dockerfile index e533ce6..90a7a28 100644 --- a/ai-service/Dockerfile +++ b/ai-service/Dockerfile @@ -1,27 +1,23 @@ # ─── ShootTracker AI Service ────────────────────────────────────────────────── -# Python + FastAPI + YOLOv8 + OpenCV +# Python + FastAPI + YOLOv8 + OpenCV (PyTorch CPU-only, ~200MB) FROM python:3.11-slim -# Dépendances système pour OpenCV (compatibles Debian Bookworm) +# Dépendances système minimales RUN apt-get update && apt-get install -y --no-install-recommends \ - libglib2.0-0 \ - libsm6 \ - libxext6 \ - libxrender1 \ - libgl1 \ - libgomp1 \ - wget \ + libglib2.0-0 libgl1 libgomp1 wget \ && rm -rf /var/lib/apt/lists/* WORKDIR /app -# Copier et installer les dépendances Python -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +# 1. PyTorch CPU-only en premier (index dédié = version légère ~200MB) +RUN pip install --no-cache-dir \ + torch==2.3.0 torchvision==0.18.0 \ + --index-url https://download.pytorch.org/whl/cpu -# Pré-télécharger le modèle YOLOv8n (pour éviter le téléchargement au premier démarrage) -RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')" || echo "Download YOLOv8n on first run" +# 2. Reste des dépendances (pas de torch/torchvision dans requirements.txt) +COPY requirements-api.txt . +RUN pip install --no-cache-dir -r requirements-api.txt # Copier le code COPY . . @@ -33,7 +29,7 @@ ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 # Healthcheck -HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=3 \ +HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=5 \ CMD wget -qO- http://localhost:8000/health || exit 1 EXPOSE 8000 diff --git a/ai-service/requirements-api.txt b/ai-service/requirements-api.txt new file mode 100644 index 0000000..2c26222 --- /dev/null +++ b/ai-service/requirements-api.txt @@ -0,0 +1,10 @@ +fastapi==0.111.0 +uvicorn[standard]==0.30.1 +python-multipart==0.0.9 +pillow==10.3.0 +numpy==1.26.4 +opencv-python-headless==4.9.0.80 +ultralytics==8.2.37 +httpx==0.27.0 +pydantic==2.7.3 +python-dotenv==1.0.1