Spaces:
Sleeping
Sleeping
| # ========================================================================= | |
| # Dockerfile — Déploiement HuggingFace Spaces (PostgreSQL + Streamlit) | |
| # | |
| # Architecture : conteneur unique gérant : | |
| # - PostgreSQL 17 (port interne 5432) | |
| # - Streamlit (port 7860, requis par HF Spaces) | |
| # | |
| # Build (depuis la racine du projet) : | |
| # docker build -t nba-analyst-ai . | |
| # | |
| # Run (test local) : | |
| # docker run --env-file .env -p 7860:7860 nba-analyst-ai | |
| # | |
| # Interface accessible sur : http://localhost:7860 | |
| # | |
| # Variables d'environnement requises (Secrets HF Spaces) : | |
| # MISTRAL_API_KEY — clé API Mistral | |
| # POSTGRES_PASSWORD — mot de passe superutilisateur PostgreSQL (admin) | |
| # PG_USER_1_PASSWORD — mot de passe utilisateur read-only (user_1) | |
| # LOGFIRE_TOKEN — (optionnel) token Logfire | |
| # ========================================================================= | |
| FROM python:3.11-slim | |
| # --- Métadonnées ----------------------------------------------------------- | |
| LABEL maintainer="NBA Analyst AI" | |
| LABEL description="Chatbot NBA hybride RAG + SQL (Streamlit + LangGraph + Mistral) — HF Spaces" | |
| # --- Dépendances système --------------------------------------------------- | |
| # postgresql-17 : serveur + outils (initdb, pg_ctl, psql, createdb) | |
| # libgomp1 : requis par FAISS (OpenMP) | |
| # libgl1 + libs : requis par OpenCV / EasyOCR | |
| # curl : healthcheck | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| postgresql-17 \ | |
| postgresql-client-17 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgl1 \ | |
| libgomp1 \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # --- Outils PostgreSQL dans le PATH ---------------------------------------- | |
| ENV PATH="/usr/lib/postgresql/17/bin:$PATH" | |
| # --- Utilisateur non-root UID 1000 (requis par HF Spaces) ----------------- | |
| RUN useradd -m -u 1000 user | |
| # --- Répertoire de travail ------------------------------------------------- | |
| WORKDIR /home/user/app | |
| # --- Installation des dépendances Python ----------------------------------- | |
| COPY --chown=user:user requirements_docker.txt . | |
| RUN pip install --no-cache-dir --upgrade pip \ | |
| && pip install --no-cache-dir -r requirements_docker.txt | |
| # --- Copie du code source -------------------------------------------------- | |
| COPY --chown=user:user MistralChat.py . | |
| COPY --chown=user:user load_excel_to_db.py . | |
| COPY --chown=user:user utils/config.py utils/langgraph_app.py utils/sql_tool.py utils/vector_store.py ./utils/ | |
| COPY --chown=user:user vector_db/ ./vector_db/ | |
| COPY --chown=user:user inputs/ ./inputs/ | |
| # --- Logo (utilisé par Streamlit en tête de page) ------------------------- | |
| COPY --chown=user:user Docs/Logo_SportSee.png ./Docs/ | |
| # --- Configuration Streamlit (thème, serveur) ------------------------------ | |
| COPY --chown=user:user .streamlit/ ./.streamlit/ | |
| # --- Scripts SQL d'initialisation ------------------------------------------ | |
| COPY --chown=user:user SQL_db/schema_relationnel_sql.sql ./sql/01_schema.sql | |
| # --- Script de démarrage --------------------------------------------------- | |
| COPY --chown=user:user start.sh /home/user/start.sh | |
| RUN chmod +x /home/user/start.sh | |
| # --- Variables d'environnement par défaut ---------------------------------- | |
| # PG_HOST/PG_PORT pointent vers PostgreSQL local dans le même conteneur | |
| ENV HOME=/home/user \ | |
| PATH="/usr/lib/postgresql/17/bin:/home/user/.local/bin:$PATH" \ | |
| PG_HOST=127.0.0.1 \ | |
| PG_PORT=5432 \ | |
| PG_DB=oc_mlops_projet_3 \ | |
| PG_ADMIN=admin \ | |
| PGDATA=/home/user/pgdata | |
| # --- Port exposé (7860 requis par HF Spaces) ------------------------------- | |
| EXPOSE 7860 | |
| # --- Passage en utilisateur non-root -------------------------------------- | |
| USER user | |
| # --- Vérification de santé ------------------------------------------------- | |
| HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=5 \ | |
| CMD curl --fail http://localhost:7860/_stcore/health || exit 1 | |
| # --- Point d'entrée -------------------------------------------------------- | |
| CMD ["/home/user/start.sh"] | |