Files
mtusi2026lab4/compose.yaml
T

92 lines
2.2 KiB
YAML

name: messenger-lab4
services:
api:
build: .
scale: 2
environment:
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_PASSWORD_FILE: /run/secrets/postgres_password
REDIS_ADDR: redis:6379
secrets: [postgres_password]
cpus: 1.0
mem_limit: 384m
stop_grace_period: 15s
depends_on:
postgres:
condition: service_healthy
migrate:
condition: service_completed_successfully
redis:
condition: service_started
lb:
image: haproxy:3.2.4-alpine
ports:
- "127.0.0.1:${LB_PORT:-8084}:8080"
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
cpus: 0.5
mem_limit: 64m
depends_on:
api:
condition: service_healthy
postgres:
image: postgres:17.9-bookworm
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
POSTGRES_INITDB_ARGS: --encoding=UTF8
secrets: [postgres_password]
volumes:
- postgres_lab4_data_v1:/var/lib/postgresql/data
cpus: 1.0
mem_limit: 512m
healthcheck:
test: [CMD-SHELL, "pg_isready -U messenger -d messenger"]
interval: 3s
timeout: 3s
retries: 20
start_period: 10s
stop_grace_period: 30s
redis:
image: redis:7.4.11-alpine
command: [redis-server, --save, "", --appendonly, "no", --maxmemory, 64mb, --maxmemory-policy, allkeys-lru]
tmpfs: [/data]
cpus: 0.25
mem_limit: 128m
healthcheck:
test: [CMD, redis-cli, ping]
interval: 3s
timeout: 2s
retries: 10
migrate:
image: postgres:17.9-bookworm
environment:
PGHOST: postgres
PGUSER: messenger
PGDATABASE: messenger
PGCONNECT_TIMEOUT: "5"
secrets: [postgres_password]
volumes:
- ./migrations:/migrations:ro
entrypoint: [/bin/sh, -ec]
command:
- 'export PGPASSWORD="$$(cat /run/secrets/postgres_password)"; exec psql -X -f /migrations/apply.psql'
cpus: 0.5
mem_limit: 128m
depends_on:
postgres:
condition: service_healthy
secrets:
postgres_password:
file: ./secrets/postgres_password.txt
volumes:
postgres_lab4_data_v1: