services:
  hollowcade:
    build:
      context: .
      args:
        NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-http://localhost:3000}
        NEXT_PUBLIC_CONTACT_EMAIL: ${NEXT_PUBLIC_CONTACT_EMAIL:-}
        NEXT_PUBLIC_LEGAL_ENTITY: ${NEXT_PUBLIC_LEGAL_ENTITY:-}
        NEXT_PUBLIC_LEGAL_JURISDICTION: ${NEXT_PUBLIC_LEGAL_JURISDICTION:-}
        NEXT_PUBLIC_ADMIN_USERNAMES: ${NEXT_PUBLIC_ADMIN_USERNAMES:-admin}
        NEXT_PUBLIC_SUPABASE_URL: ${NEXT_PUBLIC_SUPABASE_URL:-}
        NEXT_PUBLIC_SUPABASE_ANON_KEY: ${NEXT_PUBLIC_SUPABASE_ANON_KEY:-}
    env_file:
      - .env
    ports:
      - "${PUBLISH_APP_PORT:-127.0.0.1:3000}:3000"
    environment:
      NODE_ENV: production
      NEXT_PUBLIC_SITE_URL: ${NEXT_PUBLIC_SITE_URL:-http://localhost:3000}
      NEXT_PUBLIC_CONTACT_EMAIL: ${NEXT_PUBLIC_CONTACT_EMAIL:-contact@example.com}
      NEXT_PUBLIC_LEGAL_ENTITY: ${NEXT_PUBLIC_LEGAL_ENTITY:-HollowCade Operator}
      NEXT_PUBLIC_LEGAL_JURISDICTION: ${NEXT_PUBLIC_LEGAL_JURISDICTION:-the laws of the operator’s jurisdiction}
      NEXT_PUBLIC_ADMIN_USERNAMES: ${NEXT_PUBLIC_ADMIN_USERNAMES:-admin}
      NEXT_PUBLIC_SUPABASE_URL: ${NEXT_PUBLIC_SUPABASE_URL:-}
      NEXT_PUBLIC_SUPABASE_ANON_KEY: ${NEXT_PUBLIC_SUPABASE_ANON_KEY:-}
      HOLLOWCADE_UPLOAD_TOKEN: ${HOLLOWCADE_UPLOAD_TOKEN:-}
      HOLLOWCADE_OPEN_CONTRIBUTE: ${HOLLOWCADE_OPEN_CONTRIBUTE:-0}
      HOLLOWCADE_MAX_UPLOAD_MB: ${HOLLOWCADE_MAX_UPLOAD_MB:-256}
      # PSX disc-pack zips cue+bin in memory — needs headroom for ~700MB bins
      NODE_OPTIONS: ${NODE_OPTIONS:---max-old-space-size=4096}
    volumes:
      # Bind mounts so host `npm run scan-roms` and the running site share the same files.
      # (Named Docker volumes hid host edits — catalog updates never appeared on the site.)
      - ./public/roms:/app/public/roms
      - ./data:/app/data
      - ./public/covers:/app/public/covers
      - ./public/bios:/app/public/bios
    restart: unless-stopped

  caddy:
    profiles: ["caddy"]
    image: caddy:2-alpine
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      SITE_ADDRESS: ${SITE_ADDRESS:-:80}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data
      - caddy-config:/config
    depends_on:
      - hollowcade
    restart: unless-stopped

volumes:
  caddy-data:
  caddy-config:
