collabSupport/dect-relay-agent/docker-compose.yml
Joseph McQueen e8500b4324 Package dect-relay-agent as a Docker deploy bundle
Adds a one-command packager (`npm run package:relay`) that produces a
self-contained zip ready to transfer into the data center and start
with `docker compose up -d --build`. Three commands on the DC host:
unzip, edit .env, docker compose up.

Why a packager instead of `docker build` in the repo:
The agent's index.js imports the shared cisco-dect + httpDigestAuth
modules via `../integrations/...` paths, so a naive
`docker build dect-relay-agent/` would fail because those files live
outside the build context. The packager copies them into a
`workspace/` tree inside the bundle so the Dockerfile sees them as
local paths without any source rewriting.

Docker artifacts (in dect-relay-agent/):
- Dockerfile: multi-stage node:20-alpine build (~55MB final image),
  non-root `dect` user (UID/GID 1500), tini as PID 1 for clean
  SIGTERM propagation to node's graceful-shutdown path,
  `npm install --omit=dev --ignore-scripts` in the deps stage.
- docker-compose.yml: restart:unless-stopped, JSON log rotation
  (10MB × 5 files), pgrep-based health check. No `ports:` block
  because the agent is outbound-only (dials the bot).
- .dockerignore: defensive — the bundle already excludes cruft, but
  this hardens against a stray manual build.

Packager (scripts/packageDectRelayAgent.js):
- Assembles agent code + shared modules + deploy artifacts into a
  timestamped staging dir (.package-relay-tmp/, git-ignored).
- Generates a bundle README with three-command deploy instructions,
  ongoing-ops table, no-internet-DC fallback (docker save/load), and
  troubleshooting for the most common failure modes.
- Generates BUNDLE_INFO.txt with build metadata (git sha + dirty
  flag + timestamp + size) so the DC operator can trace deployed
  bundles back to source.
- Emits `dist/dect-relay-agent-bundle-<YYYYMMDD-HHMMSS>.zip` (30KB).
- Cleans staging in a finally block so failed runs don't leak.

Bundle layout (matches Dockerfile expectations):
  dect-relay-agent-bundle-<version>/
    Dockerfile, docker-compose.yml, .dockerignore
    .env.example, README.md, BUNDLE_INFO.txt
    workspace/dect-relay-agent/{package.json, index.js}
    workspace/integrations/cisco-dect/{client,probes,statusXml}.js
    workspace/utils/httpDigestAuth.js

Wiring:
- package.json: new `package:relay` and `test` npm scripts.
- .gitignore: `scripts/` changed to `scripts/*` so `!scripts/
  packageDectRelayAgent.js` can re-include just the packager
  (git forbids re-including files under a fully-excluded directory,
  hence the glob form).
- dect-relay-agent/README.md: rewrites deployment section to show
  the Docker path as the recommended production route, with the
  node-directly path kept for local dev.

Verified end-to-end: `npm run package:relay` produces a valid zip
that unpacks to the expected layout in <2s. All 113 existing tests
still pass.
2026-07-03 09:32:26 -04:00

63 lines
2.4 KiB
YAML

# DECT Relay Agent — one-command deploy for the data center.
#
# Deploy flow:
# 1. Unzip the bundle produced by scripts/packageDectRelayAgent.js.
# 2. `cp .env.example .env` and fill it in (bot URL, shared token,
# DECT serviceability password). The .env file lives NEXT TO
# this compose file and is git-ignored.
# 3. `docker compose up -d --build`
# 4. `docker compose logs -f` and confirm you see the bot log
# "Agent connected from ..." on the other side.
#
# The agent is an OUTBOUND client (it dials the bot at
# DECT_RELAY_BOT_URL). No ports are exposed and no inbound firewall
# rules are needed on the DC host — only egress to:
# - the bot's public HTTPS/WSS URL
# - every DBS-210 base station on 10.0.0.0/8 (TCP 443)
services:
dect-relay-agent:
build:
context: .
dockerfile: Dockerfile
image: dect-relay-agent:latest
container_name: dect-relay-agent
# Restart on any exit (crash, host reboot, `docker stop` doesn't
# count). Matches how the rest of the collabSupport stack is run.
restart: unless-stopped
# All runtime config comes from .env — never bake secrets into
# the image. .env is created by the operator from .env.example
# and is git-ignored by convention.
env_file:
- .env
# No `ports:` block on purpose — see header comment.
# Cap log volume so a chatty reconnect loop can't fill /var/log.
# 10MB * 5 files = 50MB per container is plenty for
# troubleshooting a week's worth of activity at info level.
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
# Health check hits the agent's own process. Since the agent
# doesn't expose an HTTP port, we probe by looking for the node
# process — sufficient to catch crashes that the restart policy
# will then fix. A future v2 could expose a tiny /healthz on a
# localhost-only port with connection-state details.
healthcheck:
test: ["CMD-SHELL", "pgrep -f 'node index.js' > /dev/null || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
# Optional: uncomment if your DC network requires host networking
# for the agent to reach the 10.x bases (e.g. because a routed
# docker bridge isn't set up). Adding host mode means the agent
# inherits the host's routing table and IP stack directly.
# network_mode: host