services:
  meshmonitor:
    image: ghcr.io/yeraze/meshmonitor:latest
    container_name: meshmonitor
    ports:
      - "8081:3001"
      - "4404:4404"
    restart: unless-stopped
    volumes:
      - /mnt/tank/docker/appdata/meshmonitor/data:/data
      - /mnt/docker-ssd/docker/compose/meshtastic/scripts:/data/scripts
    env_file: .env
    environment:
      - NODE_ENV=production
      - TZ=America/Chicago
      - MESHTASTIC_NODE_IP=10.5.1.120
      - TRUST_PROXY=true
      - COOKIE_SECURE=true
      - ALLOWED_ORIGINS=https://meshmonitor.paccoco.com
      - AUTO_UPGRADE_ENABLED=true
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@shared-postgres:5432/meshmonitor
      - PIRATE_WEATHER_API_KEY=${PIRATE_WEATHER_API_KEY}
      - LOCAL_LAT=${LOCAL_LAT}
      - LOCAL_LON=${LOCAL_LON}
      # Rate limiting
      - RATE_LIMIT_API=${RATE_LIMIT_API}
      - RATE_LIMIT_AUTH=${RATE_LIMIT_AUTH}

    networks:
      - default
      - ix-databases_shared-databases
      - pangolin
  meshmonitor-upgrader:
    image: docker:latest
    container_name: meshmonitor-upgrader
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /mnt/tank/docker/appdata/meshmonitor/data:/data
      - .:/compose:ro
    environment:
      - CONTAINER_NAME=meshmonitor
      - IMAGE_NAME=ghcr.io/yeraze/meshmonitor
      - TRIGGER_FILE=/data/.upgrade-trigger
      - STATUS_FILE=/data/.upgrade-status
      - CHECK_INTERVAL=5
      - COMPOSE_PROJECT_DIR=/mnt/docker-ssd/docker/compose/meshtastic
      - COMPOSE_PROJECT_NAME=meshmonitor
    command: /data/.meshmonitor-internal/upgrade-watchdog.sh
    depends_on:
      - meshmonitor
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
  tileserver:
    image: maptiler/tileserver-gl-light:latest
    container_name: meshmonitor-tileserver
    ports:
      - "8082:8080"
    restart: unless-stopped
    volumes:
      - ./tiles:/data
    environment:
      - VERBOSE=true
    command: --verbose
    networks:
      - default
      - pangolin
  mqtt-proxy:
    image: ghcr.io/ln4cy/mqtt-proxy:master
    container_name: meshmonitor-mqtt-proxy
    restart: unless-stopped
    environment:
      - INTERFACE_TYPE=tcp
      - TCP_NODE_HOST=meshmonitor
      - TCP_NODE_PORT=4404
      - LOG_LEVEL=INFO
      - TCP_TIMEOUT=300
      - CONFIG_WAIT_TIMEOUT=60
      - HEALTH_CHECK_ACTIVITY_TIMEOUT=300
    depends_on:
      - meshmonitor
    healthcheck:
      test: ["CMD-SHELL", "test -f /tmp/healthy && find /tmp/healthy -mmin -1 | grep -q healthy"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    networks:
      - default
networks:
  ix-databases_shared-databases:
    external: true
  pangolin:
    external: true
