# Déploiement production derrière Traefik (calqué sur la conf "colonel" qui tourne déjà)
# Lancer :  docker compose -f docker-compose.prod.yml --env-file .env.prod up -d --build
# Domaine défini via DOMAIN dans .env.prod (ex. pipe20.schepp.fr pour tester).

services:
  web:
    build: ./docker
    restart: unless-stopped
    volumes:
      - ./site:/var/www/html        # le code (git pull) ; config.php + uploads vivent dedans et persistent
    networks:
      - proxy
      - internal
    depends_on:
      db:
        condition: service_healthy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.pipe20.entrypoints=websecure"
      - "traefik.http.routers.pipe20.rule=Host(`${DOMAIN}`)"
      - "traefik.http.routers.pipe20.tls.certresolver=letsencrypt"
      - "traefik.http.services.pipe20.loadbalancer.server.port=80"

  db:
    image: mysql:8
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - dbdata:/var/lib/mysql
      - ./site/sql/schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro   # importé au 1er démarrage
    networks:
      - internal
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-p${DB_ROOT_PASSWORD}"]
      interval: 5s
      timeout: 5s
      retries: 20

networks:
  proxy:
    external: true        # réseau Traefik déjà existant
  internal:

volumes:
  dbdata:
