Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
181 lines (173 loc) · 7.34 KB
/
Copy pathdocker-compose.yml
File metadata and controls
181 lines (173 loc) · 7.34 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
# Base services. For local development run `docker compose up --build` (UI on
# http://localhost:8080, API on http://localhost:8000). For production run:
# docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
#
# Credentials are not stored here: copy .env.example to .env and set
# POSTGRES_USER / POSTGRES_PASSWORD / POSTGRES_DB first. `.env` is gitignored.
services:
# Frontend: static single-page app served by non-root nginx, reverse-proxying
# /api to the backend so the browser keeps a single origin. To host the
# frontend on a different origin, set window.__API_BASE_URL__ in
# frontend/config.js and configure CORS_ORIGINS on the api service.
web:
build: ./frontend
container_name: web
ports:
- "8080:8080"
# depends_on:
# api:
# condition: service_healthy
restart: unless-stopped
networks:
- sredevops-sec-feed
# Backend: pure JSON API (no UI assets), runs as a non-root user.
api:
build: .
container_name: api
hostname: api
environment:
# Local PostgreSQL for `docker compose up`. To run against hosted
# Supabase instead, use the overlay (which also skips the local database):
# docker compose -f docker-compose.yml -f docker-compose.supabase.yml up --build
- DATABASE_URL=postgresql://${POSTGRES_USER:?set POSTGRES_USER in .env}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:?set POSTGRES_DB in .env}
# The local postgres service has no TLS; the API is on the same bridge.
- DB_SSLMODE=prefer
# Optional Postgres pool tuning (defaults shown):
# - DB_POOL_MIN_SIZE=1
# - DB_POOL_MAX_SIZE=4
# - DB_POOL_TIMEOUT=30
# - DB_CONNECT_TIMEOUT=10
# - DB_APPLICATION_NAME=security-feed
# - DB_STATEMENT_TIMEOUT_MS=15000
# - DB_IDLE_TX_TIMEOUT_MS=30000
# - DB_LOCK_TIMEOUT_MS=5000
# - DB_SSLROOTCERT=/etc/ssl/supabase/prod-supabase.cer
# Prepared statements are off by default (safe for any pooler mode). Set
# DB_PREPARE_THRESHOLD=5 only on a direct or session-mode connection.
# - DB_PREPARE_THRESHOLD=5
# - SECURITY_FEED_DB=/app/data/feed.db
# Comma-separated allowed CORS origins. Unset (the default) denies all
# cross-origin calls; the bundled frontend is same-origin, so only set
# this when hosting the frontend on a different origin.
# - CORS_ORIGINS=https://feed.example.com,https://cdn.example.com
# Rate limiting / SSE tuning (defaults shown). 0 disables each limit:
# - RATE_LIMIT_PER_MINUTE=120
# - RATE_LIMIT_TRUST_PROXY=true
# - MAX_SSE_SUBSCRIBERS=100
# Alerting channels (uncomment and set; prefer a secrets file in prod).
# Discord is the primary channel:
# - DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
# Secondary channels:
# - SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
# - ALERT_EMAIL_TO=security@example.com
# - SMTP_HOST=smtp.example.com
# Uncomment and run `docker compose --profile search up --build` to use
# the optional OpenSearch search backend.
# - OPENSEARCH_URL=http://opensearch:9200
depends_on:
migrate:
condition: service_completed_successfully
volumes:
- feed-data:/app/data
# No curl in the slim image; probe readiness with the stdlib only. The web
# service waits for this healthcheck before serving.
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/ready', timeout=3)"
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
restart: unless-stopped
ports:
- 8000:8000
networks:
- sredevops-sec-feed
# One-shot schema migration job. It runs before the API starts and is
# idempotent. It retries the connection itself, so it works whether the
# database is the local `postgres` service or hosted Supabase (overlay).
# The admin DSN lives only in this service, never in the API container.
migrate:
build: .
container_name: migrate
command: ["python", "-m", "app.migrate", "upgrade"]
environment:
- ADMIN_DATABASE_URL=postgresql://${POSTGRES_USER:?set POSTGRES_USER in .env}:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:?set POSTGRES_DB in .env}
- DB_SSLMODE=prefer
# One-shot job: it must not restart after it succeeds.
restart: "no"
networks:
- sredevops-sec-feed
postgres:
image: docker.io/postgres:16-alpine@sha256:721873c34ceb9f8d8fc265984940dc982404c105f19ad51be9fdc5970a6080ea
container_name: postgres
environment:
# Required from `.env` (see .env.example); no default credentials ship here.
- POSTGRES_USER=${POSTGRES_USER:?set POSTGRES_USER in .env}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
- POSTGRES_DB=${POSTGRES_DB:?set POSTGRES_DB in .env}
shm_size: 128mb
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:?set POSTGRES_USER in .env} -d postgres"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
networks:
- sredevops-sec-feed
# One-shot helper: ensure the application database exists before the API
# starts (the postgres image only creates POSTGRES_DB on first init).
postgres-init:
image: docker.io/postgres:16-alpine@sha256:721873c34ceb9f8d8fc265984940dc982404c105f19ad51be9fdc5970a6080ea
container_name: postgres-init
depends_on:
postgres:
condition: service_healthy
environment:
- PGPASSWORD=${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
entrypoint: ["/bin/sh", "-c"]
command:
- |
psql -h postgres -U ${POSTGRES_USER:?set POSTGRES_USER in .env} -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB:?set POSTGRES_DB in .env}'" | grep -q 1 || \
psql -h postgres -U ${POSTGRES_USER:?set POSTGRES_USER in .env} -d postgres -c "CREATE DATABASE ${POSTGRES_DB:?set POSTGRES_DB in .env}"
# One-shot job: it must not be restarted after it succeeds.
restart: "no"
networks:
- sredevops-sec-feed
# Optional search backend, local/dev only. The security plugin is disabled
# and there is no auth, so the port is published on loopback only and must
# not be exposed to untrusted networks (see deploy/k8s/networkpolicy.yaml for
# the Kubernetes-side restriction). Enable the security plugin or front it
# with auth before using it beyond local development.
opensearch:
image: docker.io/opensearchproject/opensearch:3@sha256:adfa61f85025d06b4aeb562e7e74fde7e31c437039c93c3862c17e9acebd6c7c
profiles: ["search"]
environment:
- discovery.type=single-node
- DISABLE_SECURITY_PLUGIN=true
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
ports:
# Loopback-only: never publish this unauthenticated service on 0.0.0.0.
- "127.0.0.1:9200:9200"
volumes:
- opensearch-data:/usr/share/opensearch/data
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200 >/dev/null || exit 1"]
interval: 20s
timeout: 10s
retries: 10
restart: unless-stopped
networks:
- sredevops-sec-feed
volumes:
feed-data:
postgres-data:
opensearch-data:
networks:
sredevops-sec-feed:
driver: bridge