An instance decides what it is at startup instead of being told: it generates its own identity, registers a heartbeat, and campaigns for each game. Exactly one instance drives a game's rounds and publishes frames; the rest relay them and forward mutations to the leader. Clone the VM, boot it, done. Sessions and the scratch nonce move to Redis. Both were per-instance state that would have broken behind a load balancer: a token minted by one clone was unknown to the others, and two clones would have handed the same nonce to different players, which for the same key means the same outcome. Fixes a bug found by running two instances: /api/games read the local room object, so a follower reported a permanently settled game and its clients never saw a betting window. Hubs now serve the last frame they saw, produced or relayed. Failover measured at 6s after kill -9 on an instance leading two games. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
49 lines
1.3 KiB
YAML
49 lines
1.3 KiB
YAML
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
environment:
|
|
POSTGRES_USER: arcade
|
|
POSTGRES_PASSWORD: arcade_dev
|
|
POSTGRES_DB: arcade
|
|
ports: ["5432:5432"]
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
- ./migrations:/docker-entrypoint-initdb.d:ro
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U arcade"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
ports: ["6379:6379"]
|
|
volumes:
|
|
- redisdata:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 20
|
|
|
|
arcade:
|
|
build: .
|
|
environment:
|
|
# On a cloned VM, point these at the core machine instead. They are the
|
|
# only configuration a clone needs; identity and role are worked out at
|
|
# runtime. See docs/SCALING.md.
|
|
ARCADE_DSN: postgres://arcade:arcade_dev@postgres:5432/arcade
|
|
ARCADE_REDIS: redis:6379
|
|
ARCADE_ADDR: ":8080"
|
|
# Development funding. Leave unset in any real deployment.
|
|
ARCADE_DEV_FAUCET: "${ARCADE_DEV_FAUCET:-0}"
|
|
ports: ["8080:8080"]
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
redis: { condition: service_healthy }
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
pgdata:
|
|
redisdata:
|