File size: 4,089 Bytes
7cb1544
 
 
 
901ebd3
7cb1544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
901ebd3
7cb1544
 
 
 
901ebd3
 
7cb1544
 
 
 
 
 
 
 
 
 
901ebd3
7cb1544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6a42b4
 
bc094db
af3ea02
 
 
7cb1544
 
 
 
 
 
 
 
 
 
901ebd3
7cb1544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# =========================================================================
# 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"]