Repository navigation
Expand file tree
/
Copy pathdocker-compose.prod.yaml
More file actions
124 lines (123 loc) · 6.71 KB
/
Copy pathdocker-compose.prod.yaml
File metadata and controls
124 lines (123 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
services:
app:
container_name: capstan
# Published by .github/workflows/docker-publish.yml. Pin to a version tag
# (e.g. :0.9.0) in production; :latest tracks the most recent release.
# The default stays :latest deliberately — a pinned tag in a template file
# goes stale on every release and nothing in the repo keeps it current. Since
# :latest is mutable and the watchtower label below lets an agent move it,
# identify what is actually running with `curl localhost:5001/api/v1/version`
# or Settings → About.
image: ghcr.io/thinkbig1979/capstan:latest
restart: unless-stopped
# entrypoint.sh ends in `exec gosu`, so the Go server is PID 1. Killed docker
# CLI children reparent to it and are never reaped; init: true adds a reaper.
init: true
# Docker's default is 10s before SIGKILL, which is shorter than the
# server's own graceful-shutdown budget (up to 15s for in-flight HTTP
# requests + up to 30s draining an in-flight backup/restore/sync run —
# see backend/cmd/server/main.go's backupDrainTimeout). Without this, a
# `docker stop`/compose down mid-backup gets SIGKILLed before the process
# ever reaches its own bounded drain. 60s covers the ~45s worst case with
# margin (agent-os-7a5).
stop_grace_period: 60s
# Memory ceiling. Capstan forks restic/rclone as children
# (services/backup_restic.go, backup_rclone.go) and restic's RAM use
# scales with repository index size, not raw data size, so a large
# backup/restore is the realistic path to exhausting host memory and
# inviting the kernel OOM killer (nothing here sets oom_score_adj).
# ASSUMED, not measured on this host: no production-scale restic
# repository was available to profile while making this change
# (agent-os-qru.4). The figure below is a documented community data
# point, not an observation from this deployment — restic users have
# reported index/RAM use of roughly 6-7GB for a ~1.2TB repository
# (https://forum.restic.net/t/memory-usage-oom-etc-on-a-big-repository/8758),
# i.e. on the order of 0.5% of repository size. 2g gives headroom for
# the Capstan server process plus a restic/rclone run against a
# repository up to roughly 200-300GB under that ratio. This is a
# starting point, NOT a substitute for sizing against your own
# repository — see README.md's "Resource limits" section (under
# Production Deployment) for how to do that.
#
# Set in two places on purpose. This stack is run with `docker compose
# up` (see README), never `docker stack deploy`/swarm. `mem_limit` is
# the Compose Specification's top-level, non-swarm key and is
# unambiguously honoured by `docker compose up` on a single Engine —
# it is the value actually enforced here. `deploy.resources.limits`
# is historically a swarm-only construct and its enforcement under
# plain `compose up` has been inconsistent across Compose
# versions/docs (see docker/compose#7307, docker/compose#10046), so it
# is NOT relied on for enforcement; it is kept in sync with mem_limit
# (the spec requires the two to be consistent when both are set) so
# tooling that only reads the `deploy` shape — and this bead's own
# acceptance check, `docker compose config | grep -E "memory|cpus"` —
# sees the real ceiling rather than nothing.
mem_limit: 2g
deploy:
resources:
limits:
memory: 2g
# No CPU limit: the risk this addresses (agent-os-qru.4) is memory
# exhaustion/OOM, not CPU contention, and no CPU measurement justifies
# a ceiling here. Add `cpus: <n>` following the same pattern if CPU
# contention is later observed.
ports:
- "5001:5001"
volumes:
# Capstan joins the socket's group at runtime; no host changes needed.
- /var/run/docker.sock:/var/run/docker.sock
# STACKS_DIR must be the same path inside and outside the container (see
# docs/explanation/security-model.md): Capstan runs `docker compose`
# through the host's daemon, which resolves a managed stack's relative
# binds (./data:/data) against the path Capstan sees. With different
# paths that data lands outside the directory Capstan manages and backs
# up, with no error. Set STACKS_DIR in .env to move it; the startup log
# reports an ERROR if the mount breaks this rule (agent-os-a1ye.1).
- ${STACKS_DIR:-/opt/stacks}:${STACKS_DIR:-/opt/stacks}
# ./data is a host bind mount — the restic backup repository lives at
# ./data/restic-repo (container path /app/data/restic-repo) by default.
# Snapshots survive container recreation as long as this directory exists.
- ./data:/app/data
- ./keys:/app/keys:ro
environment:
# Match the host user that owns your stacks/data (default 1000).
- PUID=${PUID:-1000}
- PGID=${PGID:-1000}
# Container timezone, which is the zone clock-time schedules run in:
# scheduled updates and backups fire against this clock, not the host's.
# Left at UTC, "03:00" in the UI means 03:00 UTC, so an operator in
# Europe/Amsterdam gets 05:00 local in summer and 04:00 in winter. Set it
# to your IANA zone (e.g. TZ=Europe/Amsterdam) in .env or the shell.
- TZ=${TZ:-UTC}
# Derived from the same variable as the mount above, so they cannot drift.
- STACKS_DIR=${STACKS_DIR:-/opt/stacks}
- HOST_STACKS_DIR=${HOST_STACKS_DIR:-${STACKS_DIR:-/opt/stacks}}
# JWT_SECRET (required) and STORAGE_KEY (recommended) are read from .env
# below — generate each with `openssl rand -hex 32`. See README / Deployment
# Guide. STORAGE_KEY encrypts stored secrets at rest independently of
# JWT_SECRET; it falls back to JWT_SECRET if unset.
# Backup — optional env-var fallbacks; DB settings (Settings → Backup) take
# precedence at runtime. Set these if you prefer environment-level config
# over the UI, or for scripted/headless deployments.
# - RESTIC_REPOSITORY=/app/data/restic-repo
# - RESTIC_PASSWORD=change-me
# - RCLONE_REMOTE=myremote
# - RCLONE_PATH=capstan-backups
env_file:
- .env
networks:
- capstan-network
labels:
- "com.centurylinklabs.watchtower.enable=true"
healthcheck:
# Liveness (no Docker call), and a real GET rather than --spider: --spider
# sends HEAD, which has no route and falls through to the SPA catch-all,
# so it returned 200 even when GET /health returned 503 (agent-os-69a).
test: ["CMD-SHELL", "wget --no-verbose --tries=1 -O /dev/null http://localhost:$${PORT:-5001}/health || exit 1"]
interval: 30s
timeout: 10s
start_period: 5s
retries: 3
networks:
capstan-network:
external: true