version: "3.8"

services:
  web:
    image: registry.gitlab.com/taaazzz-prog/missioflow-site:latest
    environment:
      - HOST=0.0.0.0
      - PORT=4321
      - SMTP_HOST=${SMTP_HOST:-ssl0.ovh.net}
      - SMTP_PORT=${SMTP_PORT:-465}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASSWORD=${SMTP_PASSWORD}
      - SMTP_FROM=${SMTP_FROM:-contact@missioflow.fr}
      - CONTACT_TO=${CONTACT_TO:-contact@missioflow.fr}
    networks:
      - traefik-public
    deploy:
      replicas: 1
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      resources:
        limits:
          memory: 256M
          cpus: "0.50"
        reservations:
          memory: 128M
          cpus: "0.15"
      labels:
        # --- Traefik routing ---
        - "traefik.enable=true"

        # HTTPS - missioflow.fr
        - "traefik.http.routers.missioflow.rule=Host(`missioflow.fr`) || Host(`www.missioflow.fr`)"
        - "traefik.http.routers.missioflow.entrypoints=websecure"
        - "traefik.http.routers.missioflow.tls.certresolver=letsencrypt"
        - "traefik.http.services.missioflow.loadbalancer.server.port=4321"

        # HTTP -> HTTPS redirect
        - "traefik.http.routers.missioflow-http.rule=Host(`missioflow.fr`) || Host(`www.missioflow.fr`)"
        - "traefik.http.routers.missioflow-http.entrypoints=web"
        - "traefik.http.routers.missioflow-http.middlewares=redirect-to-https"

        # .com -> .fr redirect
        - "traefik.http.routers.missioflow-com.rule=Host(`missioflow.com`) || Host(`www.missioflow.com`)"
        - "traefik.http.routers.missioflow-com.entrypoints=websecure"
        - "traefik.http.routers.missioflow-com.tls.certresolver=letsencrypt"
        - "traefik.http.routers.missioflow-com.middlewares=redirect-to-fr"

        - "traefik.http.routers.missioflow-com-http.rule=Host(`missioflow.com`) || Host(`www.missioflow.com`)"
        - "traefik.http.routers.missioflow-com-http.entrypoints=web"
        - "traefik.http.routers.missioflow-com-http.middlewares=redirect-to-fr"

        # Middlewares
        - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
        - "traefik.http.middlewares.redirect-to-https.redirectscheme.permanent=true"

        - "traefik.http.middlewares.redirect-to-fr.redirectregex.regex=^https?://(?:www\\.)?missioflow\\.com/(.*)"
        - "traefik.http.middlewares.redirect-to-fr.redirectregex.replacement=https://missioflow.fr/$${1}"
        - "traefik.http.middlewares.redirect-to-fr.redirectregex.permanent=true"

networks:
  traefik-public:
    external: true
