forked from mtusi2026/mtusi2026lab3
130 lines
3.3 KiB
YAML
130 lines
3.3 KiB
YAML
name: messenger-lab3
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:17.6-alpine3.22
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets: [postgres_password]
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
networks: [data]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "1.0", memory: 512M}
|
|
stop_grace_period: 30s
|
|
restart: unless-stopped
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.1.4-alpine3.22
|
|
command: ["valkey-server", "/run/secrets/valkey_conf"]
|
|
secrets: [valkey_conf]
|
|
networks: [data]
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "valkey-cli ping 2>&1 | grep -qE 'PONG|NOAUTH'"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "0.25", memory: 96M}
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtusi-messenger:lab3
|
|
command: ["python", "-m", "app.migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets: [database_url]
|
|
networks: [data]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "0.25", memory: 128M}
|
|
restart: "no"
|
|
|
|
api:
|
|
build: .
|
|
image: mtusi-messenger:lab3
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: "8080"
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_STORE: postgres
|
|
SESSION_CACHE_MAX_SECONDS: ${SESSION_CACHE_MAX_SECONDS:-300}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
DB_POOL_MAX: ${DB_POOL_MAX:-10}
|
|
secrets: [database_url, cache_url]
|
|
networks: [edge, data]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
valkey:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2).status==200 else 1)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
start_period: 5s
|
|
retries: 3
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits: {cpus: "0.5", memory: 256M}
|
|
stop_signal: SIGTERM
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
|
|
lb:
|
|
image: haproxy:3.2.4-alpine
|
|
volumes:
|
|
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
|
ports:
|
|
- "127.0.0.1:${APP_PORT:-8080}:8080"
|
|
networks: [edge]
|
|
depends_on:
|
|
api:
|
|
condition: service_started
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8405/lb-health"]
|
|
interval: 5s
|
|
timeout: 2s
|
|
retries: 3
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "0.5", memory: 128M}
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
edge: {}
|
|
data:
|
|
internal: true
|
|
|
|
volumes:
|
|
pgdata:
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
cache_url:
|
|
file: ./secrets/cache_url
|
|
valkey_conf:
|
|
file: ./secrets/valkey.conf
|