Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
2a9c719baThis file is pinned to the selected release. Download the original to open it in your design tool.
services:
hivescale-api:
# NOTE: CI (.github/workflows/backend-image.yml) publishes the backend as
# ghcr.io/macnite/hivehub — the old hivescale-api image name is no longer
# updated, so pulling it would silently pin you to a stale backend.
image: ghcr.io/macnite/hivehub:latest
depends_on:
hivescale-db:
condition: service_healthy
environment:
# Required secrets — set them in .env (cp .env.example .env). The
# ":?" makes compose fail fast instead of starting with a known default.
API_KEY: '${API_KEY:?set API_KEY in .env (openssl rand -hex 32)}'
HIVEPAL_SERVICE_API_KEY: '${HIVEPAL_SERVICE_API_KEY:-}'
HIVEPAL_JWT_SECRET: '${HIVEPAL_JWT_SECRET:-}'
# Defaults to the bundled hivescale-db service, reusing POSTGRES_PASSWORD
# so the two can never drift apart. Override only for an external DB.
DATABASE_URL: '${DATABASE_URL:-postgresql://hivescale:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@hivescale-db:5432/hivescale}'
# Public base URL used to build OTA firmware download links (HTTPS in
# production). Without it, download URLs are relative and OTA from a
# device will not work.
PUBLIC_BASE_URL: '${PUBLIC_BASE_URL:-}'
TZ: '${TZ:-Europe/Berlin}'
# Built-in login-protected local dashboard at /dashboard (single-owner
# self-host; the first visit runs a setup wizard that creates the admin
# account). It exposes every device on this server behind that login, so
# leave it false on multi-tenant deployments.
ENABLE_LOCAL_DASHBOARD: '${ENABLE_LOCAL_DASHBOARD:-false}'
DASHBOARD_SESSION_SECRET: '${DASHBOARD_SESSION_SECRET:-}'
DASHBOARD_SESSION_TTL_HOURS: '${DASHBOARD_SESSION_TTL_HOURS:-168}'
# Secure by default: the session cookie is only sent over HTTPS, so it can
# never leak over a plain-HTTP hop. This assumes the dashboard is reached
# through the reverse proxy that terminates TLS (the documented setup). Set
# it to false only for plain-HTTP local testing, where a secure cookie
# would otherwise never be sent and login would appear to fail.
DASHBOARD_COOKIE_SECURE: '${DASHBOARD_COOKIE_SECURE:-true}'
# "Publish data": lets a dashboard admin publish ONE chart at a time under
# an unguessable link that is served without a login, for embedding in a
# website (see docs/publish-embed.md). Nothing is public until somebody
# publishes it; set this to false to switch the feature off entirely, at
# which point every already-published link returns 404.
ENABLE_PUBLIC_EMBEDS: '${ENABLE_PUBLIC_EMBEDS:-true}'
# Rate limiter: trust CF-Connecting-IP / X-Forwarded-For for the client
# IP. Off by default because it is only safe when a trusted proxy in front
# of the API overwrites these headers — otherwise a client that can reach
# the API directly can spoof them to bypass the limiter or poison another
# client's bucket. Set this to true once (and only once) the API sits
# behind a reverse proxy / Cloudflare, so per-client rate limiting keys off
# the real client IP instead of the proxy's.
TRUST_PROXY_HEADERS: '${TRUST_PROXY_HEADERS:-false}'
# ── Abuse / DoS protection knobs ──
RATE_LIMIT_ENABLED: '${RATE_LIMIT_ENABLED:-true}'
RATE_LIMIT_DEFAULT: '${RATE_LIMIT_DEFAULT:-120/minute}'
MAX_BODY_BYTES: '${MAX_BODY_BYTES:-262144}'
MAX_FIRMWARE_BYTES: '${MAX_FIRMWARE_BYTES:-16777216}'
# Hive audio (issue #71). One minute of 16 kHz PCM16 is ~1.9 MB and there
# is deliberately NO automatic retention sweep — recordings live until
# somebody deletes them — so this directory grows with use. The cap below
# bounds a SINGLE upload; the node stops itself at 60 s and this is the
# backstop for a hub that does not.
MAX_RECORDING_BYTES: '${MAX_RECORDING_BYTES:-4194304}'
# ── Optional MQTT bridge (Home Assistant etc.) — disabled by default ──
MQTT_ENABLED: '${MQTT_ENABLED:-false}'
MQTT_HOST: '${MQTT_HOST:-localhost}'
MQTT_PORT: '${MQTT_PORT:-1883}'
MQTT_USERNAME: '${MQTT_USERNAME:-}'
MQTT_PASSWORD: '${MQTT_PASSWORD:-}'
MQTT_TLS: '${MQTT_TLS:-false}'
MQTT_CLIENT_ID: '${MQTT_CLIENT_ID:-hivescale-backend}'
MQTT_BASE_TOPIC: '${MQTT_BASE_TOPIC:-hivescale}'
MQTT_QOS: '${MQTT_QOS:-0}'
MQTT_RETAIN: '${MQTT_RETAIN:-true}'
MQTT_HA_DISCOVERY: '${MQTT_HA_DISCOVERY:-true}'
MQTT_HA_DISCOVERY_PREFIX: '${MQTT_HA_DISCOVERY_PREFIX:-homeassistant}'
MQTT_HA_EXPIRE_AFTER: '${MQTT_HA_EXPIRE_AFTER:-0}'
ports:
# Bound to loopback by default so the API is NOT directly reachable from
# the network. Put a reverse proxy (Nginx / Caddy / Cloudflare Tunnel) in
# front of it to terminate TLS and forward to 127.0.0.1:31115 — the
# firmware verifies the backend's certificate, so HTTPS is required anyway.
# To expose the port directly on the LAN instead (not recommended), change
# this to "31115:8000"; if you do, also review TRUST_PROXY_HEADERS and
# DASHBOARD_COOKIE_SECURE above, which assume the loopback + proxy setup.
- "127.0.0.1:31115:8000"
restart: unless-stopped
volumes:
# Uploaded OTA firmware binaries live in FIRMWARE_DIR (/app/firmware).
# Without a volume they are lost on every container recreation while the
# firmware_releases DB rows survive — leaving releases that 404.
- firmware-data:/app/firmware
# Hive audio recordings (RECORDINGS_DIR). Same reasoning as above, and
# more pointed: the hive_recordings rows survive a container recreation,
# so without a volume the dashboard would list sessions whose audio is
# gone. Point this at real disk if you record often — nothing prunes it.
- recordings-data:/app/recordings
hivescale-db:
image: postgres:16-alpine
environment:
POSTGRES_DB: hivescale
POSTGRES_USER: hivescale
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}'
TZ: '${TZ:-Europe/Berlin}'
healthcheck:
test:
- CMD-SHELL
- pg_isready -U hivescale -d hivescale
interval: 30s
timeout: 5s
retries: 5
restart: unless-stopped
volumes:
# Bind-mount a host path for the database. Adjust to your system.
- /mnt/path-to-db-data:/var/lib/postgresql/data
volumes:
firmware-data:
recordings-data: