Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
196 lines (189 loc) · 6.56 KB
/
Copy pathdocker-compose.yml
File metadata and controls
196 lines (189 loc) · 6.56 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
# Pin the Compose project name so container/volume names are deterministic across
# environments (locally the dir is "tweeter", on CI it's the repo "pulse"). CI and
# the Makefile reference "tweeter-backend-1" by name, so this keeps them valid.
name: tweeter
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: ${DB_NAME:-tweeter}
POSTGRES_USER: ${DB_USER:-tweeter}
POSTGRES_PASSWORD: ${DB_PASSWORD:-tweeter}
volumes:
- db_data:/var/lib/postgresql/data
shm_size: '256mb'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-tweeter} -d ${DB_NAME:-tweeter}"]
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
redis:
image: redis:7-alpine
# This Redis backs BullMQ queues and the feed/timeline sorted sets — i.e.
# semi-durable data, not a disposable cache. `noeviction` is therefore the
# correct policy: under memory pressure, fail writes loudly rather than let
# LRU silently drop queued jobs or feed entries (BullMQ requires noeviction).
command:
- "redis-server"
- "--maxmemory"
- "512mb"
- "--maxmemory-policy"
- "noeviction"
- "--save"
- ""
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
minio:
image: minio/minio:latest
command: server /data --console-address ":9001"
environment:
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:-minioadmin}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:-minioadmin}
volumes:
- minio_data:/data
ports:
- "9000:9000"
- "9001:9001"
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 10s
timeout: 5s
retries: 10
start_period: 15s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
createbuckets:
image: minio/mc:latest
depends_on:
minio:
condition: service_healthy
environment:
MINIO_BUCKET: ${MINIO_BUCKET:-tweeter-media}
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-minioadmin}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin}
entrypoint: >
/bin/sh -c "
mc alias set local http://minio:9000 $${MINIO_ACCESS_KEY} $${MINIO_SECRET_KEY};
mc mb --ignore-existing local/$${MINIO_BUCKET};
mc anonymous set download local/$${MINIO_BUCKET};
echo 'Bucket $${MINIO_BUCKET} ready';
exit 0;
"
backend:
build:
context: .
dockerfile: backend/Dockerfile
args:
# Pinned Node version — sourced from .nvmrc by Makefile/CI; default matches it.
NODE_VERSION: ${NODE_VERSION:-24.16.0}
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
minio:
condition: service_healthy
# Wait for the media bucket to be created before serving. This also makes
# `docker compose up --wait` deterministic: createbuckets is a run-to-completion
# one-shot (exits 0), so without an explicit completion dependency `--wait`
# would block waiting for it to become "running/healthy".
createbuckets:
condition: service_completed_successfully
environment:
NODE_ENV: ${NODE_ENV:-production}
PORT: 3000
DATABASE_URL: ${DATABASE_URL:-postgresql://tweeter:tweeter@db:5432/tweeter}
DATABASE_SSL: ${DATABASE_SSL:-false}
DB_MIGRATIONS_RUN: ${DB_MIGRATIONS_RUN:-true}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
WEB_ORIGIN: ${WEB_ORIGIN:-http://localhost:8080}
JWT_ACCESS_SECRET: ${JWT_ACCESS_SECRET}
JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
JWT_ACCESS_EXPIRY: ${JWT_ACCESS_EXPIRY:-15m}
JWT_REFRESH_EXPIRY: ${JWT_REFRESH_EXPIRY:-30d}
MINIO_ENDPOINT: minio
MINIO_PORT: 9000
MINIO_USE_SSL: "false"
# Public endpoint browsers use to PUT/GET presigned URLs (host-published).
MINIO_PUBLIC_ENDPOINT: ${MINIO_PUBLIC_ENDPOINT:-localhost}
MINIO_PUBLIC_PORT: ${MINIO_PUBLIC_PORT:-9000}
MINIO_PUBLIC_USE_SSL: ${MINIO_PUBLIC_USE_SSL:-false}
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-minioadmin}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin}
MINIO_BUCKET: ${MINIO_BUCKET:-tweeter-media}
MINIO_REGION: ${MINIO_REGION:-us-east-1}
# Public-read base for serving media (keys → URLs at read time). Defaults to
# the public MinIO endpoint + bucket; set to a CDN origin in prod.
MEDIA_PUBLIC_BASE_URL: ${MEDIA_PUBLIC_BASE_URL:-http://localhost:9000/tweeter-media}
# Media limits (only config differs dev↔prod).
MEDIA_MAX_FILES_PER_POST: ${MEDIA_MAX_FILES_PER_POST:-2}
MEDIA_MAX_BYTES_PER_FILE: ${MEDIA_MAX_BYTES_PER_FILE:-1048576}
MEDIA_MAX_BYTES_PER_POST: ${MEDIA_MAX_BYTES_PER_POST:-2097152}
MEDIA_GLOBAL_CAP_BYTES: ${MEDIA_GLOBAL_CAP_BYTES:-524288000}
MEDIA_SOFT_THRESHOLD_PCT: ${MEDIA_SOFT_THRESHOLD_PCT:-80}
SNOWFLAKE_MACHINE_ID: ${SNOWFLAKE_MACHINE_ID:-0}
CELEBRITY_FOLLOWER_THRESHOLD: ${CELEBRITY_FOLLOWER_THRESHOLD:-10000}
ports:
- "3000:3000"
healthcheck:
# Use 127.0.0.1 (not localhost): the app binds IPv4 0.0.0.0, but on the
# Linux CI runner `localhost` can resolve to IPv6 ::1 first, where nothing
# listens — so the probe is refused and the container is marked unhealthy
# even though the app is up. Forcing IPv4 makes it deterministic.
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/health || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
frontend:
build:
context: .
dockerfile: frontend/Dockerfile
target: runner
args:
NODE_VERSION: ${NODE_VERSION:-24.16.0}
VITE_API_BASE_URL: ${VITE_API_BASE_URL:-/api/v1}
VITE_WS_URL: ${VITE_WS_URL:-}
depends_on:
backend:
condition: service_healthy
ports:
- "${FRONTEND_PORT:-8080}:8080"
healthcheck:
# IPv4 (see backend healthcheck note) — avoids IPv6 ::1 probe refusal on CI.
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
volumes:
db_data:
minio_data: