forked from mtusi2026/mtusi2026lab2
ЛР 2: PostgreSQL, сессии в Valkey, кэш истории (трек 1)
This commit is contained in:
+148
@@ -0,0 +1,148 @@
|
||||
name: mtusi-lab2
|
||||
|
||||
secrets:
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
valkey_password:
|
||||
file: ./secrets/valkey_password
|
||||
cache_url:
|
||||
file: ./secrets/cache_url
|
||||
valkey_cache_password:
|
||||
file: ./secrets/valkey_cache_password
|
||||
history_cache_url:
|
||||
file: ./secrets/history_cache_url
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.6-alpine
|
||||
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements"]
|
||||
environment:
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets:
|
||||
- postgres_password
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 10s
|
||||
restart: unless-stopped
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.3-alpine
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- >-
|
||||
exec valkey-server
|
||||
--appendonly yes
|
||||
--appendfsync everysec
|
||||
--maxmemory 128mb
|
||||
--maxmemory-policy noeviction
|
||||
--requirepass "$$(cat /run/secrets/valkey_password)"
|
||||
secrets:
|
||||
- valkey_password
|
||||
volumes:
|
||||
- valkeydata:/data
|
||||
ports:
|
||||
- "127.0.0.1:${VALKEY_PORT:-6379}:6379"
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD-SHELL
|
||||
- 'valkey-cli -a "$$(cat /run/secrets/valkey_password)" ping 2>/dev/null | grep -q PONG'
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
|
||||
valkey-cache:
|
||||
image: valkey/valkey:8.1.3-alpine
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- >-
|
||||
exec valkey-server
|
||||
--save ""
|
||||
--appendonly no
|
||||
--maxmemory 64mb
|
||||
--maxmemory-policy allkeys-lru
|
||||
--requirepass "$$(cat /run/secrets/valkey_cache_password)"
|
||||
secrets:
|
||||
- valkey_cache_password
|
||||
ports:
|
||||
- "127.0.0.1:${VALKEY_CACHE_PORT:-6380}:6379"
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD-SHELL
|
||||
- 'valkey-cli -a "$$(cat /run/secrets/valkey_cache_password)" ping 2>/dev/null | grep -q PONG'
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
|
||||
|
||||
migrate:
|
||||
build:
|
||||
context: .
|
||||
target: migrate
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
secrets:
|
||||
- database_url
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
api:
|
||||
build: .
|
||||
env_file: .env
|
||||
environment:
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
HISTORY_CACHE: ${HISTORY_CACHE:-safe}
|
||||
HISTORY_CACHE_URL_FILE: /run/secrets/history_cache_url
|
||||
HISTORY_CACHE_TTL_SECONDS: ${HISTORY_CACHE_TTL_SECONDS:-30}
|
||||
HISTORY_CACHE_FILL_DELAY_MS: ${HISTORY_CACHE_FILL_DELAY_MS:-0}
|
||||
secrets:
|
||||
- database_url
|
||||
- cache_url
|
||||
- history_cache_url
|
||||
ports:
|
||||
- "${API_PUBLISH_PORT:-8080}:8080"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
valkey-cache:
|
||||
condition: service_started
|
||||
required: false
|
||||
restart: unless-stopped
|
||||
|
||||
cachebench:
|
||||
profiles: ["bench"]
|
||||
build:
|
||||
context: .
|
||||
target: cachebench
|
||||
secrets:
|
||||
- database_url
|
||||
- history_cache_url
|
||||
volumes:
|
||||
- ./evidence:/evidence
|
||||
restart: "no"
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
valkeydata:
|
||||
Reference in New Issue
Block a user