Files
mtusi2026lab3/compose.yaml
T

80 lines
2.6 KiB
YAML

services:
migrate:
build: .
command: ["python", "server.py"]
environment:
RUN_MIGRATIONS_ONLY: "1"
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger}
CACHE_URL: redis://valkey:6379/0
depends_on:
postgres: { condition: service_healthy }
valkey: { condition: service_healthy }
restart: "no"
api:
build: .
restart: unless-stopped
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
CURSOR_SECRET: ${CURSOR_SECRET:?Set CURSOR_SECRET in .env}
DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger}
CACHE_URL: redis://valkey:6379/0
DB_POOL_MAX: ${DB_POOL_MAX:-10}
DB_POOL_MIN: ${DB_POOL_MIN:-1}
depends_on:
migrate: { condition: service_completed_successfully }
valkey: { condition: service_healthy }
cpus: ${API_CPUS:-1.0}
mem_limit: ${API_MEMORY:-512m}
stop_grace_period: 10s
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"]
interval: 2s
timeout: 3s
retries: 2
start_period: 10s
postgres:
image: postgres:16.4-bookworm
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-messenger}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-messenger}
volumes: ["postgres_data:/var/lib/postgresql/data"]
cpus: 2.0
mem_limit: 1g
healthcheck:
test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""]
interval: 3s
timeout: 3s
retries: 20
valkey:
image: valkey/valkey:8.0.1-alpine
restart: unless-stopped
command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec"]
volumes: ["valkey_data:/data"]
cpus: 0.25
mem_limit: 128m
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 3s
timeout: 3s
retries: 10
haproxy:
image: haproxy:3.0.8-alpine
restart: unless-stopped
ports: ["127.0.0.1:${APP_PORT:-8080}:8080"]
volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"]
depends_on: [api]
cpus: ${LB_CPUS:-0.25}
mem_limit: 128m
healthcheck:
test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]
interval: 10s
timeout: 3s
retries: 3
volumes:
postgres_data:
valkey_data: