88 lines
2.4 KiB
YAML
88 lines
2.4 KiB
YAML
name: mtusi-messenger-lab2
|
|
|
|
services:
|
|
|
|
postgres:
|
|
image: postgres:17.6-alpine3.22
|
|
container_name: mtusi-lab2-postgres
|
|
# pg_stat_statements counts executed queries, track 1 uses it to measure the cache stampede.
|
|
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all"]
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: 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: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 10s
|
|
restart: unless-stopped
|
|
|
|
redis:
|
|
image: redis:8.4.0-alpine
|
|
container_name: mtusi-lab2-redis
|
|
# Session cache only, PostgreSQL is the source of truth: no RDB/AOF, a restart simply empties the cache.
|
|
# Every key carries a TTL, so under memory pressure volatile-lru evicts the least used sessions.
|
|
command:
|
|
- sh
|
|
- -c
|
|
- >-
|
|
exec docker-entrypoint.sh redis-server
|
|
--requirepass "$$(cat /run/secrets/redis_password)"
|
|
--save ""
|
|
--appendonly no
|
|
--maxmemory 64mb
|
|
--maxmemory-policy volatile-lru
|
|
secrets:
|
|
- redis_password
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/redis_password)\" redis-cli ping | grep -q PONG"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 10
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
|
|
api:
|
|
build: .
|
|
image: mtusi-messenger:lab2
|
|
container_name: mtusi-lab2-api
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
environment:
|
|
APP_HOST: "0.0.0.0"
|
|
APP_PORT: "8080"
|
|
DB_HOST: postgres
|
|
DB_PORT: "5432"
|
|
DB_NAME: messenger
|
|
DB_USER: messenger
|
|
DB_PASSWORD_FILE: /run/secrets/db_password
|
|
REDIS_HOST: redis
|
|
REDIS_PORT: "6379"
|
|
REDIS_PASSWORD_FILE: /run/secrets/redis_password
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_CACHE_SINGLE_FLIGHT: ${SESSION_CACHE_SINGLE_FLIGHT:-true}
|
|
secrets:
|
|
- db_password
|
|
- redis_password
|
|
ports:
|
|
- "127.0.0.1:8080:8080"
|
|
restart: unless-stopped
|
|
|
|
secrets:
|
|
db_password:
|
|
file: ./secrets/db_password
|
|
redis_password:
|
|
file: ./secrets/redis_password
|
|
|
|
volumes:
|
|
postgres-data:
|