# =============================================================================
# Azimuth Tier 1 Node — Docker Compose
# Full setup guide: https://azimuth.day/docs/docker
#
# Quick start:
#   1. curl -LO https://azimuth.day/downloads/azimuth-node-docker-amd64.tar.gz   # or -arm64
#      docker load < azimuth-node-docker-amd64.tar.gz
#   2. curl -LO https://azimuth.day/downloads/docker-compose.yml
#   3. Edit AZIMUTH_API_KEY and the AZIMUTH_NODE_* location values below.
#   4. docker compose up -d
#
# Both the amd64 and arm64 image tarballs load the tags azimuth-node:latest and
# azimuth-node:0.3.0 — pick the tarball for your CPU; the image name is the same.
#
# NOTE: the AZIMUTH_* environment variables are read ONLY on the first startup,
# when the container generates its config file (/var/lib/azimuth/config.toml on
# the azimuth-data volume). Later restarts reuse the saved config so the node
# keeps its identity. To re-generate the config from the environment:
#   docker compose down -v      # WARNING: deletes the volume (node identity!)
#   docker compose up -d
#
# Maintained by the Azimuth team — https://azimuth.day
# =============================================================================

services:
  azimuth-node:
    image: azimuth-node:latest        # or pin the release: azimuth-node:0.3.0
    container_name: azimuth-node
    restart: unless-stopped

    # --- Hardware passthrough ------------------------------------------------
    # The RTL-SDR reaches the container through the USB bus. Remove the devices
    # block to run without hardware (stub mode: container stays up, no captures).
    devices:
      - "/dev/bus/usb:/dev/bus/usb"
      # Optional GPS receiver (timing / Tier 2): uncomment and adjust the path.
      # - "/dev/ttyACM0:/dev/ttyACM0"

    # The container runs as the non-root user `azimuth` (uid 10001). For USB
    # access that user must be in the HOST's USB device group. 46 is the default
    # plugdev gid on Debian/Ubuntu/Raspberry Pi OS — verify yours with:
    #   getent group plugdev            # -> plugdev:x:46:
    #   ls -n /dev/bus/usb/001/         # group column = the gid to use
    group_add:
      - "46"

    # --- Configuration (applied on FIRST startup only — see note above) ------
    environment:
      # Backend API
      AZIMUTH_API_URL: "https://azimuth.day"
      # REQUIRED to register and earn — create a key in the azimuth.day dashboard.
      AZIMUTH_API_KEY: ""

      # Node identity
      AZIMUTH_NODE_ID: ""                    # leave empty: the node auto-registers and saves its assigned id
      AZIMUTH_NODE_LABEL: "my-azimuth-node"  # human-readable name shown in the dashboard
      AZIMUTH_HARDWARE_TYPE: "tier1_rtlsdr"  # tier0_mobile / tier1_rtlsdr / tier2_gpsdo

      # Node location (Tier 1+ nodes are stationary — set your real coordinates)
      AZIMUTH_NODE_LAT: "0.0"                # latitude, decimal degrees
      AZIMUTH_NODE_LON: "0.0"                # longitude, decimal degrees
      AZIMUTH_NODE_ALT: "0.0"                # altitude in meters

      # Daemon behavior
      AZIMUTH_STATUS_BIND: "0.0.0.0:8420"    # status server bind INSIDE the container — keep 0.0.0.0
      AZIMUTH_HEARTBEAT_SECS: "15"           # heartbeat interval, seconds
      AZIMUTH_SUBMIT_SECS: "30"              # observation submission interval, seconds

      # SDR tuning
      AZIMUTH_SDR_SAMPLE_RATE: "2048000"     # sample rate in Hz (2048000 is standard for RTL-SDR)
      AZIMUTH_SDR_GAIN: "-1"                 # -1 = automatic gain control (recommended)

      # Region-specific frequency scanning (v0.3.0+)
      AZIMUTH_REGION: "AUTO"                 # ISO country code (US, DE, JP, ...) or AUTO for worldwide
                                              # See https://azimuth.day/docs/regions for the full list

      # Multi-signal scanner (v0.2.5+): the generated config enables the
      # LTE + DTV + FM scanner by default — no env var needed. To customize
      # (scan mode, weights, frequency lists), edit the persisted config on
      # the volume after first boot and restart:
      #   docker compose cp azimuth-node:/var/lib/azimuth/config.toml .
      #   # edit the [scanning] section (full schema: config.example.toml in the repo)
      #   docker compose cp ./config.toml azimuth-node:/var/lib/azimuth/config.toml
      #   docker compose restart
      # Nodes upgraded from older images keep their existing config untouched.

      # Advanced: where the generated config is written/read. Usually leave
      # unchanged. Mount your own config.toml at this path for full control,
      # including the [ntrip] and [gps] sections — see the guide.
      AZIMUTH_CONFIG_PATH: "/var/lib/azimuth/config.toml"

    # --- Status endpoint -----------------------------------------------------
    # GET /status is UNAUTHENTICATED. It is bound to loopback on the host by
    # default. Change to "8420:8420" only behind an authenticating reverse proxy.
    ports:
      - "127.0.0.1:8420:8420"

    # --- Persistence ---------------------------------------------------------
    # Holds config.toml + node-identity.json so the node keeps its identity
    # across restarts and does not re-register.
    volumes:
      - azimuth-data:/var/lib/azimuth

    # Mirrors the image's built-in HEALTHCHECK; shows in `docker compose ps`.
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8420/status"]
      interval: 30s
      timeout: 5s
      start_period: 20s
      retries: 3

volumes:
  azimuth-data:
