# docker-compose.production.yml - Configuration pour web-sentinel.taaazzz-prog.fr
version: '3.8'

networks:
  faildaily-ssl-network:
    external: 
      name: faildaily_faildaily-ssl-network
  web-sentinel:
    driver: bridge

volumes:
  postgres_data:
  redis_data:

services:
  # API Principal
  web-sentinel-api:
    build:
      context: ../..
      dockerfile: deployment/Dockerfile.api
    container_name: web-sentinel-api
    restart: unless-stopped
    environment:
      - DATABASE_URL=postgresql://websentinel_user:${POSTGRES_PASSWORD}@web-sentinel-db:5432/websentinel_prod
      - WEB_SENTINEL_POSTGRES_URL=${DATABASE_URL}
      - WEB_SENTINEL_LICENSE_BACKEND=postgresql
      - REDIS_URL=redis://web-sentinel-redis:6379/0
      - WEB_SENTINEL_SECRET_KEY=${WEB_SENTINEL_SECRET_KEY}
      - FLASK_ENV=production
    networks:
      - faildaily-ssl-network
      - web-sentinel
    depends_on:
      - web-sentinel-db
      - web-sentinel-redis
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-api.rule=Host(`api.web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-api.tls=true"
      - "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=cors-headers"
      - "traefik.http.middlewares.cors-headers.headers.accesscontrolallowmethods=GET,POST,OPTIONS"
      - "traefik.http.middlewares.cors-headers.headers.accesscontrolalloworiginlist=*"
      - "traefik.http.middlewares.cors-headers.headers.accesscontrolallowheaders=*"

  # Base de données PostgreSQL
  web-sentinel-db:
    image: postgres:15-alpine
    container_name: web-sentinel-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=websentinel_user
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=websentinel_prod
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - web-sentinel
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U websentinel_user -d websentinel_prod"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Redis pour cache et rate limiting
  web-sentinel-redis:
    image: redis:7-alpine
    container_name: web-sentinel-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - web-sentinel
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru

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

  # Serveur d'installation
  web-sentinel-install:
    image: nginx:alpine
    container_name: web-sentinel-install
    restart: unless-stopped
    volumes:
      - ./install:/usr/share/nginx/html:ro
      - ./nginx-install.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - faildaily-ssl-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-install.rule=Host(`install.web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-install.tls=true"
      - "traefik.http.routers.web-sentinel-install.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-install.loadbalancer.server.port=80"

  # Interface web principale (optionnelle)
  web-sentinel-web:
    image: nginx:alpine
    container_name: web-sentinel-web
    restart: unless-stopped
    volumes:
      - ./web:/usr/share/nginx/html:ro
      - ./nginx-web.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - faildaily-ssl-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-web.rule=Host(`web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-web.tls=true"
      - "traefik.http.routers.web-sentinel-web.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-web.loadbalancer.server.port=80"