Исходная точка lab3: код из solution/bvt2302-bodanyuk лабы 2, коммит ef44e48 (PR mtusi2026/mtusi2026lab2#42 принят). README, COURSE, contracts/ и tests/ преподавателя не тронуты; к Makefile дописан студенческий раздел lab2, .env.example — версия lab2. Исследование трека 2 lab2 (bench/track2) не переносилось. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
3.5 KiB
YAML
109 lines
3.5 KiB
YAML
# Lab 2 stand: API + PostgreSQL + Valkey. Start from a clean clone:
|
|
# python scripts/init_secrets.py # once: random local credentials into ./secrets (git-ignored)
|
|
# cp .env.example .env # optional overrides
|
|
# docker compose up -d --build --wait
|
|
# Images are pinned by version AND digest. Passwords are passed only as secret files.
|
|
name: mtusi-lab2
|
|
|
|
x-api-env: &api-env
|
|
APP_ENV: ${APP_ENV:-lab}
|
|
LOG_LEVEL: ${LOG_LEVEL:-info}
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
SESSION_STORE: ${SESSION_STORE:-valkey}
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
DB_POOL_MIN: ${DB_POOL_MIN:-1}
|
|
DB_POOL_MAX: ${DB_POOL_MAX:-10}
|
|
DB_TIMEOUT_SECONDS: ${DB_TIMEOUT_SECONDS:-3}
|
|
CACHE_TIMEOUT_SECONDS: ${CACHE_TIMEOUT_SECONDS:-0.5}
|
|
PASSWORD_HASH_CONCURRENCY: ${PASSWORD_HASH_CONCURRENCY:-2}
|
|
DOCS_ENABLED: ${DOCS_ENABLED:-true}
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:18.6-bookworm@sha256:afc7e2d441324c0388fa80c3d24f733b4194a4eb7f47dd8ee2b08eb1a24a647c
|
|
environment:
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets: [postgres_password]
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql # PostgreSQL 18 image keeps PGDATA under this path
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger -q"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 10s
|
|
stop_grace_period: 30s # clean shutdown checkpoint instead of crash recovery
|
|
restart: unless-stopped
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.1.3-bookworm@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571
|
|
# The password goes into a config include readable only by the valkey user,
|
|
# so it never appears in the process arguments. docker-entrypoint.sh drops root.
|
|
command:
|
|
- sh
|
|
- -c
|
|
- >-
|
|
umask 077 &&
|
|
printf 'requirepass %s\n' "$$(cat /run/secrets/valkey_password)" > /tmp/requirepass.conf &&
|
|
chown valkey /tmp/requirepass.conf &&
|
|
exec docker-entrypoint.sh valkey-server /etc/valkey/valkey.conf
|
|
secrets: [valkey_password]
|
|
volumes:
|
|
- ./infra/valkey/valkey.conf:/etc/valkey/valkey.conf:ro
|
|
- valkeydata:/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/valkey_password)\" valkey-cli ping | grep -q PONG"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 5s
|
|
restart: unless-stopped
|
|
|
|
migrate:
|
|
build: .
|
|
image: mtusi-messenger:lab2
|
|
command: ["python", "-m", "messenger.migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
secrets: [database_url]
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
disable: true
|
|
restart: "no"
|
|
|
|
api:
|
|
build: .
|
|
image: mtusi-messenger:lab2
|
|
environment: *api-env
|
|
secrets: [database_url, cache_url]
|
|
ports:
|
|
- "127.0.0.1:${APP_PUBLISH_PORT:-8080}:8080" # only on localhost of the host
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
valkey:
|
|
condition: service_healthy
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
pgdata:
|
|
valkeydata:
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
valkey_password:
|
|
file: ./secrets/valkey_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
cache_url:
|
|
file: ./secrets/cache_url
|