services:
  app:
    build:
      context: .
    container_name: portail-associations-app
    init: true
    depends_on:
      db:
        condition: service_healthy
    environment:
      NODE_ENV: production
      PORT: 3000
      DATABASE_URL: ${DATABASE_URL:-mysql://portail:portail_password@db:3306/portail_associations}
      JWT_SECRET: ${JWT_SECRET:-local-dev-change-me}
      ADMIN_EMAIL: ${ADMIN_EMAIL:-selectakeke973@gmail.com}
      BOOTSTRAP_ADMIN_EMAIL: ${BOOTSTRAP_ADMIN_EMAIL:-}
      BOOTSTRAP_ADMIN_PASSWORD: ${BOOTSTRAP_ADMIN_PASSWORD:-}
      BOOTSTRAP_ADMIN_NAME: ${BOOTSTRAP_ADMIN_NAME:-}
      BOOTSTRAP_USERS: ${BOOTSTRAP_USERS:-}
      SMTP_PROVIDER: ${SMTP_PROVIDER:-}
      SMTP_HOST: ${SMTP_HOST:-}
      SMTP_PORT: ${SMTP_PORT:-}
      SMTP_USER: ${SMTP_USER:-}
      SMTP_PASS: ${SMTP_PASS:-}
      SMTP_FROM: ${SMTP_FROM:-}
      SMTP_SECURE: ${SMTP_SECURE:-}
      SMTP_REQUIRE_TLS: ${SMTP_REQUIRE_TLS:-}
      APP_BASE_URL: ${APP_BASE_URL:-http://localhost:3000}
      APP_READY_DELAY_MS: ${APP_READY_DELAY_MS:-8000}
      GRACEFUL_SHUTDOWN_TIMEOUT_MS: ${GRACEFUL_SHUTDOWN_TIMEOUT_MS:-20000}
      MAINTENANCE_FLAG_PATH: ${MAINTENANCE_FLAG_PATH:-/app/uploads/system/maintenance.flag}
      ENTREPRISE_API_TOKEN: ${ENTREPRISE_API_TOKEN:-}
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET:-}
      FACEBOOK_APP_ID: ${FACEBOOK_APP_ID:-}
      FACEBOOK_APP_SECRET: ${FACEBOOK_APP_SECRET:-}
    ports:
      - "3000:3000"
    volumes:
      - portail_associations_uploads:/app/uploads
    command: sh -c "pnpm exec drizzle-kit migrate && exec pnpm start"
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:3000/health/ready | grep '\"ok\":true' >/dev/null"]
      interval: 10s
      timeout: 4s
      retries: 12
      start_period: 25s
    stop_grace_period: 25s
    restart: unless-stopped

  db:
    image: mysql:8.4
    container_name: portail-associations-db
    environment:
      MYSQL_DATABASE: portail_associations
      MYSQL_USER: portail
      MYSQL_PASSWORD: portail_password
      MYSQL_ROOT_PASSWORD: root_password
    ports:
      - "3307:3306"
    volumes:
      - portail_associations_mysql:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "portail", "-pportail_password"]
      interval: 5s
      timeout: 5s
      retries: 20
    restart: unless-stopped

volumes:
  portail_associations_mysql:
  portail_associations_uploads:
