Deployment
View on GitHubDocumentation / Deployment
Deployment
Getting started runs Looksee on one machine. This page covers a server that other people use: addressing, TLS through a reverse proxy, GPU inference, backups, and upgrades.
A server on your network
Set WEBRTC_HOST_IP in .env to the address users reach the server by, such as 192.168.1.20. Browsers connect to that address for live video, and the default RUNTIME_* URLs point Studio at it. Set the passwords that Getting started lists, then start the stack:
docker compose up -d --build
Studio is at http://192.168.1.20:3000. Browser webcams do not work in this setup: browsers allow camera access only on localhost or over HTTPS, so a webcam workflow needs the TLS setup below.
TLS with a reverse proxy
Terminate TLS in a reverse proxy in front of Studio, the API, and MediaMTX's WebRTC port. The example uses Caddy, which obtains certificates and proxies WebSockets without extra configuration; any proxy that forwards WebSocket upgrades works.
studio.example.com {
handle_path /looksee-api/* {
reverse_proxy 127.0.0.1:8000
}
handle {
reverse_proxy 127.0.0.1:3000
}
}
media.example.com {
reverse_proxy 127.0.0.1:8889
}
Point Studio and the API at the public names in .env:
WEBRTC_HOST_IP=203.0.113.10 # the server's public address, for WebRTC media
RUNTIME_API_URL=https://studio.example.com/looksee-api
RUNTIME_WS_URL=wss://studio.example.com/looksee-api
RUNTIME_MEDIAMTX_WEBRTC_URL=https://media.example.com
CORS_ORIGIN_REGEX=^https://studio\.example\.com$
AUTH_COOKIE_SECURE=true
The proxy targets the default host ports. If you change WEB_PORT, API_PORT, or MTX_WEBRTC_PORT, use the corresponding port in the Caddyfile.
Caddy strips /looksee-api before forwarding HTTP and WebSocket requests to the API. Studio and the API share a public host, so the browser sends the looksee_session cookie when opening Studio pages. Studio checks the session through its internal SERVER_API_URL. WebRTC signalling goes through the proxy. Open MTX_WEBRTC_ICE_PORT (default 8189) on the firewall for UDP media sent directly to WEBRTC_HOST_IP.
Restart the affected services after editing .env:
docker compose up -d
GPU inference
The inference image built by Compose runs models on the CPU. ONNX Runtime prefers CUDA when it is available, and the looksee-inference package has a gpu extra that installs onnxruntime-gpu instead of onnxruntime. The Dockerfile exposes two build arguments for this:
| Argument | Default | Purpose |
|---|---|---|
TARGET | cpu | Which extra to install: cpu or gpu |
BASE_IMAGE | python:3.12-slim-trixie | Base image; a GPU build needs one with the CUDA runtime and cuDNN that match the ONNX Runtime release, plus Python 3.12 |
Build and run with a Compose override that passes the GPU through:
# compose.gpu.yaml
services:
inference:
build:
args:
TARGET: gpu
BASE_IMAGE: <cuda base image with python 3.12>
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
docker compose -f compose.yaml -f compose.gpu.yaml up -d --build inference
The host needs the NVIDIA driver and the NVIDIA Container Toolkit. On startup the inference log lists the execution providers ONNX Runtime found; CUDAExecutionProvider confirms the GPU is in use.
Sizing
Detection cost is the number of model runs per second across all cameras: the sum of every Detect node's Checks per second. Decoding cost depends on the stream resolution and frame rate, independent of detection. Two levers keep a CPU deployment comfortable:
- Use camera substreams at 720p or lower.
- Keep Checks per second at 1 to 2 unless the scenario needs more.
Raise INFERENCE_CPUS and INFERENCE_MEMORY as cameras are added. The API, PostgreSQL, and Valkey are light by comparison. Run one API replica: filter state and cooldowns live in the API's memory.
Backups
From the deployed checkout, stop writers and make a backup outside the repository. pg_dump uses the database and role configured in the running PostgreSQL container. docker compose cp reads the signing key and uploaded videos from this project's stopped service containers. Run the steps in the same shell and keep the directory printed at the end.
umask 077
backup_dir=$(mktemp -d ../looksee-backup.XXXXXXXX)
docker compose stop
docker compose up -d --wait postgres
docker compose exec -T postgres sh -ec 'exec pg_dump -Fc -U "$POSTGRES_USER" -d "$POSTGRES_DB"' > "$backup_dir/looksee.dump"
docker compose exec -T postgres pg_restore --list < "$backup_dir/looksee.dump" > /dev/null
docker compose cp -a api:/data/keys/. - > "$backup_dir/api_keys.tar"
docker compose cp -a storage:/data/. - > "$backup_dir/storage_data.tar"
printf '%s\n' "$backup_dir"
To include evidence images, also archive the snapshots volume before restarting the API.
docker compose cp -a api:/data/snapshots/. - > "$backup_dir/api_snapshots.tar"
Keep a private copy of .env and any custom bundles in models/ with the backup. For external S3 storage, back up the bucket separately. After a routine backup, resume the same release with docker compose up -d. For an upgrade, leave the application stopped and follow the instructions below.
To restore into a fresh installation, use the saved configuration and database role. Set backup_dir to the backup directory. Create the destination service containers and load the archives before starting the application.
docker compose create --build api storage
docker compose up -d --wait postgres
docker compose exec -T postgres sh -ec 'exec pg_restore --exit-on-error --single-transaction -U "$POSTGRES_USER" -d "$POSTGRES_DB"' < "$backup_dir/looksee.dump"
docker compose cp -a - api:/data/keys < "$backup_dir/api_keys.tar"
docker compose cp -a - storage:/data < "$backup_dir/storage_data.tar"
if [ -f "$backup_dir/api_snapshots.tar" ]; then
docker compose cp -a - api:/data/snapshots < "$backup_dir/api_snapshots.tar"
fi
Start the restored release with docker compose up -d. If the restore is part of an upgrade from 0.3.0, complete the retention step below first.
Upgrades
Read the changelog and make a backup from the old checkout. Leave the API stopped and PostgreSQL running. Upgrade the API, inference and Studio from the same Looksee commit. Compose pins MediaMTX to its own compatible upstream version.
Save the old commit, record the user and workflow counts, and stop PostgreSQL. Continue only after the backup and these commands succeed.
git rev-parse HEAD > "$backup_dir/looksee-commit"
docker compose exec -T postgres sh -ec 'exec psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT (SELECT count(*) FROM users) AS users, (SELECT count(*) FROM workflows) AS workflows"'
docker compose stop postgres
Switch the checkout to the 0.4.0 release.
git fetch --tags origin
git switch --detach v0.4.0
PostgreSQL 18 to 19
If the installation already uses PostgreSQL 19, keep its current volume, run docker compose up -d --wait postgres, and continue with retention.
For PostgreSQL 18, set POSTGRES_VOLUME_NAME in .env to a new, unused volume unique to this installation, for example looksee_pg19_data. Keep the previous Compose project name, database role, database name, and other volumes. Start only PostgreSQL 19, restore the dump and compare the counts with the values recorded on 18.
docker compose up -d --wait postgres
docker compose exec -T postgres sh -ec 'exec pg_restore --exit-on-error --single-transaction -U "$POSTGRES_USER" -d "$POSTGRES_DB"' < "$backup_dir/looksee.dump"
docker compose exec -T postgres sh -ec 'exec psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT (SELECT count(*) FROM users) AS users, (SELECT count(*) FROM workflows) AS workflows"'
Keep the original PostgreSQL 18 volume and the dump. To roll back before accepting new writes, stop the stack, return to the commit saved in looksee-commit, restore the previous volume setting in .env, and start the old stack.
Retention on upgrade
After an upgrade from 0.3.0, the first cleanup removes snapshots, alerts and finished deliveries older than 30 days by default. The three former *_RETENTION_DAYS variables no longer set these periods. To preserve older evidence, keep the API stopped, apply migration 0003, and set the policy before the first cleanup. The example keeps all three categories indefinitely. Substitute the previous number of days for each category to retain a custom policy.
docker compose run --rm --build --no-deps api-migrate
docker compose exec -T postgres sh -ec 'exec psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"' <<'SQL'
INSERT INTO retention_settings (id, snapshots_days, alerts_days, deliveries_days)
VALUES (1, 0, 0, 0)
ON CONFLICT (id) DO NOTHING;
SQL
After verifying the restore and selecting the retention policy, start the full stack and check the service states. The owner can adjust each period later in Settings → Retention.
docker compose up -d --build
docker compose ps -a
Native services
For development, the infrastructure can run in containers while the services run from the source tree. The repository's CONTRIBUTING.md describes that setup.