services:
  aibroker-ota:
    build:
      context: ./ota
      dockerfile: Dockerfile
    container_name: aibroker-ota
    # "no", not "unless-stopped". This hub is on-demand: it exists so a PAILot
    # build can reach a device while its owner is away — fire it up, publish,
    # tear it down. "unless-stopped" brought it back on every Docker start, so
    # a service wanted a few times a year was competing for a port at every
    # boot, against a daemon carrying live traffic.
    restart: "no"
    # 8767 — 8765 belongs to the daemon's PAILot MQTT broker, which is
    # launchd-managed and therefore always holds it first.
    ports:
      - "127.0.0.1:8767:8767"
    volumes:
      - ${HOME}/.aibroker/ota:/data
    environment:
      - DATA_DIR=/data
      - PORT=8767
      - AIBROKER_OTA_PUBLISHERS=${AIBROKER_OTA_PUBLISHERS:-}
      - TRUST_HEADER=${TRUST_HEADER:-true}
    user: "${UID}:${GID}"
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8767/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    deploy:
      resources:
        limits:
          memory: 256M
