Repository navigation
Expand file tree
/
Copy pathdocker-compose.cloud.yml
More file actions
293 lines (282 loc) · 16.1 KB
/
Copy pathdocker-compose.cloud.yml
File metadata and controls
293 lines (282 loc) · 16.1 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Cloud profile: one Django process, no Celery, external Postgres and object storage.
#
# docker compose -f docker-compose.cloud.yml up -d
#
# Deliberately a STANDALONE file, not a layer over docker-compose.yml. The base file
# defines db, redis, minio, worker and beat, and layering can add services but cannot
# remove them -- so a `-f base -f cloud` chain would still start the very containers this
# profile exists to do without.
#
# THE ONE THING THAT BREAKS SILENTLY. With CELERY_BROKER_URL unset, settings put Celery
# in eager mode and every `.delay()` runs inline, so nothing looks wrong. But
# CELERY_BEAT_SCHEDULE is beat's business, and there is no beat here -- so
# `send_return_reminders` (a duty-of-care message in the accountability flow) simply
# never fires. The `cron` service below is not optional garnish; it is what replaces
# beat. An external scheduler is unsupported unless its topology declaration names the
# shared host gate or provider control-plane disablement in every state except `normal`
# and `acknowledged-normal`; merely dropping this service is now refused. After declaring that boundary,
# register these commands with the provider:
#
# */15 * * * * python manage.py run_scheduled_tasks --due-only
# */30 * * * * python manage.py flush_email_outbox
#
# STORAGE. R2 (or any S3-compatible host) needs STORAGE_PRESIGN_METHOD=put -- the MinIO
# POST-policy flow is not supported. CORS is set in the provider's dashboard, not here:
# `mc cors set` is unusable against modern MinIO and R2 has no `mc` at all.
#
# PUBLIC_IMAGE_BASE_URL and AWS_S3_PUBLIC_ENDPOINT_URL must name the real public host.
# They are baked into every presigned upload URL and every public image `src`, so
# `localhost` here produces a deployment that works only from the server console and
# shows broken images to everyone else.
x-logging: &default-logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
x-restart: &default-restart unless-stopped
x-spaceworks-host-orchestration:
scheduler:
mode: image
services: [cron]
pointer:
mode: atomic-file
path: /var/lib/spaceworks/ops/database-pointer.env
static_environment: /etc/spaceworks/cloud.env
database_identity: endpoint-plus-queried-uuid
writer_services: [backend, cron]
sibling_lifecycle: provider-isolated-database
x-app-env: &app-env
SPACEWORKS_OCI_DIGEST: ${SPACEWORKS_OCI_DIGEST:-}
SPACEWORKS_TASK_GENERATION: ${SPACEWORKS_TASK_GENERATION:-}
SECRET_KEY: ${SECRET_KEY:?set SECRET_KEY}
DEBUG: "False"
ALLOWED_HOSTS: ${ALLOWED_HOSTS:?set ALLOWED_HOSTS}
# Deployment-wide app tombstones (app labels, see `suggest_tombstones`). Every
# Django process must see the same list: URL routing, admin registration and the
# schema are process-global, so a worker or beat without it runs a different app set.
TOMBSTONED_APPS: ${TOMBSTONED_APPS:-}
# Managed Postgres (Supabase, Neon, RDS). MANAGED_POSTGRES=True matters for purge:
# those hosts forbid session_replication_role, so immutability triggers are suspended
# through the app.allow_immutable_delete GUC instead.
DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL}
SPACEWORKS_DB_POINTER_GENERATION: ${SPACEWORKS_DB_POINTER_GENERATION:?use scripts/spaceworks-compose.sh}
MANAGED_POSTGRES: ${MANAGED_POSTGRES:-True}
# Pooled connections matter more here than on a local box: a managed Postgres charges
# for connections and a cold one per request is most of the request.
CONN_MAX_AGE: ${CONN_MAX_AGE:-60}
DISABLE_SERVER_SIDE_CURSORS: ${DISABLE_SERVER_SIDE_CURSORS:-True}
CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS:-}
CSRF_TRUSTED_ORIGINS: ${CSRF_TRUSTED_ORIGINS:-}
PUBLIC_APP_BASE_URL: ${PUBLIC_APP_BASE_URL:?set PUBLIC_APP_BASE_URL}
# Upstream check-in roster for the `checked_in` public-request mode. Blank leaves the
# integration dormant; a tenant must also be switched into the mode and bound to a
# `checkin_space_id`. Absent here, setting it in the host .env never reaches Django.
CHECKIN_API_URL: ${CHECKIN_API_URL:-}
CHECKIN_TIMEOUT: ${CHECKIN_TIMEOUT:-5.0}
CHECKIN_CACHE_SECONDS: ${CHECKIN_CACHE_SECONDS:-30}
CHECKIN_REQUIRED_PURPOSE: ${CHECKIN_REQUIRED_PURPOSE:-Working on a project}
CHECKIN_MAX_RESPONSE_BYTES: ${CHECKIN_MAX_RESPONSE_BYTES:-1048576}
CHECKIN_MAX_ROWS: ${CHECKIN_MAX_ROWS:-2000}
CHECKIN_PROVIDER_NAME: ${CHECKIN_PROVIDER_NAME:-}
# Optional integrations and secrets the code reads. Each must be listed here or a
# value set in .env never reaches Django. Blank keeps the feature off / at its default.
EVENT_STATION_PIN_PEPPER: ${EVENT_STATION_PIN_PEPPER:-}
PUSH_TOKEN_HMAC_KEY: ${PUSH_TOKEN_HMAC_KEY:-}
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN:-}
TELEGRAM_WEBHOOK_SECRET: ${TELEGRAM_WEBHOOK_SECRET:-}
GITHUB_API_TOKEN: ${GITHUB_API_TOKEN:-}
STRIPE_CONNECT_REDIRECT_URI: ${STRIPE_CONNECT_REDIRECT_URI:-}
PUBLIC_IMAGE_MAX_BYTES: ${PUBLIC_IMAGE_MAX_BYTES:-10485760}
PUBLIC_IMAGE_URL_TTL_SECONDS: ${PUBLIC_IMAGE_URL_TTL_SECONDS:-300}
PLATFORM_STAFF_ORIGINS: ${PLATFORM_STAFF_ORIGINS:-}
CRON_SECRET: ${CRON_SECRET:-}
TELEGRAM_API_URL: ${TELEGRAM_API_URL:-https://api.telegram.org}
# HTTPS is the default here, so HSTS is too (settings derive 0 only when HTTPS is off).
SECURE_HSTS_SECONDS: ${SECURE_HSTS_SECONDS:-31536000}
# R2 wants "auto"; AWS wants the bucket region.
AWS_S3_REGION_NAME: ${AWS_S3_REGION_NAME:-us-east-1}
# Split SPA/API origins need SameSite=None + Secure; see "Split deployment" in README.md.
AUTH_COOKIE_SAMESITE: ${AUTH_COOKIE_SAMESITE:-None}
AUTH_COOKIE_SECURE: ${AUTH_COOKIE_SECURE:-True}
API_CLIENT_ENC_KEY: ${API_CLIENT_ENC_KEY:?set API_CLIENT_ENC_KEY}
HMAC_CLIENT_ID: ${HMAC_CLIENT_ID:-}
HMAC_SECRET: ${HMAC_SECRET:-}
HMAC_MAX_CLOCK_SKEW_SECONDS: ${HMAC_MAX_CLOCK_SKEW_SECONDS:-300}
APICLIENT_REQUIRE_NONCE: ${APICLIENT_REQUIRE_NONCE:-False}
HMAC_PROTECTED_PATH_PREFIXES: ${HMAC_PROTECTED_PATH_PREFIXES:-/api/public/,/api/v1/public/}
API_CLIENT_AUTH_REQUIRED: ${API_CLIENT_AUTH_REQUIRED:-False}
PII_ENCRYPTION_ENABLED: ${PII_ENCRYPTION_ENABLED:-False}
PII_ENCRYPTION_DUAL_READ: ${PII_ENCRYPTION_DUAL_READ:-True}
PII_KEY_BROKER: ${PII_KEY_BROKER:-local}
PII_MASTER_KEY: ${PII_MASTER_KEY:-}
PII_MASTER_KEY_PREVIOUS: ${PII_MASTER_KEY_PREVIOUS:-}
PII_SEARCH_HASH_KEY: ${PII_SEARCH_HASH_KEY:-}
PII_DEK_CACHE_TTL_SECONDS: ${PII_DEK_CACHE_TTL_SECONDS:-300}
PII_AWS_KMS_KEY_ID: ${PII_AWS_KMS_KEY_ID:-}
PII_AWS_KMS_REGION: ${PII_AWS_KMS_REGION:-}
PII_AWS_KMS_ENDPOINT_URL: ${PII_AWS_KMS_ENDPOINT_URL:-}
AUDIT_MAC_MASTER_KEY: ${AUDIT_MAC_MASTER_KEY:-}
AUDIT_ATTESTATION_DEPLOYMENT_ID: ${AUDIT_ATTESTATION_DEPLOYMENT_ID:-}
AUDIT_ATTESTATION_ANCHOR_BACKEND: ${AUDIT_ATTESTATION_ANCHOR_BACKEND:-}
AUDIT_ATTESTATION_S3_BUCKET: ${AUDIT_ATTESTATION_S3_BUCKET:-}
AUDIT_ATTESTATION_S3_PREFIX: ${AUDIT_ATTESTATION_S3_PREFIX:-}
AUDIT_ATTESTATION_RETENTION_DAYS: ${AUDIT_ATTESTATION_RETENTION_DAYS:-2555}
AUDIT_ATTESTATION_S3_OBJECT_LOCK_MODE: ${AUDIT_ATTESTATION_S3_OBJECT_LOCK_MODE:-}
AUDIT_ATTESTATION_S3_ENDPOINT_URL: ${AUDIT_ATTESTATION_S3_ENDPOINT_URL:-}
AUDIT_ATTESTATION_S3_ACCESS_KEY_ID: ${AUDIT_ATTESTATION_S3_ACCESS_KEY_ID:-}
AUDIT_ATTESTATION_S3_SECRET_ACCESS_KEY: ${AUDIT_ATTESTATION_S3_SECRET_ACCESS_KEY:-}
AUDIT_ATTESTATION_S3_REGION_NAME: ${AUDIT_ATTESTATION_S3_REGION_NAME:-}
AUDIT_ATTESTATION_HTTP_URL: ${AUDIT_ATTESTATION_HTTP_URL:-}
AUDIT_ATTESTATION_HTTP_BEARER_TOKEN: ${AUDIT_ATTESTATION_HTTP_BEARER_TOKEN:-}
AUDIT_ATTESTATION_HTTP_TIMEOUT: ${AUDIT_ATTESTATION_HTTP_TIMEOUT:-10}
ENABLE_HTTPS: ${ENABLE_HTTPS:-true}
TRUST_X_FORWARDED_PROTO: ${TRUST_X_FORWARDED_PROTO:-true}
# Count every proxy in front of this container, or DRF keys throttles on the proxy's
# address and every user shares one rate-limit bucket.
TRUSTED_PROXY_COUNT: ${TRUSTED_PROXY_COUNT:-1}
AXES_FAILURE_LIMIT: ${AXES_FAILURE_LIMIT:-5}
# Resend speaks SMTP, so it needs no code: host smtp.resend.com, user "resend",
# password an API key. Any SMTP provider works the same way.
EMAIL_BACKEND: ${EMAIL_BACKEND:-django.core.mail.backends.smtp.EmailBackend}
EMAIL_HOST: ${EMAIL_HOST:-smtp.resend.com}
EMAIL_PORT: ${EMAIL_PORT:-587}
EMAIL_HOST_USER: ${EMAIL_HOST_USER:-resend}
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD:-}
EMAIL_USE_TLS: ${EMAIL_USE_TLS:-True}
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL:?set DEFAULT_FROM_EMAIL}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:?set AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:?set AWS_SECRET_ACCESS_KEY}
AWS_STORAGE_BUCKET_NAME: ${AWS_STORAGE_BUCKET_NAME:-evidence}
PUBLIC_IMAGE_BUCKET: ${PUBLIC_IMAGE_BUCKET:-public-images}
PUBLIC_IMAGE_BASE_URL: ${PUBLIC_IMAGE_BASE_URL:?set PUBLIC_IMAGE_BASE_URL}
AWS_S3_ENDPOINT_URL: ${AWS_S3_ENDPOINT_URL:?set AWS_S3_ENDPOINT_URL}
AWS_S3_PUBLIC_ENDPOINT_URL: ${AWS_S3_PUBLIC_ENDPOINT_URL:?set AWS_S3_PUBLIC_ENDPOINT_URL}
# R2 and Supabase need PUT presigning; the POST-policy flow is MinIO-only.
STORAGE_PRESIGN_METHOD: ${STORAGE_PRESIGN_METHOD:-put}
EVIDENCE_OBJECT_RETENTION_DAYS: ${EVIDENCE_OBJECT_RETENTION_DAYS:-365}
EVIDENCE_OBJECT_EXPIRY_ENABLED: ${EVIDENCE_OBJECT_EXPIRY_ENABLED:-False}
EVIDENCE_RETENTION_BATCH_SIZE: ${EVIDENCE_RETENTION_BATCH_SIZE:-100}
BACKUP_AGE_RECIPIENT: ${BACKUP_AGE_RECIPIENT:-}
BACKUP_ARCHIVE_SIGNING_PRIVATE_KEY: ${BACKUP_ARCHIVE_SIGNING_PRIVATE_KEY:-}
BACKUP_ARCHIVE_VERIFY_PUBLIC_KEY: ${BACKUP_ARCHIVE_VERIFY_PUBLIC_KEY:-}
BACKUP_OPS_DIR: /var/lib/spaceworks/ops/work
# Left EMPTY on purpose. Blank => CELERY_TASK_ALWAYS_EAGER defaults True and tasks run
# inline in this process, which is the whole point of the profile. Setting it here
# without also running a worker would queue tasks nothing ever consumes.
CELERY_BROKER_URL: ""
SPACEWORKS_HOST_MARKER_PATH: /run/spaceworks-host/restore-marker.json
BACKUP_PRODUCER_CAPABILITY_MARKER_PATH: /run/spaceworks-host/producer-capability.json
BACKUP_PRODUCER_PRIVILEGED_SCRIPTS_DIR: /run/spaceworks-privileged-scripts
services:
orchestration-init:
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
user: "0:0"
entrypoint: ["python", "/app/scripts/bootstrap_host_orchestration.py"]
environment:
DATABASE_URL: ${SPACEWORKS_MAINTENANCE_DATABASE_URL:?set SPACEWORKS_MAINTENANCE_DATABASE_URL}
SPACEWORKS_RUNTIME_DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL}
SPACEWORKS_HOST_MARKER_WRITE_PATH: /host-state/restore-marker.json
SPACEWORKS_SCHEDULER_MODE: image
SPACEWORKS_SCHEDULER_SERVICES: cron
volumes:
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/host-state
migrate:
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
environment:
<<: *app-env
DATABASE_URL: ${SPACEWORKS_MAINTENANCE_DATABASE_URL:?set SPACEWORKS_MAINTENANCE_DATABASE_URL}
command: ["--role", "migrate", "python", "manage.py", "migrate"]
logging: *default-logging
volumes:
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/work:/var/lib/spaceworks/ops/work
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/operation.lock:/var/lib/spaceworks/ops/operation.lock
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/run/spaceworks-host:ro
depends_on:
orchestration-init:
condition: service_completed_successfully
orchestration-ready:
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
user: "0:0"
entrypoint: ["python", "/app/scripts/bootstrap_host_orchestration.py"]
environment:
DATABASE_URL: ${SPACEWORKS_MAINTENANCE_DATABASE_URL:?set SPACEWORKS_MAINTENANCE_DATABASE_URL}
SPACEWORKS_RUNTIME_DATABASE_URL: ${DATABASE_URL:?set DATABASE_URL}
SPACEWORKS_HOST_MARKER_WRITE_PATH: /host-state/restore-marker.json
SPACEWORKS_SCHEDULER_MODE: image
SPACEWORKS_SCHEDULER_SERVICES: cron
volumes:
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/host-state
depends_on:
migrate:
condition: service_completed_successfully
backend:
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
restart: *default-restart
logging: *default-logging
environment: *app-env
volumes:
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/work:/var/lib/spaceworks/ops/work
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/operation.lock:/var/lib/spaceworks/ops/operation.lock
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/run/spaceworks-host:ro
- ./scripts:/run/spaceworks-privileged-scripts:ro
# Keep the whole gunicorn invocation on ONE line: in a YAML folded scalar a
# more-indented line keeps its newline, and a newline inside `sh -c` ends the
# command -- gunicorn then runs bare on its 127.0.0.1 default while the healthcheck,
# which probes localhost, still reports healthy.
command: ["--role", "backend", "sh", "-c", "python manage.py collectstatic --noinput && exec gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers ${GUNICORN_WORKERS:-3} --timeout ${GUNICORN_TIMEOUT:-60} --graceful-timeout 30 --max-requests 1000 --max-requests-jitter 100 --access-logfile - --error-logfile -"]
ports:
- "${BACKEND_PORT:-8000}:8000"
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health/readiness/', timeout=3).read()\""]
interval: 10s
timeout: 5s
retries: 6
start_period: 45s
depends_on:
orchestration-ready:
condition: service_completed_successfully
# Replaces Celery beat. Without this, return reminders stop and nothing reports it.
cron:
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
restart: *default-restart
logging: *default-logging
environment: *app-env
volumes:
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/work:/var/lib/spaceworks/ops/work
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/operation.lock:/var/lib/spaceworks/ops/operation.lock
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/run/spaceworks-host:ro
- ./scripts:/run/spaceworks-privileged-scripts:ro
# A sleep loop rather than a cron daemon: the image runs unprivileged as uid 10001
# and ships no crond, and `--due-only` already makes the cadence idempotent, so the
# loop only has to be frequent enough -- not accurate.
command: ["--role", "cron", "sh", "-c", "while true; do python manage.py run_scheduled_tasks --due-only || true; python manage.py flush_email_outbox || true; sleep ${CRON_INTERVAL_SECONDS:-900}; done"]
depends_on:
orchestration-ready:
condition: service_completed_successfully
candidate-backend:
profiles: [host-recovery]
image: ${MAKERSPACE_BACKEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-backend}:${MAKERSPACE_IMAGE_TAG:-latest}
environment: *app-env
command: ["--role", "backend", "gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "1", "--access-logfile", "-", "--error-logfile", "-"]
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health/readiness/', timeout=3).read()\""]
interval: 10s
timeout: 5s
retries: 6
volumes:
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/work:/var/lib/spaceworks/ops/work
- ${SPACEWORKS_OPS_HOST_DIR:-/var/lib/spaceworks/ops}/operation.lock:/var/lib/spaceworks/ops/operation.lock
- ${SPACEWORKS_HOST_STATE_DIR:-/var/lib/spaceworks/host}/public:/run/spaceworks-host:ro
frontend:
image: ${MAKERSPACE_FRONTEND_IMAGE:-ghcr.io/spaceworks-hq/spaceworks-frontend}:${MAKERSPACE_IMAGE_TAG:-latest}
restart: *default-restart
logging: *default-logging
ports:
- "${FRONTEND_PORT:-8080}:80"
depends_on:
backend:
condition: service_healthy
# nginx resolves `backend` once at start. When Compose recreates backend (new image,
# or a changed .env as setup.sh does for the backup keys) it gets a new IP, and a
# frontend left running answers 502 for every /api call until restarted.
restart: true