# Dockerfile.api.stripe - Image API avec système de paiement Stripe et licences
FROM python:3.11-slim

WORKDIR /app

# Installation des dépendances système
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    libpq-dev \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Copie des requirements
COPY requirements.txt requirements-api.txt ./
RUN pip install --no-cache-dir -r requirements.txt -r requirements-api.txt
RUN pip install --no-cache-dir python-dotenv stripe

# Installation du package web_sentinel
COPY setup.py ./
COPY web_sentinel/ ./web_sentinel/
RUN pip install -e .

# Copie des scripts API
COPY web_sentinel_api_honest.py ./
COPY logging_config.py ./

# Création du répertoire pour la base de licences
RUN mkdir -p /root/.web-sentinel

# Exposition du port Flask
EXPOSE 5000

# Variables d'environnement par défaut
ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=web_sentinel_api_with_stripe.py

# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  CMD curl -f http://localhost:5000/api/v1/health || exit 1

# Commande de démarrage avec Gunicorn
CMD ["gunicorn", \
     "--bind", "0.0.0.0:5000", \
     "--workers", "4", \
     "--threads", "2", \
     "--timeout", "120", \
     "--access-logfile", "-", \
     "--error-logfile", "-", \
     "--log-level", "info", \
     "web_sentinel_api_honest:app"]
