Completed for a grade of three

This commit is contained in:
2026-10-23 14:11:11 +03:00
parent a3dbcd6ba4
commit 92c2fdc254
54 changed files with 1221 additions and 92 deletions
+39 -3
View File
@@ -4,7 +4,6 @@ services:
postgres:
image: postgres:17.6-alpine3.22
container_name: mtusi-lab3-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:
@@ -25,7 +24,6 @@ services:
redis:
image: redis:8.4.0-alpine
container_name: mtusi-lab3-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:
@@ -48,11 +46,36 @@ services:
start_period: 5s
restart: unless-stopped
# One-shot: applies Flyway migrations once and exits. Replicas start only after it succeeded,
# so they never race each other on the schema.
migrate:
build: .
image: mtusi-messenger:lab3
command: ["migrate"]
healthcheck:
disable: true
depends_on:
postgres:
condition: service_healthy
environment:
DB_HOST: postgres
DB_PORT: "5432"
DB_NAME: messenger
DB_USER: messenger
DB_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
restart: "no"
api:
build: .
image: mtusi-messenger:lab3
container_name: mtusi-lab3-api
# Interchangeable replicas: no container_name and no published port, traffic only through `lb`.
deploy:
replicas: ${API_REPLICAS:-2}
depends_on:
migrate:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
@@ -65,14 +88,27 @@ services:
DB_NAME: messenger
DB_USER: messenger
DB_PASSWORD_FILE: /run/secrets/db_password
DB_MIGRATE_ON_START: "false"
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}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
secrets:
- db_password
- redis_password
# SIGTERM: Ktor stops accepting, finishes requests in flight (shutdownGracePeriod 3 s, shutdownTimeout 10 s).
stop_grace_period: 15s
restart: unless-stopped
lb:
image: haproxy:3.2.4-alpine
volumes:
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
ports:
- "127.0.0.1:8080:8080"
restart: unless-stopped