Repository navigation
Expand file tree
/
Copy pathdocker-compose.cluster.yml
More file actions
255 lines (247 loc) · 10.5 KB
/
Copy pathdocker-compose.cluster.yml
File metadata and controls
255 lines (247 loc) · 10.5 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
# Release-compiled 4-node cluster - same topology as docker-compose.cluster.dev.yml, built with
# `swift build -c release` so throughput numbers mean something.
#
# Three differences from the dev stack, all of them the point of this file:
# 1. Each node runs the self-contained production image (alarik/Dockerfile), NOT a debug binary
# off a shared .build volume. There is deliberately no `./alarik:/app` bind mount - it would
# shadow /app/Alarik and the container would have no binary to run at all.
# 2. `--env production`, matching the image's own default CMD.
# 3. LOG_LEVEL defaults to info, not debug. Debug logging dominates the profile under load and
# would make any measurement taken here meaningless.
#
# Its own project name, so containers and storage volumes never collide with the dev stack's -
# the two are alternatives, but you can build one while the other is still up.
name: alarik-cluster
services:
# alarik-1 owns the image build; the other three reference the tag it produces. Compose runs the
# build phase before creating any container, so one `docker compose -f docker-compose.cluster.yml
# up -d --build` compiles release once and starts four containers from it. Bring the stack up as
# a whole - starting a single non-building node before the tag exists has nothing to run.
alarik-1:
build:
context: ./alarik
dockerfile: Dockerfile
image: alarik-cluster:latest
container_name: alarik-cluster-1
restart: unless-stopped
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
ports:
- "8081:8080"
environment:
- LOG_LEVEL=${LOG_LEVEL:-info}
# The load balancer's URL, not this node's own port - every node advertises the same
# externally-reachable address (used for shared-link URLs, OIDC callbacks, etc.) so a link
# generated by any node round-robins across the whole cluster when followed, the same as it
# would behind a real load balancer in production. Distinct from CLUSTER_NODE_ADDRESS below,
# which stays this node's own internal address - that's how peers reach THIS node directly.
- API_BASE_URL=http://localhost:8080
- CONSOLE_BASE_URL=http://localhost:3000
- ADMIN_USERNAME=${ADMIN_USERNAME:-alarik}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-alarik}
- JWT=release-cluster-jwt-secret-at-least-32b
- CLUSTER_NODE_ADDRESS=http://alarik-1:8080
- CLUSTER_SECRET=release-cluster-secret
# Erasure coding sized for this 4-node cluster: k=2 data + m=2 parity shards (one shard per
# node). The default is 4+2, which needs 6 nodes and would fail every write here - a cluster
# must have at least k+m active nodes to accept writes. Tolerates losing any 2 nodes.
- CLUSTER_EC_DATA_SHARDS=2
- CLUSTER_EC_PARITY_SHARDS=2
# Providing default keys is optional but necessary for testing
- DEFAULT_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- DEFAULT_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
volumes:
# Storage only - no source, no .build. See the header note.
- alarik-1-storage:/app/Storage
healthcheck:
# Deliberately no -f: /api/v1/health sits behind `InternalAuthenticator`, so an
# unauthenticated probe gets a 401 - which still proves the server is listening and routing,
# which is all this needs. Same "any response means it's up" reasoning as the lb's check.
test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://127.0.0.1:8080/api/v1/health"]
interval: 3s
timeout: 3s
retries: 30
start_period: 10s
networks:
- alarik-network
alarik-2:
image: alarik-cluster:latest
# Never reach for a registry: this tag is built locally by alarik-1, and a pull attempt would
# fail with a confusing "pull access denied" instead of the real "bring the stack up together".
pull_policy: never
container_name: alarik-cluster-2
restart: unless-stopped
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
ports:
- "8082:8080"
environment:
- LOG_LEVEL=${LOG_LEVEL:-info}
# See alarik-1's API_BASE_URL comment - the load balancer's URL, not this node's own port.
- API_BASE_URL=http://localhost:8080
- CONSOLE_BASE_URL=http://localhost:3000
- ADMIN_USERNAME=${ADMIN_USERNAME:-alarik}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-alarik}
- JWT=release-cluster-jwt-secret-at-least-32b
- CLUSTER_NODE_ADDRESS=http://alarik-2:8080
- CLUSTER_SECRET=release-cluster-secret
- CLUSTER_SEED_NODES=http://alarik-1:8080
# Erasure coding sized for this 4-node cluster - see alarik-1.
- CLUSTER_EC_DATA_SHARDS=2
- CLUSTER_EC_PARITY_SHARDS=2
- DEFAULT_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- DEFAULT_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
volumes:
- alarik-2-storage:/app/Storage
healthcheck:
test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://127.0.0.1:8080/api/v1/health"]
interval: 3s
timeout: 3s
retries: 30
start_period: 10s
depends_on:
alarik-1:
condition: service_healthy
networks:
- alarik-network
alarik-3:
image: alarik-cluster:latest
pull_policy: never
container_name: alarik-cluster-3
restart: unless-stopped
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
ports:
- "8083:8080"
environment:
- LOG_LEVEL=${LOG_LEVEL:-info}
# See alarik-1's API_BASE_URL comment - the load balancer's URL, not this node's own port.
- API_BASE_URL=http://localhost:8080
- CONSOLE_BASE_URL=http://localhost:3000
- ADMIN_USERNAME=${ADMIN_USERNAME:-alarik}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-alarik}
- JWT=release-cluster-jwt-secret-at-least-32b
- CLUSTER_NODE_ADDRESS=http://alarik-3:8080
- CLUSTER_SECRET=release-cluster-secret
- CLUSTER_SEED_NODES=http://alarik-1:8080
# Erasure coding sized for this 4-node cluster - see alarik-1.
- CLUSTER_EC_DATA_SHARDS=2
- CLUSTER_EC_PARITY_SHARDS=2
- DEFAULT_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- DEFAULT_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
volumes:
- alarik-3-storage:/app/Storage
healthcheck:
test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://127.0.0.1:8080/api/v1/health"]
interval: 3s
timeout: 3s
retries: 30
start_period: 10s
depends_on:
alarik-1:
condition: service_healthy
networks:
- alarik-network
alarik-4:
image: alarik-cluster:latest
pull_policy: never
container_name: alarik-cluster-4
restart: unless-stopped
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
ports:
- "8084:8080"
environment:
- LOG_LEVEL=${LOG_LEVEL:-info}
# See alarik-1's API_BASE_URL comment - the load balancer's URL, not this node's own port.
- API_BASE_URL=http://localhost:8080
- CONSOLE_BASE_URL=http://localhost:3000
- ADMIN_USERNAME=${ADMIN_USERNAME:-alarik}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-alarik}
- JWT=release-cluster-jwt-secret-at-least-32b
- CLUSTER_NODE_ADDRESS=http://alarik-4:8080
- CLUSTER_SECRET=release-cluster-secret
- CLUSTER_SEED_NODES=http://alarik-1:8080
# Erasure coding sized for this 4-node cluster - see alarik-1.
- CLUSTER_EC_DATA_SHARDS=2
- CLUSTER_EC_PARITY_SHARDS=2
- DEFAULT_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- DEFAULT_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
volumes:
- alarik-4-storage:/app/Storage
healthcheck:
test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://127.0.0.1:8080/api/v1/health"]
interval: 3s
timeout: 3s
retries: 30
start_period: 10s
depends_on:
alarik-1:
condition: service_healthy
networks:
- alarik-network
# Round-robins across all four nodes - the console, aws-cli, or any other S3 client pointed at
# this one URL actually exercises cross-node routing/forwarding instead of always landing on the
# same node, the same as a real load balancer in front of a production cluster. Any node can
# serve any request, so there's no "primary" to pick.
#
# Shares nginx/cluster.dev.conf with the dev stack rather than duplicating it: the upstreams are
# resolved by SERVICE name (alarik-1..4), which is identical in both files, so one config serves
# both and can't drift out of sync with the other.
lb:
image: nginx:alpine
container_name: alarik-cluster-lb
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./nginx/cluster.dev.conf:/etc/nginx/conf.d/default.conf:ro
healthcheck:
# nginx:alpine's busybox ash doesn't support /dev/tcp redirection - curl is available on the
# image instead. Deliberately no -f/--fail: any response at all (even a non-2xx from
# whichever backend nginx proxied to) means nginx itself is up and can reach the cluster.
test: ["CMD", "curl", "-s", "-o", "/dev/null", "http://127.0.0.1/"]
interval: 3s
timeout: 3s
retries: 10
start_period: 3s
depends_on:
alarik-1:
condition: service_healthy
alarik-2:
condition: service_healthy
alarik-3:
condition: service_healthy
alarik-4:
condition: service_healthy
networks:
- alarik-network
# Production build (console/Dockerfile): a prerendered Nuxt bundle served by node, with no source
# bind mount and no HMR port. Nuxt still reads NUXT_PUBLIC_* at runtime, so the URLs below apply
# to the built server without rebuilding the image.
console:
build:
context: ./console
dockerfile: Dockerfile
image: alarik-cluster-console:latest
container_name: alarik-cluster-console
restart: unless-stopped
ports:
- "3000:3000"
environment:
- NODE_ENV=production
# Nuxt's runtimeConfig.public only auto-reads env vars with the NUXT_PUBLIC_ prefix (see
# console/nuxt.config.ts) - a bare API_BASE_URL is silently ignored and the console falls
# back to its hardcoded default (localhost:8080). Points at the load balancer, not any one
# node directly, so the console's own traffic distributes across the cluster too.
- NUXT_PUBLIC_API_BASE_URL=http://localhost:8080
- NUXT_PUBLIC_CONSOLE_BASE_URL=http://localhost:3000
depends_on:
lb:
condition: service_healthy
networks:
- alarik-network
networks:
alarik-network:
driver: bridge
volumes:
alarik-1-storage:
alarik-2-storage:
alarik-3-storage:
alarik-4-storage: