Files
Heimdall/docs/docker-compose.md
T

270 lines
15 KiB
Markdown
Raw Normal View History

# Docker Compose deployment
The required stack is PostgreSQL and Heimdall Central. The Agent is deployed
separately on each camera-network host; the Central UI supplies a
digest-pinned Agent Compose file for each site. RustFS, ntfy, Ollama, TURN,
Redis and scheduled backups have separate Compose files and can be left out.
## Central and database
For a new Linux server, run the interactive installer directly from the source
repository; cloning the repository is not required:
```bash
2026-11-04 20:55:14 +01:00
SOURCE_BASE_URL="${HEIMDALL_SOURCE_BASE_URL:-https://sources.tordais.cc/arnaud.dartois/Heimdall/raw/branch/main}"
curl -fsSL "$SOURCE_BASE_URL/install/install-server.sh" | HEIMDALL_SOURCE_BASE_URL="$SOURCE_BASE_URL" bash
```
2026-10-28 06:38:24 +01:00
The installer uses `eltruncho/heimdall:latest` from Docker Hub, creates a
minimal Central + PostgreSQL Compose project, and configures the maintained
`nickfedor/watchtower` fork to check the explicitly labelled Central container
every 24 hours. Watchtower uses `--cleanup` to remove the previous Central
image after updating; it does not remove PostgreSQL data or named volumes.
`pull_policy: always` also makes each `docker compose up` pull the configured
images, including optional service Compose files. It generates PostgreSQL and JWT secrets locally and writes them to a
mode-600 `.env` and secret file in the chosen installation directory. It asks
which optional services to prepare and whether to start each one. Selected
optional Compose files and backup scripts are fetched individually; no
repository checkout is created. Integration URLs and credentials remain
configured in Central's UI. The script requires an interactive terminal and
reads prompts from it even when downloaded with a pipe.
Running either installer again in the same directory offers to refresh the
generated Compose. It first validates the new file, saves the previous one as
`docker-compose.yml.bak.<timestamp>`, and replaces it. Existing `.env`, secret
files, and Docker volumes are preserved. If the new Compose requires an env
key that is missing, the installer adds a generated secret or a default value
without changing existing entries. It does not rotate the PostgreSQL password;
the existing secret file and `DATABASE_URL` must remain paired. Declining the
update leaves the installation unchanged. Inspect custom Compose edits in the
backup before deciding whether to carry them into future generated versions.
If you choose an optional service again, its refreshed Compose or script asset
also gets a timestamped backup before replacement.
Watchtower needs access to `/var/run/docker.sock`, which grants broad control
over the Docker host. The upstream project describes itself for homelabs and
similar setups and does not recommend it for commercial/production workloads;
automatic latest-tag updates also do not provide staged rollout or rollback.
For stricter production change control, disable/remove the Watchtower service
and deploy a reviewed image digest through an orchestrator or release process.
On Windows 10/11 with Docker Desktop in Linux-container mode, use PowerShell to
download and run the matching installer without cloning the repository:
```powershell
2026-11-04 20:55:14 +01:00
$sourceBase = if ($env:HEIMDALL_SOURCE_BASE_URL) { $env:HEIMDALL_SOURCE_BASE_URL.TrimEnd('/') } else { 'https://sources.tordais.cc/arnaud.dartois/Heimdall/raw/branch/main' }
$installer = Join-Path $env:TEMP 'heimdall-install-server.ps1'
2026-11-04 20:55:14 +01:00
Invoke-WebRequest -UseBasicParsing -Uri "$sourceBase/install/install-server.ps1" -OutFile $installer
Set-ExecutionPolicy -Scope Process Bypass -Force
& $installer
Remove-Item $installer
```
The execution-policy bypass applies only to the current PowerShell process; a
Group Policy can still block script execution. Both installers generate secrets
2026-11-04 20:55:14 +01:00
locally and keep them in the selected installation directory. The scripts use the
source URL shown above by default. To pin a reviewed revision, set
`HEIMDALL_SOURCE_BASE_URL` to its `raw/commit/<SHA>` URL before downloading and
running the installer; this also selects optional Compose and backup files. An
offline installation must provide those selected assets.
The repository's `docker/docker-compose.prod.yml` is a manual alternative for
2026-10-28 06:38:24 +01:00
operators who need a custom layout. It includes the same scoped Watchtower
service and pull policies. Keep `docker/.env` private (mode 600) and create a
PostgreSQL password file; its value must match the password in `DATABASE_URL`.
The `.env.example` file contains development credentials and must not be used
unchanged for a production deployment.
```sh
umask 077
mkdir -p -m 700 docker/secrets
db_password="$(openssl rand -hex 32)"
printf '%s' "$db_password" > docker/secrets/db_password
cat > docker/.env <<EOF
POSTGRES_DB=heimdall
POSTGRES_USER=heimdall
DATABASE_URL=Host=postgresql;Port=5432;Database=heimdall;Username=heimdall;Password=${db_password}
JWT__KEY=$(openssl rand -hex 32)
JWT__REFRESHKEY=$(openssl rand -hex 32)
JWT__ISSUER=heimdall
JWT__AUDIENCE=heimdall-api
ASPNETCORE_ENVIRONMENT=Production
WEB_PORT=5000
RECORDING_STORAGE_QUOTA_MAX_BYTES=1099511627776
Cors__AllowedOrigins=https://heimdall.example.org
EOF
unset db_password
# Replace the example origin above with the public origin of your Central.
# The recording quota defaults to 1 TiB (1099511627776 bytes).
docker compose --env-file docker/.env -f docker/docker-compose.prod.yml up -d
```
Central images also include Tesseract OCR and its English language data. The
manual license-plate crop reader is opt-in and defaults to disabled. Core and
production Compose files, plus both server installer templates, map
`PLATE_OCR_ENABLED` to Central's `PlateOcr__Enabled` option. Installer-generated
`.env` files set it to `false`; set `PLATE_OCR_ENABLED=true` and recreate the
Central service to enable the feature. Existing installer upgrades preserve an
existing value and add `false` only when the key is absent.
When enabled, an authorized operator can upload a JPEG/PNG plate crop from the
camera detail page. Processing runs on Central; the temporary crop is removed
after processing, while the candidate text and history event are persisted.
The feature limits uploads to 512 KiB and images to four megapixels. It does
not detect plates in video or perform face recognition, and the OCR result is
not a verified identity. Review retention/privacy implications in
[`skills/vision-identity/SKILL.md`](../skills/vision-identity/SKILL.md) before
enabling it.
The development Compose builds Central from the local source and starts only
Central plus PostgreSQL:
```sh
docker compose --env-file docker/.env -f docker/docker-compose.yml up -d
```
For a disposable local installation, copy `.env.example` to an ignored
temporary env file, replace the sample database/JWT values with generated
values, and choose unused loopback ports. Use a unique Compose project name and
`HEIMDALL_NETWORK_NAME`; after checking `/healthz`, stop only that project with
`docker compose -p <project> ... down --volumes --remove-orphans`. Verify its
containers, volumes, and network are gone. Never use `.env.example` unchanged
for an exposed or production deployment. The disposable recipe is maintained
in [`skills/deployment-guide-acceptance/SKILL.md`](../skills/deployment-guide-acceptance/SKILL.md).
## Agent
Prefer the Compose shown in the Central UI's site installation panel. It uses
the image reference and digest from Central's verified release manifest and
includes the site token, public Central URL, Agent name and release public key.
Save it as `docker-compose.yml`, then run `docker compose up -d`. The generated
Compose contains the pinned trust key; no separate PEM file is required. Do
not substitute a mutable image tag for the digest.
The Agent Compose is generated by Central's UI for the selected site; there is
no production Agent Compose in this repository. For local development only,
use `docker/docker-compose.agent.dev.yml` with a development site token and the
local Central URL. The published Agent image uses CPU inference. The optional
NVIDIA, AMD and Intel overlays expose hardware for inventory; they do not
enable GPU inference.
Docker Agents mount `/var/run/docker.sock` so the Agent can pull and replace its
container when Central dispatches an update. This socket grants broad control
of the Docker host, effectively host-administrator access. Keep it only on
hosts where that trust is acceptable. The Agent image includes the Docker CLI
client; it does not run a Docker daemon. Updates preserve the previous image
for rollback if the replacement fails its health check. On Linux, start the
generated Compose with `DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)"
docker compose up -d` so the non-root Agent process can access hosts whose
socket is owned by the Docker group. The UI's `docker run` command determines
this group ID from the host socket automatically.
## Optional software
Start Central first to create the shared `heimdall-net` network. Optional
services then join that network where applicable, so their Compose projects
remain separate while Central can resolve their service names.
```sh
docker compose --env-file docker/.env -f docker/docker-compose.ollama.yml up -d
docker compose --env-file docker/.env -f docker/docker-compose.ntfy.yml up -d
docker compose --env-file docker/.env -f docker/docker-compose.rustfs.yml up -d
docker compose --env-file docker/.env -f docker/docker-compose.coturn.yml up -d
docker compose --env-file docker/.env -f docker/docker-compose.redis.yml up -d
docker compose --env-file docker/.env -f docker/docker-compose.backup.yml up -d
```
Configure Ollama at `http://ollama:11434` in Central's AI settings when enabled.
Choose RustFS as the storage provider in Central and use `http://rustfs:9000` as
its endpoint. Configure the ntfy server URL in Central's notification settings.
Live view can connect directly when ICE succeeds. For clients behind restrictive NAT/firewalls, deploy and validate TURN, then configure its URLs and matching shared secret in Central; without a reachable relay, those clients may not connect.
Redis is provided as a standalone service but is not currently required by
Central. Backups are independent of the core startup and require the core
network and PostgreSQL service to be running.
See [GPU Agent notes](gpu-runtime.md) and
[Agent update signing](agent-release-signing.md) for device access and
trusted-key setup.
## Optional live video with WebRTC
The live-view vertical uses the separately maintained MediaMTX image. It is not
started with the core stack. Configure Central with the public `HEIMDALL_WHEP_URL`
and `HEIMDALL_PUBLISH_RTSPS_URL` (including scheme, host and port only). Provide
`HEIMDALL_MEDIAMTX_AUTH_URL` to the MediaMTX container; when both services share
the default Docker network this can use the Central service name and internal
port. Configure `HEIMDALL_WEBRTC_PUBLIC_HOST`,
`HEIMDALL_WEBRTC_ALLOWED_ORIGIN`, and `HEIMDALL_LIVE_MEDIA_CERT_DIR` for the
public listener and its TLS certificate (`server.crt` and `server.key`). The
certificate must cover both public WHEP and RTSPS hostnames. Open the configured
RTSPS/WHEP TCP ports and WebRTC ICE UDP port in the firewall. Add STUN URLs under
`LiveMedia:IceServers`; for TURN REST credentials set
`LiveMedia:Turn:Urls` and `LiveMedia:Turn:SharedSecret`. Central returns
five-minute HMAC credentials to the browser; the shared secret is never sent.
When using `docker-compose.coturn.yml`, configure the Central secret from the same
protected secret source as `docker/secrets/coturn_secret`; protect the Central
`.env` with owner-only permissions.
Start the core project first so its external `heimdall-net` network exists, then
start MediaMTX with a separate project name:
```sh
docker compose --env-file docker/.env -f docker/docker-compose.webrtc.yml -p heimdall-live up -d
```
Stop only this optional project with `docker compose ... -p heimdall-live down`.
Live publishing requires an assigned Agent and an online, enabled camera. Agent
relays are video-only H.264 passthrough, limited to two simultaneous cameras per
Agent. Central reserves eight viewers per camera and two per user in its process;
use one Central instance until shared reservation storage is configured. A stream
with a browser-incompatible codec is not transcoded. The WHEP read session
expires after ten minutes; the browser deletes the WHEP resource on
stop/navigation. Physical camera and external TURN validation remain deployment
acceptance work.
### Disposable live-view acceptance
For an isolated local playback test, use the local-only override and synthetic
source Compose files. Generate a unique `.env` outside the repository with new
PostgreSQL/JWT secrets, loopback ports, `HEIMDALL_NETWORK_NAME`,
`HEIMDALL_WEBRTC_ALLOWED_ORIGIN`, and
`HEIMDALL_MEDIAMTX_AUTH_URL=http://heimdall:8080/api/live-media/auth`.
Configure `HEIMDALL_WHEP_URL=http://127.0.0.1:<whep-port>`,
`HEIMDALL_PUBLISH_RTSPS_URL=rtsp://127.0.0.1:<publish-port>`,
`HEIMDALL_ALLOW_INSECURE_HTTP=true`,
`HEIMDALL_ALLOW_INSECURE_RTSP=true`, and
`HEIMDALL_WEBRTC_ALLOWED_ORIGIN=http://localhost:<web-port>`. Set
`HEIMDALL_NETWORK_NAME` to a unique network name and select unused values for
`WEB_PORT`, `HEIMDALL_TEST_PUBLISH_PORT`, `HEIMDALL_TEST_WHEP_PORT`,
`HEIMDALL_TEST_ICE_PORT`, `HEIMDALL_SYNTHETIC_RTSP_PORT`, and
`HEIMDALL_TEST_AGENT_PORT`. Insecure protocols are allowed only because all media
ports bind to loopback in this recipe. Then start Central, the local MediaMTX,
and synthetic source from changed source, excluding the Agent until a site token
is available:
```sh
docker compose -p "$project" --env-file "$env_file" \
-f docker/docker-compose.yml \
-f docker/docker-compose.webrtc-local-test.yml \
-f docker/docker-compose.webrtc-test.yml \
up -d --build postgresql heimdall mediamtx synthetic-camera synthetic-camera-publisher
```
Complete first-admin setup, create a site, put its generated test site token in
the disposable `.env`, and start `heimdall-agent` from the same Compose files.
Create and assign an online camera with the synthetic source RTSP URL, then open
its detail page and start live video. Verify an ungranted user is denied, stop
and disable the camera, and check the Agent process and WHEP session are closed.
Use unique ports and the unique network value for each run. Tear down only this
project with `down --volumes --remove-orphans`, confirm its containers, named
volumes and network are gone, and delete its temporary environment/secret files.
This recipe is HTTP/RTSP loopback-only; production configuration remains RTSPS
and HTTPS with a trusted certificate.
A source-built disposable acceptance on 5 November 2026 decoded a 640×360 synthetic
frame through the actual `live-view.js` module in Chromium. WHEP resource deletion
returned 200, Central session release returned 204, and disabling the camera
reduced the Agent publisher count from one to zero. The project teardown left no
containers, volumes, or network. MediaMTX origins and public ICE host must be passed
through its `MTX_WEBRTCALLOWORIGINS` and `MTX_WEBRTCADDITIONALHOSTS` environment
variables; placeholders inside `mediamtx.yml` are not expanded.