forked from mtusi2026/mtusi2026lab3
97 lines
2.6 KiB
YAML
97 lines
2.6 KiB
YAML
name: mtusi-lab3-osokin
|
|
x-app: &app
|
|
image: mtusi-messenger:lab3
|
|
build: .
|
|
environment:
|
|
APP_HOST: 0.0.0.0
|
|
APP_PORT: 8080
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
SESSION_STORE: redis
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
CURSOR_KEY_FILE: /run/secrets/cursor_key
|
|
secrets: [database_url, cache_url, cursor_key]
|
|
mem_limit: 256m
|
|
cpus: 1
|
|
dns_opt: ['timeout:1', 'attempts:1']
|
|
networks: [backend]
|
|
services:
|
|
db:
|
|
image: postgres:17.6-bookworm
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets: [db_password]
|
|
volumes: [pgdata:/var/lib/postgresql/data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
mem_limit: 512m
|
|
cpus: 2
|
|
networks: [backend]
|
|
redis:
|
|
image: redis:7.4.5-bookworm
|
|
command: [redis-server, /usr/local/etc/redis/redis.conf]
|
|
volumes:
|
|
- redisdata:/data
|
|
- ./infra/redis.conf:/usr/local/etc/redis/redis.conf:ro
|
|
healthcheck:
|
|
test: [CMD, redis-cli, ping]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
mem_limit: 128m
|
|
cpus: 0.5
|
|
networks: [backend]
|
|
migrate:
|
|
<<: *app
|
|
command: [python, -m, messenger.migrate]
|
|
healthcheck: {disable: true}
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
api:
|
|
<<: *app
|
|
scale: ${API_REPLICAS:-2}
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
redis: {condition: service_healthy}
|
|
stop_grace_period: 10s
|
|
healthcheck:
|
|
test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=4)"]
|
|
interval: 2s
|
|
timeout: 5s
|
|
start_period: 5s
|
|
retries: 2
|
|
lb:
|
|
image: haproxy:3.0.16-alpine
|
|
ports: ['127.0.0.1:${APP_PORT:-8080}:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready']
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 5
|
|
stop_grace_period: 10s
|
|
mem_limit: 128m
|
|
cpus: 0.5
|
|
networks: [frontend, backend]
|
|
volumes:
|
|
pgdata:
|
|
redisdata:
|
|
networks:
|
|
frontend:
|
|
backend:
|
|
internal: true
|
|
secrets:
|
|
db_password: {file: ./secrets/db_password}
|
|
database_url: {file: ./secrets/database_url}
|
|
cache_url: {file: ./secrets/cache_url}
|
|
cursor_key: {file: ./secrets/cursor_key}
|