version: "3.8"

services:
  redis:
    image: redis:alpine
    networks:
      - app_network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3
    deploy:
      restart_policy:
        condition: any

  backend:
    image: mon-backend:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: any
      mode: replicated
      placement:
        constraints: [node.role == manager]
    ports:
      - target: 5000
        published: 5000
        protocol: tcp
        # ❌ SUPPRIMÉ : mode: host
        # En mode ingress par défaut, ce port sera load balancé
    networks:
      - app_network
    environment:
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    depends_on:
      - redis
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
      interval: 10s
      timeout: 5s
      retries: 3

networks:
  app_network:
    driver: overlay
