forked from mtusi2026/mtusi2026lab3
74 lines
2.0 KiB
YAML
74 lines
2.0 KiB
YAML
services:
|
|
db:
|
|
image: postgres:16.9-bookworm
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
|
|
secrets: [db_password]
|
|
volumes: [postgres_data:/var/lib/postgresql/data]
|
|
cpus: 1.0
|
|
mem_limit: 512m
|
|
healthcheck:
|
|
test: [CMD-SHELL, 'pg_isready -U messenger -d messenger']
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
cache:
|
|
image: redis:7.4.3-bookworm
|
|
command: [redis-server, --appendonly, 'yes', --appendfsync, everysec]
|
|
volumes: [redis_data:/data]
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
healthcheck:
|
|
test: [CMD, redis-cli, ping]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
migrate:
|
|
build: .
|
|
command: [python, -m, src.migrate]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets: [database_url]
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
depends_on:
|
|
db: {condition: service_healthy}
|
|
healthcheck: {disable: true}
|
|
api:
|
|
build: .
|
|
scale: 2
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL: redis://cache:6379/0
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
DB_POOL_MAX: ${DB_POOL_MAX:-8}
|
|
secrets: [database_url]
|
|
dns_opt: ['timeout:1', 'attempts:1']
|
|
cpus: ${API_CPU:-1.0}
|
|
mem_limit: ${API_MEMORY:-256m}
|
|
stop_grace_period: 10s
|
|
depends_on:
|
|
migrate: {condition: service_completed_successfully}
|
|
cache: {condition: service_healthy}
|
|
healthcheck:
|
|
test: [CMD, python, /app/scripts/healthcheck.py]
|
|
interval: 2s
|
|
timeout: 4s
|
|
retries: 30
|
|
lb:
|
|
image: haproxy:3.0.11-bookworm
|
|
ports: ['127.0.0.1:${APP_PORT:-8080}:8080']
|
|
volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro']
|
|
cpus: 0.5
|
|
mem_limit: 128m
|
|
depends_on:
|
|
api: {condition: service_healthy}
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
secrets:
|
|
db_password: {file: .secrets/db_password}
|
|
database_url: {file: .secrets/database_url}
|