# docker-compose.websentinel.yml
version: '3.8'

services:
  web-sentinel-api:
    build: 
      context: ../..
      dockerfile: deployment/Dockerfile.api
    container_name: web-sentinel-api
    restart: unless-stopped
    environment:
      - FLASK_ENV=production
      - WEB_SENTINEL_SECRET_KEY=${WEB_SENTINEL_SECRET_KEY}
      - DATABASE_URL=${DATABASE_URL}
      - REDIS_URL=${REDIS_URL}
    volumes:
      - ./data:/app/data
      - ./logs:/app/logs
      - ./config:/app/config:ro
    networks:
      - traefik
      - web-sentinel-internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-api.rule=Host(`api.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-api.entrypoints=websecure"
      - "traefik.http.routers.web-sentinel-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-api.loadbalancer.server.port=5000"
      - "traefik.http.routers.web-sentinel-api.middlewares=auth-api"
      
  # Middleware d'authentification API
  web-sentinel-auth:
    image: nginx:alpine
    container_name: web-sentinel-auth
    volumes:
      - ./nginx/auth.conf:/etc/nginx/nginx.conf:ro
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.auth-api.forwardauth.address=http://web-sentinel-auth/auth"
      
  # Base de données pour les clés API et historique
  web-sentinel-db:
    image: postgres:15-alpine
    container_name: web-sentinel-db
    restart: unless-stopped
    environment:
      - POSTGRES_DB=web_sentinel
      - POSTGRES_USER=websentinel
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    volumes:
      - web-sentinel-db-data:/var/lib/postgresql/data
      - ./init-db:/docker-entrypoint-initdb.d:ro
    networks:
      - web-sentinel-internal
      
  # Cache Redis pour les résultats
  web-sentinel-redis:
    image: redis:7-alpine
    container_name: web-sentinel-redis
    restart: unless-stopped
    command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
    volumes:
      - web-sentinel-redis-data:/data
    networks:
      - web-sentinel-internal

  # Documentation statique
  web-sentinel-docs:
    image: nginx:alpine
    container_name: web-sentinel-docs
    restart: unless-stopped
    volumes:
      - ../../docs:/usr/share/nginx/html:ro
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-docs.rule=Host(`docs.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-docs.entrypoints=websecure"
      - "traefik.http.routers.web-sentinel-docs.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-docs.loadbalancer.server.port=80"

  # Serveur de fichiers pour les scripts d'installation
  web-sentinel-install:
    image: nginx:alpine
    container_name: web-sentinel-install
    restart: unless-stopped
    volumes:
      - ../../install:/usr/share/nginx/html:ro
      - ./releases:/usr/share/nginx/html/releases:ro
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-install.rule=Host(`install.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-install.entrypoints=websecure"
      - "traefik.http.routers.web-sentinel-install.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-install.loadbalancer.server.port=80"

networks:
  traefik:
    external: true
  web-sentinel-internal:
    internal: true

volumes:
  web-sentinel-db-data:
  web-sentinel-redis-data: