forked from mtusi2026/mtusi2026lab3
71 lines
1.8 KiB
YAML
71 lines
1.8 KiB
YAML
name: lyakhonov-lab3
|
|
x-api: &api
|
|
image: lyakhonov-messenger:lab3
|
|
build: .
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL: redis://redis:6379/0
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
POOL_SIZE: ${POOL_SIZE:-10}
|
|
OPTIMIZED_WRITES: ${OPTIMIZED_WRITES:-1}
|
|
secrets: [database_url]
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
cpus: ${API_CPUS:-0.5}
|
|
mem_limit: ${API_MEMORY:-256m}
|
|
stop_grace_period: 12s
|
|
services:
|
|
db:
|
|
image: postgres:16.6-alpine
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets: [db_password]
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
healthcheck:
|
|
test: [CMD-SHELL, "pg_isready -U messenger -d messenger"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 30
|
|
cpus: 1
|
|
mem_limit: 512m
|
|
redis:
|
|
image: redis:7.4.1-alpine
|
|
command: [redis-server, --maxmemory, 64mb, --maxmemory-policy, allkeys-lru, --save, "", --appendonly, "no"]
|
|
cpus: 0.25
|
|
mem_limit: 128m
|
|
migrate:
|
|
<<: *api
|
|
command: [python, -m, src.migrate]
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
disable: true
|
|
api:
|
|
<<: *api
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
lb:
|
|
image: haproxy:3.0.6-alpine
|
|
ports: ["127.0.0.1:8080:8080"]
|
|
volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro]
|
|
depends_on: [api]
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
stop_grace_period: 12s
|
|
healthcheck:
|
|
test: [CMD, haproxy, -c, -f, /usr/local/etc/haproxy/haproxy.cfg]
|
|
interval: 5s
|
|
timeout: 2s
|
|
retries: 3
|
|
secrets:
|
|
db_password:
|
|
file: ./secrets/db_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
volumes:
|
|
postgres_data:
|