version: '3.8'

services:
  # Main website - Next.js standalone
  website:
    image: registry.infra.mintel.me/mintel/mintel.me:latest
    build:
      context: .
      dockerfile: docker/Dockerfile
      args:
        - NEXT_PUBLIC_ANALYTICS_PROVIDER=${NEXT_PUBLIC_ANALYTICS_PROVIDER}
        - NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
        - NEXT_PUBLIC_UMAMI_HOST_URL=${NEXT_PUBLIC_UMAMI_HOST_URL}
        - NEXT_PUBLIC_PLAUSIBLE_DOMAIN=${NEXT_PUBLIC_PLAUSIBLE_DOMAIN}
        - NEXT_PUBLIC_PLAUSIBLE_SCRIPT_URL=${NEXT_PUBLIC_PLAUSIBLE_SCRIPT_URL}
        - NEXT_PUBLIC_GLITCHTIP_DSN=${NEXT_PUBLIC_GLITCHTIP_DSN}
    container_name: mintel-website
    restart: unless-stopped
    # Port 3000 is internal to the docker network, Caddy will proxy to it.
    # We can expose it for debugging if needed, but it's safer to keep it internal.
    expose:
      - "3000"
    environment:
      - NODE_ENV=production
      - REDIS_URL=redis://redis:6379
      - NEXT_PUBLIC_ANALYTICS_PROVIDER=${NEXT_PUBLIC_ANALYTICS_PROVIDER}
      - NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
      - NEXT_PUBLIC_UMAMI_HOST_URL=${NEXT_PUBLIC_UMAMI_HOST_URL}
      - NEXT_PUBLIC_PLAUSIBLE_DOMAIN=${NEXT_PUBLIC_PLAUSIBLE_DOMAIN}
      - NEXT_PUBLIC_PLAUSIBLE_SCRIPT_URL=${NEXT_PUBLIC_PLAUSIBLE_SCRIPT_URL}
      - NEXT_PUBLIC_GLITCHTIP_DSN=${NEXT_PUBLIC_GLITCHTIP_DSN}
    depends_on:
      - redis
    networks:
      - app-network

  # Redis cache for performance
  redis:
    image: redis:7-alpine
    container_name: mintel-redis
    restart: unless-stopped
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 3

  # Caddy reverse proxy with automatic SSL
  caddy:
    image: caddy:2-alpine
    container_name: mintel-caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./docker/Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
      - caddy-config:/config
    environment:
      - DOMAIN=${DOMAIN:-localhost}
      - EMAIL=${ADMIN_EMAIL:-admin@example.com}
    depends_on:
      - website
    networks:
      - app-network

volumes:
  redis-data:
  caddy-data:
  caddy-config:

networks:
  app-network:
    driver: bridge
