Files
ExecuteR/IaC/compose/docker-compose.yml
Alphaeus Mote b242509675 feat(deploy): bundled Postgres on the internal network by default [skip ci]
docker-compose.yml gains a postgres service (EXECUTER-DB-00001, official
image pinned by major and digest like NATS, INTERNAL network only, no host
port, pg_isready health check, shm_size, runs as PUID:PGID, data in
${STACK_BINDMOUNTROOT}/${STACK_NAME}/Postgres/Data). It is in the "postgres"
Compose profile; COMPOSE_PROFILES in .env turns it on, and the backend waits
for it healthy (depends_on required: false, so SQLite and external databases
start without it). The backend defaults to DATABASE_PROVIDER=postgres with
DATABASE_CONNECTION_STRING and DATABASE_PASSWORD from .env.
docker-compose.postgres-port.yml publishes a host port, opt-in through
POSTGRES_BIND.

deploy.sh decides the database: what .env names when the operator set it;
else SQLite when API/Data/app.db exists (written to .env, with a note on how
to move); else the bundled Postgres, its password generated into .env (and
exported), never regenerated over an existing database. COMPOSE_PROFILES
follows. The decisions are functions that scripts/tests/Test-DeployDatabase.sh
runs on fixtures without Docker. Compose 2.20.2+ is checked; a new .env is
mode 600. New-LocalSecrets.ps1 generates the password for a new .env and
keeps an existing .env's database settings on -Force.

README: deploy, secrets, Compose, database providers, Postgres backups and
pg_restore, and Moving from SQLite to Postgres (migrate-database).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 06:01:01 -05:00

288 lines
13 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#=============================================================================
# ExecuteR - Windows endpoint management control plane
# Agent + NATS-over-WebSocket + ASP.NET Core backend + React (MUI) web console
#=============================================================================
#
# CREDENTIALS:
# Initial admin: generated at first start into /data/initial-admin-password.txt
# (or INITIAL_ADMIN_USERNAME / INITIAL_ADMIN_PASSWORD in .env)
# NATS decentralized auth: seeds generated by scripts/New-LocalSecrets.ps1
# Database: DATABASE_PASSWORD generated into .env by deploy.sh / New-LocalSecrets.ps1
#
# PRODUCTION SETUP:
# 1. ./scripts/New-LocalSecrets.ps1 # generate .env + NATS keys + DB password
# 2. docker compose up -d --build # start postgres, nats, backend, webui
# 3. Point the external reverse proxy at the published host ports below
#
# DATABASE: Postgres by default, the postgres service below on the INTERNAL
# network only. It runs under the "postgres" profile, which COMPOSE_PROFILES
# in .env turns on (deploy.sh keeps it in line with DATABASE_PROVIDER); with
# DATABASE_PROVIDER=sqlite or your own server it is left out and not started.
#
# ENDPOINTS (host-published; front with your external reverse proxy):
# - WebUI: http://<host>:${WEBUI_PORT} -> /
# - Backend API: http://<host>:${BACKEND_PORT} -> /api/*
# - NATS WebSocket: ws://<host>:${NATS_WS_PORT} -> /messaging/agent,/messaging/browser
# - Postgres: not published (docker-compose.postgres-port.yml, opt-in)
#
#=============================================================================
name: '${STACK_NAME:-stk-executer-00001}'
networks:
EXTERNAL:
name: EXECUTER-EXTERNAL
driver: bridge
internal: false
attachable: true
INTERNAL:
name: EXECUTER-INTERNAL
driver: bridge
internal: true
attachable: true
services:
postgres:
# The bundled database. Only on the INTERNAL network and never published:
# the backend reaches it as postgres:5432. docker-compose.postgres-port.yml
# (deploy.sh adds it when POSTGRES_BIND is set) publishes a host port.
# The server major is pinned: a new major needs pg_upgrade or a dump and
# restore, and the backend image's pg_dump (POSTGRES_CLIENT_MAJOR) follows it.
image: '${POSTGRES_IMAGE:-postgres}:${POSTGRES_VERSION:-18-trixie@sha256:e3d24f6906d0760bf4da0dae872415391ededefad23fd471c47dc53b0ddf3c42}'
profiles: ['postgres']
container_name: EXECUTER-DB-00001
restart: unless-stopped
# SIGINT is Postgres' fast shutdown; a big checkpoint gets a minute.
stop_signal: SIGINT
stop_grace_period: 60s
shm_size: '256mb'
logging:
driver: 'local'
networks:
INTERNAL:
expose:
- '5432'
# Runs as the stack's user like the backend, so the data tree deploy.sh
# prepares (and chowns) is its own; the image's nss_wrapper covers a uid
# without a passwd entry.
user: "${PUID:-1000}:${PGID:-1000}"
environment:
POSTGRES_DB: 'executer'
POSTGRES_USER: 'executer'
# Set once, when the data folder is first initialised; empty refuses to initialise.
POSTGRES_PASSWORD: '${DATABASE_PASSWORD:-}'
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
# Postgres 18+ keeps its cluster in <mount>/18/docker, so a later major can sit beside it.
- "${STACK_BINDMOUNTROOT:-/mnt/data/docker/stacks}/${STACK_NAME:-stk-executer-00001}/Postgres/Data:/var/lib/postgresql:rw"
healthcheck:
# Over TCP: the first start's initialisation server listens on the socket only.
test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-p", "5432", "-U", "executer", "-d", "executer"]
start_period: 60s
interval: 10s
retries: 6
timeout: 5s
labels:
com.centurylinklabs.watchtower.enable: '${POSTGRES_ENABLEAUTOMATICUPDATES:-false}'
diun.enable: '${POSTGRES_ENABLEAUTOMATICUPDATES:-false}'
wud.watch: '${POSTGRES_ENABLEAUTOMATICUPDATES:-false}'
dockhand.update: '${POSTGRES_ENABLEAUTOMATICUPDATES:-false}'
nats:
image: '${NATS_IMAGE:-nats}:${NATS_VERSION:-2.12-alpine@sha256:7cef1bd3fed6034e95cf6e6bc9c28c5afa6dc58e9fb778dd7924a1ac62569f2d}'
container_name: EXECUTER-NATS-00001
command: ["-c", "/etc/nats/nats.conf"]
restart: unless-stopped
stop_signal: SIGTERM
stop_grace_period: 30s
logging:
driver: 'local'
networks:
INTERNAL:
EXTERNAL:
expose:
- '4222'
ports:
# WebSocket listener — the external reverse proxy maps /messaging/* here.
- '${BIND_EXTERNAL_ADDRESS:-0.0.0.0}:${NATS_WS_PORT:-19222}:9222'
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ../../src/Infra/nats/nats.conf:/etc/nats/nats.conf:ro
- ../../secrets/nats/resolver.conf:/etc/nats/resolver.conf:ro
- "${STACK_BINDMOUNTROOT:-/mnt/data/docker/stacks}/${STACK_NAME:-stk-executer-00001}/NATS/JetStream:/data/jetstream:rw"
- "${STACK_BINDMOUNTROOT:-/mnt/data/docker/stacks}/${STACK_NAME:-stk-executer-00001}/NATS/Resolver:/data/resolver:rw"
healthcheck:
test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8222/healthz"]
start_period: 20s
interval: 10s
retries: 5
timeout: 5s
labels:
com.centurylinklabs.watchtower.enable: '${NATS_ENABLEAUTOMATICUPDATES:-false}'
diun.enable: '${NATS_ENABLEAUTOMATICUPDATES:-false}'
wud.watch: '${NATS_ENABLEAUTOMATICUPDATES:-false}'
dockhand.update: '${NATS_ENABLEAUTOMATICUPDATES:-false}'
backend:
# Published image by default; `build` is the fallback used when the image
# is not present locally and cannot be pulled (pull_policy: missing).
# scripts/deploy.sh pulls first and builds only if the pull fails.
# Tags: X.Y.Z (a release), latest (newest main), X.Y.Z.N (a main build
# between releases), dev and X.Y.Z.N-dev (other branches).
image: '${REGISTRY:-prod.git.gracesolution.info/gsadmin}/${BACKEND_IMAGE:-executer-backend}:${BACKEND_VERSION:-${UNIFIED_VERSION:-latest}}'
pull_policy: '${IMAGE_PULL_POLICY:-missing}'
container_name: EXECUTER-API-00001
build:
context: ../..
dockerfile: src/Infra/backend/Dockerfile
args:
UNIFIED_VERSION: ${UNIFIED_VERSION:-0.0.0.0}
restart: unless-stopped
stop_signal: SIGTERM
stop_grace_period: 30s
depends_on:
nats:
condition: service_healthy
# The bundled database when its profile is on. required: false lets
# SQLite and your own database start without it (Compose 2.20.2+).
postgres:
condition: service_healthy
required: false
logging:
driver: 'local'
networks:
INTERNAL:
EXTERNAL:
expose:
- '8080'
ports:
- '${BIND_EXTERNAL_ADDRESS:-0.0.0.0}:${BACKEND_PORT:-19080}:8080'
# Operators remap with PUID/PGID when volume ownership requires it.
user: "${PUID:-1000}:${PGID:-1000}"
environment:
ASPNETCORE_URLS: 'http://0.0.0.0:8080'
# postgres (the bundled service above) | sqlite (DATABASE_PATH) | sqlserver.
DATABASE_PROVIDER: '${DATABASE_PROVIDER:-postgres}'
DATABASE_PATH: '/data/app.db'
# The bundled one: Host=postgres;Port=5432;Database=executer;Username=executer (in .env).
DATABASE_CONNECTION_STRING: '${DATABASE_CONNECTION_STRING:-}'
DATABASE_PASSWORD: '${DATABASE_PASSWORD:-}'
# Backups from Settings › Database (SQLite, Postgres): inside the /data bind mount below.
DATABASE_BACKUP_PATH: '${DATABASE_BACKUP_PATH:-/data/backups}'
NATS_URL: 'nats://nats:4222'
LOG_LEVEL: '${LOG_LEVEL:-Information}'
LOG_JSON: '${LOG_JSON:-0}'
LOG_DIRECTORY: '${LOG_DIRECTORY:-/data/logs}'
LOG_RETAIN_FILES: '${LOG_RETAIN_FILES:-7}'
LOG_MAX_BYTES: '${LOG_MAX_BYTES:-10485760}'
DEVICE_ORPHAN_AFTER_DAYS: '${DEVICE_ORPHAN_AFTER_DAYS:-30}'
TRUST_PROXY: '${TRUST_PROXY:-1}'
TRUSTED_PROXIES: '${TRUSTED_PROXIES:-}'
TRUSTED_NETWORKS: '${TRUSTED_NETWORKS:-}'
TRUSTED_HOSTS: '${TRUSTED_HOSTS:-}'
TLS_SELF_SIGNED: '${TLS_SELF_SIGNED:-0}'
TLS_CERT_DIR: '${TLS_CERT_DIR:-}'
# Your own certificate (file only in a container): mount it read-only and point TLS_CERT_FILE at it.
TLS_CERT_SOURCE: '${TLS_CERT_SOURCE:-}'
TLS_CERT_FILE: '${TLS_CERT_FILE:-}'
TLS_CERT_KEY_FILE: '${TLS_CERT_KEY_FILE:-}'
TLS_CERT_PASSWORD: '${TLS_CERT_PASSWORD:-}'
TLS_DISTRIBUTE_CA: '${TLS_DISTRIBUTE_CA:-}'
FORWARD_LIMIT: '${FORWARD_LIMIT:-1}'
PUBLIC_SERVER_URL: '${PUBLIC_SERVER_URL:-}'
INITIAL_ADMIN_USERNAME: '${INITIAL_ADMIN_USERNAME:-}'
INITIAL_ADMIN_PASSWORD: '${INITIAL_ADMIN_PASSWORD:-}'
# The OIDC callback path is fixed at /api/auth/oidc/callback (shown in the UI).
OIDC_ENABLED: '${OIDC_ENABLED:-0}'
OIDC_AUTHORITY: '${OIDC_AUTHORITY:-}'
OIDC_CLIENT_ID: '${OIDC_CLIENT_ID:-}'
OIDC_CLIENT_SECRET: '${OIDC_CLIENT_SECRET:-}'
OIDC_PROVIDER_NAME: '${OIDC_PROVIDER_NAME:-}'
OIDC_SCOPES: '${OIDC_SCOPES:-openid profile email}'
OIDC_NAME_CLAIM: '${OIDC_NAME_CLAIM:-}'
OIDC_ROLE_CLAIM: '${OIDC_ROLE_CLAIM:-}'
OIDC_ADMIN_ROLE: '${OIDC_ADMIN_ROLE:-}'
OIDC_OPERATOR_ROLE: '${OIDC_OPERATOR_ROLE:-}'
OIDC_VIEWER_ROLE: '${OIDC_VIEWER_ROLE:-}'
OIDC_DEFAULT_ROLE: '${OIDC_DEFAULT_ROLE:-Operator}'
OIDC_REQUIRE_MAPPED_ROLE: '${OIDC_REQUIRE_MAPPED_ROLE:-0}'
AUTH_LOGIN_MODE: '${AUTH_LOGIN_MODE:-Both}'
AUTH_FORCE_LOCAL: '${AUTH_FORCE_LOCAL:-0}'
NATS_ACCOUNT_SIGNING_SEED: '${NATS_ACCOUNT_SIGNING_SEED:-}'
NATS_ACCOUNT_PUBLIC_KEY: '${NATS_ACCOUNT_PUBLIC_KEY:-}'
AGENT_PACKAGE_PATH: '${AGENT_PACKAGE_PATH:-/data/agent}'
# The built-in store runs inside this container, with its files under /data.
S3_EMBEDDED: '${S3_EMBEDDED:-1}'
S3_ENABLED: '${S3_ENABLED:-0}'
S3_ENDPOINT: '${S3_ENDPOINT:-}'
S3_REGION: '${S3_REGION:-us-east-1}'
S3_BUCKET: '${S3_BUCKET:-}'
S3_ACCESS_KEY: '${S3_ACCESS_KEY:-}'
S3_SECRET_KEY: '${S3_SECRET_KEY:-}'
S3_FORCE_PATH_STYLE: '${S3_FORCE_PATH_STYLE:-1}'
S3_PRESIGN_EXPIRY_SECONDS: '${S3_PRESIGN_EXPIRY_SECONDS:-900}'
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- "${STACK_BINDMOUNTROOT:-/mnt/data/docker/stacks}/${STACK_NAME:-stk-executer-00001}/API/Data:/data:rw"
# Out-of-band agent updates: drop a new Agent.msi / Agent.zip (and an
# optional VERSION marker) into this host folder and it is served
# immediately — it wins over the package baked into the image, so no
# new backend build is needed.
- "${STACK_BINDMOUNTROOT:-/mnt/data/docker/stacks}/${STACK_NAME:-stk-executer-00001}/API/AgentPackage:/data/agent:rw"
healthcheck:
test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/api/health"]
start_period: 30s
interval: 10s
retries: 5
timeout: 5s
labels:
com.centurylinklabs.watchtower.enable: '${BACKEND_ENABLEAUTOMATICUPDATES:-false}'
diun.enable: '${BACKEND_ENABLEAUTOMATICUPDATES:-false}'
wud.watch: '${BACKEND_ENABLEAUTOMATICUPDATES:-false}'
dockhand.update: '${BACKEND_ENABLEAUTOMATICUPDATES:-false}'
webui:
image: '${REGISTRY:-prod.git.gracesolution.info/gsadmin}/${WEBUI_IMAGE:-executer-webui}:${WEBUI_VERSION:-${UNIFIED_VERSION:-latest}}'
pull_policy: '${IMAGE_PULL_POLICY:-missing}'
container_name: EXECUTER-WEB-00001
build:
context: ../..
dockerfile: src/Infra/webui/Dockerfile
args:
UNIFIED_VERSION: ${UNIFIED_VERSION:-0.0.0.0}
restart: unless-stopped
stop_signal: SIGTERM
stop_grace_period: 30s
logging:
driver: 'local'
networks:
EXTERNAL:
expose:
- '3000'
ports:
- '${BIND_EXTERNAL_ADDRESS:-0.0.0.0}:${WEBUI_PORT:-13080}:3000'
# Operators remap with PUID/PGID when volume ownership requires it.
user: "${PUID:-1000}:${PGID:-1000}"
environment:
PORT: '3000'
NODE_ENV: 'production'
ORIGIN: '${PUBLIC_SERVER_URL:-http://localhost:13080}'
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
healthcheck:
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
start_period: 20s
interval: 10s
retries: 5
timeout: 5s
labels:
com.centurylinklabs.watchtower.enable: '${WEBUI_ENABLEAUTOMATICUPDATES:-false}'
diun.enable: '${WEBUI_ENABLEAUTOMATICUPDATES:-false}'
wud.watch: '${WEBUI_ENABLEAUTOMATICUPDATES:-false}'
dockhand.update: '${WEBUI_ENABLEAUTOMATICUPDATES:-false}'