Skip to content
FlyCockpit
Cockpit Context/ Deployment & Backups
Cockpit Context logo

Deployment, Configuration & Backups

Cockpit ContextTypeScript + Landlock LSPMIT
Repository

Deploy Cockpit Context in production with Docker Compose, reverse proxies, Cloudflare Tunnel, environment tuning, and verified Postgres backups.

Platforms: Linux with Docker Compose (Landlock LSP confinement)

Cockpit Context deploys on a Linux host with Docker Compose: one Node.js 26.13.1 application container (app) and one PostgreSQL 18 (postgres:18.6-trixie) container.

Single-Replica Constraint & Network Topology

  • Run exactly one app replica, using stop-first replacement during upgrades. In-process job execution, rate limiters, SSE live streams, and answer/version caches are process-local. Never scale app horizontally or run two app instances against the same database simultaneously.
  • Network isolation: compose.yaml publishes no host ports. PostgreSQL runs exclusively on the Compose project-private internal network under alias cockpit-context-postgres. Only app joins both internal and egress (outbound HTTPS/SSH for OpenRouter, Git hosts, and optional SMTP/S3/OIDC).
  • Unique project name: Always pass a unique Compose project name (such as -p cockpit-context) when sharing a host with other FlyCockpit services. Do not add container_name or global network/volume overrides.

Production Deployment

Clone the repository and prepare .env privately (never use .env.docker.defaults in production):

git clone https://github.com/FlyCockpit/context.git
cd context
cp .env.example .env

Generate strong secrets (pnpm generate:secrets, or openssl rand -hex 32 for POSTGRES_PASSWORD and openssl rand -base64 32 for COCKPIT_CONTEXT_ENCRYPTION_KEYS). Use a hex POSTGRES_PASSWORD because compose.yaml interpolates it directly into DATABASE_URL without URL-escaping.

Note: compose.yaml builds Dockerfile locally by default. Release images are published to ghcr.io/flycockpit/context:<version> by the manual Release workflow; pin by digest for immutable deployments and keep the app and optional backup image tags identical.

First Administrator Bootstrap

You must set ADMIN_EMAILS before first boot. Until the first account exists, only the bootstrap flow can create an account (even if SIGNUP_ENABLED=true):

  1. Start the stack privately before routing public traffic. On startup, the server prints a one-time, in-memory [bootstrap] token to stdout:
    docker compose -p cockpit-context logs app | grep '\[bootstrap\]'
  2. Complete first signup privately. On a plain VPS, temporarily set BETTER_AUTH_URL=https://localhost:8443, COCKPIT_CONTEXT_HTTP_PORT=3036, and TRUST_PROXY_HOPS=1, start with the loopback overlay:
    docker compose -p cockpit-context -f compose.yaml -f compose.vps.yaml up -d --build
    Proxy https://localhost:8443 to 127.0.0.1:3036 with a loopback Caddy listener (tls internal), forward port 8443 over SSH (ssh -N -L 8443:127.0.0.1:8443 deploy@your-server), and visit https://localhost:8443/en-US/signup with your ADMIN_EMAILS address and [bootstrap] token.
  3. Enroll administrator 2FA within the 24-hour grace period and save recovery codes.
  4. Stop the app, set BETTER_AUTH_URL to your final public HTTPS origin, remove the temporary listener, configure public TLS routing, and start the app again.

Warning: If you plan to enable FORCE_SSO=true, leave it unset during bootstrap. Create the administrator first, configure OIDC SSO, sign in once via SSO as that admin (matching verified email) so Better Auth links the identity, and only then enable FORCE_SSO=true.

If an existing database has users but no administrator, promote one directly in PostgreSQL (using lowercase email):

docker compose -p cockpit-context exec postgres psql -U cockpit_context -d cockpit_context \
  -c "UPDATE \"user\" SET role = 'admin' WHERE email = 'you@example.com';"

Reverse Proxy, Dokploy & Cloudflare Tunnel

Every reverse proxy in front of Cockpit Context must satisfy four requirements:

  1. Exact BETTER_AUTH_URL: Set BETTER_AUTH_URL to the exact public HTTPS origin (no trailing path). OAuth issuer (<origin>/api/auth), resource (<origin>/mcp), and cookies all derive from it.
  2. Unbuffered SSE streaming on /mcp and live views: Do not buffer text/event-stream responses. Cockpit Context emits : keepalive comments every 15 seconds, and MCP calls can stay open for up to COCKPIT_CONTEXT_MCP_WAIT_SECONDS (900 seconds by default).
  3. Preserve paths: Forward /mcp, /api/auth/*, and /.well-known/* unchanged.
  4. Accurate TRUST_PROXY_HOPS: Defaults to 0 (ignores X-Forwarded-For). Set 1 behind a single proxy (Traefik/Dokploy, Caddy, or a Cloudflare Tunnel directly to app), or 2 for a Cloudflare Tunnel feeding Traefik/Caddy. Always restrict direct origin access to your proxy chain.

Plain VPS with Caddy

Set COCKPIT_CONTEXT_HTTP_PORT=3036 (avoiding port 3000 if Dokploy uses it) and launch with compose.vps.yaml:

docker compose -p cockpit-context -f compose.yaml -f compose.vps.yaml up -d --build

Configure Caddy with flush_interval -1 so SSE streams flush immediately:

context.example.com {
  reverse_proxy 127.0.0.1:3036 {
    flush_interval -1
  }
}

Dokploy Compose

Create a Dokploy Compose project (not Swarm Application) using compose.yaml alone:

  • Git source: Connect https://github.com/FlyCockpit/context.git with Compose path compose.yaml and put secrets/variables in the Environment tab.
  • Raw Compose file: Pin the app build context to a full commit SHA and pass BUILDKIT_CONTEXT_KEEP_GIT_DIR: "1" so /ready reports the baked commit SHA.
  • In Dokploy’s Domains tab, route your HTTPS domain to service app, container port 3000.
  • Set TRUST_PROXY_HOPS=1 in the Compose environment (without it, every client shares Traefik’s IP for rate limits).
  • Compression: Cockpit Context ships no Node compression middleware. Attach a Traefik compress middleware (traefik.http.middlewares.<name>.compress=true) to the router, and confirm SSE streams remain unbuffered.

Home Server Behind Cloudflare Tunnel

For servers behind NAT/CGNAT without a public IP, run a named cloudflared tunnel:

  • Tunnel → app (http://127.0.0.1:3036 with compose.vps.yaml, or cloudflared container on the egress network pointing at http://app:3000): set TRUST_PROXY_HOPS=1.
  • Tunnel → Traefik/Caddy → app: set TRUST_PROXY_HOPS=2 and add cloudflared’s IP to your proxy’s trusted proxy list. Serve the local proxy on plain HTTP (no HTTPS redirect loop).
  • For locally managed tunnel containers (cloudflare/cloudflared, UID 65532), store credentials outside the Git checkout (e.g. /etc/cloudflared) with chmod 700 on the directory, chmod 400 on the JSON file, and chown -R 65532:65532 /etc/cloudflared.
  • Do not place Cloudflare Bot Fight Mode, Managed Challenges, or Cloudflare Access in front of /mcp, /.well-known/*, or /api/auth/*—coding agents cannot solve browser challenges.

Runtime Health & Deploy Verification

  • Liveness: GET /health
  • Readiness (including migrations and baked commit): GET /ready
  • Remote verification: pnpm deploy:check https://context.example.com --commit <sha>
  • Host verification: pnpm dokploy:verify --project cockpit-context --url https://context.example.com --commit <sha>

Environment Variables Reference

Core Required Settings

Variable Default Description
POSTGRES_PASSWORD (required) Strong hex password (openssl rand -hex 32), interpolated into DATABASE_URL by compose.yaml.
BETTER_AUTH_SECRET (required) Random secret (≥ 32 chars) for sessions, OAuth signing, and password peppering.
BETTER_AUTH_SECRET_PREVIOUS (unset) Prior auth secret during zero-loss password pepper rotation.
BETTER_AUTH_URL (required) Exact public HTTPS origin (https://context.example.com), no path or trailing slash.
ADMIN_EMAILS (required) Comma-separated bootstrap admin email allowlist. Keep configured after first boot.
COCKPIT_CONTEXT_ENCRYPTION_KEYS (required) AES-256-GCM keyring (v1:<base64 32-byte key>) for saved SSH keys.
OPENROUTER_API_KEY (unset) OpenRouter API key. App boots without it, but investigations fail until set.
COCKPIT_CONTEXT_MODEL (unset) Primary OpenRouter model ID (required when OPENROUTER_API_KEY is set).
COCKPIT_CONTEXT_HELPER_MODEL (unset) Optional model ID for delegated exploration helper runs.

Networking, Auth & Privacy

Variable Default Description
TRUST_PROXY_HOPS 0 Exact number of trusted reverse proxies (1 for Traefik/Caddy/direct tunnel, 2 for tunnel + proxy).
COCKPIT_CONTEXT_HTTP_PORT 3000 Loopback port used only by compose.vps.yaml.
CORS_ORIGIN (unset) Leave unset for same-origin deploys; never wildcard.
SIGNUP_ENABLED false Keep false and invite users from Admin → Users.
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM (unset) Enables email verification, password resets, and emailed invites (587 STARTTLS or 465 implicit TLS).
SSO_ENABLED, SSO_CLIENT_ID, SSO_CLIENT_SECRET, SSO_ISSUER, SSO_PROVIDER_NAME (unset) Optional OIDC SSO configuration.
FORCE_SSO false Disables password login; requires full SSO configuration in production.
COCKPIT_CONTEXT_CONVERSATION_RETENTION_DAYS 90 Days of inactivity before automatic conversation deletion (0 disables).
COCKPIT_CONTEXT_OPERATOR_NAME, COCKPIT_CONTEXT_OPERATOR_CONTACT_EMAIL (unset) Public operator details displayed on the privacy notice.
COCKPIT_CONTEXT_GIT_HOST_ALLOWLIST (unset) Comma-separated exact FQDNs of internal Git servers permitted to resolve to private IPs.

Investigation Engine, Storage, LSP & Caching

Variable Default Description
COCKPIT_CONTEXT_DATA_DIR /data Persistent storage path for bare clones and checkouts.
COCKPIT_CONTEXT_MAX_STORAGE_GB 20 Decimal GB (10^9 bytes/GB) cache ceiling before LRU pruning to 90%.
COCKPIT_CONTEXT_MODEL_API chat-completions Upstream API wire format: chat-completions, responses, or messages.
COCKPIT_CONTEXT_OPENROUTER_BASE_URL https://openrouter.ai/api/v1 OpenRouter-compatible API root (HTTPS required in production).
COCKPIT_CONTEXT_MAX_ITERATIONS 100 Agent loop iteration cap per main investigation.
COCKPIT_CONTEXT_RUN_TIMEOUT_SECONDS 600 Wall-clock run cap and checkout lease length.
COCKPIT_CONTEXT_MODEL_STALL_SECONDS 90 Max silence per model call (10–3600).
COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS 4 Global concurrent runs across all users.
COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS_PER_USER 3 Concurrent main runs per user (overview summaries count globally only).
COCKPIT_CONTEXT_MAX_QUEUED_RUNS_PER_USER 20 Max queued main runs per user before returning BUSY (0 = unlimited).
COCKPIT_CONTEXT_MAX_PARALLEL_HELPERS / COCKPIT_CONTEXT_MAX_HELPERS 5 / 10 Parallel and total helper runs per investigation.
COCKPIT_CONTEXT_MCP_WAIT_SECONDS 900 Default and max wait_seconds for query_dependency / get_query_result.
COCKPIT_CONTEXT_MCP_QUERIES_PER_HOUR 30 Hourly query_dependency cap per MCP credential.
COCKPIT_CONTEXT_MCP_QUERIES_PER_USER_PER_HOUR 120 Aggregate hourly query_dependency cap across all of a user’s credentials (0 = off).
COCKPIT_CONTEXT_MCP_TOOL_CALLS_PER_MINUTE 120 Per-credential MCP tool call rate limit.
COCKPIT_CONTEXT_MAX_MCP_RESULT_WAITS_PER_USER 10 Concurrent parked get_query_result waits per user.
COCKPIT_CONTEXT_MAX_LIVE_STREAMS_PER_USER 20 Concurrent web SSE live streams per user.
COCKPIT_CONTEXT_ANSWER_CACHE_ENABLED / _TTL_SECONDS / _MAX_ENTRIES true / 3600 / 500 Per-user in-memory MCP answer reuse settings.
COCKPIT_CONTEXT_VERSION_CACHE_TTL_SECONDS / _MAX_ENTRIES 300 / 1000 Exact version/tag/SHA resolution cache (0 = off).
COCKPIT_CONTEXT_FETCH_INTERVAL_SECONDS 300 Minimum interval between automatic branch remote fetches.
COCKPIT_CONTEXT_LSP_SANDBOX required required (Landlock confinement; disables LSP if unavailable) or off (dev only).
COCKPIT_CONTEXT_LSP_MAX_SERVERS / _IDLE_SECONDS 4 / 30 Active language server pool size (0 disables LSPs) and idle eviction timeout.
MIGRATE_ON_START true Apply committed migrations on boot (false only when running a separate migrate command first).
DATABASE_POOL_MAX 10 Postgres pool size (minimum 3 for auth lock slots).
JOBS_CONCURRENCY 2 In-process background job concurrency.

Backup & Freshness Monitoring

Variable Default Description
BACKUP_ENABLED false Strict true/false. When true, migrating starts require a valid destination (/backups or S3) and take pre-migration and pre-drop dumps.
BACKUP_SCHEDULE off Set daily with Compose profile backup to run scheduled dumps.
BACKUP_HOUR_UTC / BACKUP_KEEP 3 / 14 Daily dump UTC hour and local retention count.
BACKUP_S3_BUCKET, BACKUP_S3_ACCESS_KEY_ID, BACKUP_S3_SECRET_ACCESS_KEY (unset) Off-site S3 bucket and dedicated write credentials (unset by PID 1 entrypoint before tini execs the server).
BACKUP_S3_REGION, BACKUP_S3_ENDPOINT, BACKUP_S3_PREFIX auto, (unset), cockpit-context/prod/database S3-compatible endpoint, region, and object key prefix.
BACKUP_MONITOR_S3_ACCESS_KEY_ID, BACKUP_MONITOR_S3_SECRET_ACCESS_KEY (unset) Separate ListBucket-only credentials for Admin → Backups freshness monitoring (reusing the writer key refuses startup).
BACKUP_MAX_AGE_HOURS 36 Hours before the 6-hourly freshness check flags stale backups.
BACKUP_HEARTBEAT_URL (unset) Optional webhook pinged after a successful backup upload.

Backup and Restore

Backups are verified custom-format PostgreSQL archives (pg_dump -Fc) and are opt-in (BACKUP_ENABLED=false, BACKUP_SCHEDULE=off by default).

Caution: PostgreSQL dumps are not encrypted bundles and do not include /data or your secrets. For full disaster recovery, separately protect:

  1. COCKPIT_CONTEXT_ENCRYPTION_KEYS (required to decrypt saved SSH keys in the DB)
  2. BETTER_AUTH_SECRET (required to verify peppered password hashes)
  3. The /data volume (specifically any private repositories cloned with a one-time SSH key, which cannot auto-refetch)

Enabling Automated Backups

Add compose.backup.yaml (mounts /backups on app) and the backup Compose profile for daily scheduling, after setting BACKUP_ENABLED=true and BACKUP_SCHEDULE=daily:

docker compose -p cockpit-context \
  -f compose.yaml \
  -f compose.vps.yaml \
  -f compose.backup.yaml \
  --profile backup up -d --build

For credential isolation, the container entrypoint runs as PID 1 during startup migrations using BACKUP_S3_ACCESS_KEY_ID / BACKUP_S3_SECRET_ACCESS_KEY, then unsets both variables before execing tini and the Node server. The running web server retains only the separate ListBucket-only BACKUP_MONITOR_S3_* credentials.

Host Backup, Drill & Offline Restore

Run the Linux host helper from your repository checkout, always specifying --project:

# Take an immediate verified database dump
bash scripts/backup/host.sh backup --project cockpit-context

# List available local and S3 dumps
bash scripts/backup/host.sh list --project cockpit-context

# Run a disposable restore drill (verifies archive & migration tables)
bash scripts/backup/host.sh drill --project cockpit-context

# Guided offline restore (prompts before stopping app & backup scheduler)
bash scripts/backup/host.sh restore --project cockpit-context

Restore behavior and exit codes:

  • The guided helper prompts "Stop the app and continue?", stops both app and backup, previews the archive and target database, and requires explicit confirmation before replacing data inside a single transaction.
  • Restored databases automatically receive a 7-day deletion hold (if you restore outside the helper, run the image command hold-deletions 7 before starting the app).
  • Exit codes: 0 = committed cleanly (app remains stopped so you can recover /data snapshot clones and verify COCKPIT_CONTEXT_ENCRYPTION_KEYS before running docker start); 3 = refused/cancelled with nothing changed (helper restarts stopped services); 4 = failed and provably rolled back (helper restarts stopped services); 1 or 129/130/143 = uncertain outcome—keep all writers stopped and inspect the database before starting the app.