Собрать стенд из API, PostgreSQL и Valkey с хуком перезапуска
This commit is contained in:
+73
-3
@@ -1,12 +1,82 @@
|
||||
# Local stand: the API over PostgreSQL (users, chats, messages) and Valkey
|
||||
# (sessions). Only the API is published, on loopback. Credentials are files in
|
||||
# ./secrets created by `make secrets`; named volumes keep the data across
|
||||
# restarts, and only `make destroy` removes them.
|
||||
services:
|
||||
api:
|
||||
build: .
|
||||
image: mtusi-messenger:lab2
|
||||
# Fixed name so the Makefile targets and student-tests/lifecycle.sh address
|
||||
# the same container whether it was started by compose or by docker run.
|
||||
# Fixed name for docker logs/inspect in the report.
|
||||
container_name: mtusi-messenger-lab2
|
||||
env_file: .env
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
SESSION_STORE_URL_FILE: /run/secrets/session_store_url
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
secrets:
|
||||
- database_url
|
||||
- session_store_url
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
# Loopback only; override with PUBLISH=127.0.0.1:18080 when 8080 is busy.
|
||||
ports:
|
||||
- "${PUBLISH:-127.0.0.1:8080}:8080"
|
||||
stop_grace_period: 10s
|
||||
|
||||
postgres:
|
||||
image: postgres:18.6-alpine3.24@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873
|
||||
environment:
|
||||
POSTGRES_DB: messenger
|
||||
POSTGRES_USER: messenger
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets:
|
||||
- postgres_password
|
||||
# Since PostgreSQL 18 the image keeps PGDATA in a versioned directory
|
||||
# below /var/lib/postgresql, so the volume is mounted on the parent.
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "messenger", "-d", "messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 10s
|
||||
# A clean shutdown writes a checkpoint instead of leaving crash recovery
|
||||
# to the next start.
|
||||
stop_grace_period: 30s
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:9.1.2-alpine3.24@sha256:48332870af354a799964c0012ae1194a0bf2bf894eb508f945810596dc2d8d11
|
||||
command: ["valkey-server", "/usr/local/etc/valkey/valkey.conf"]
|
||||
secrets:
|
||||
- valkey_auth
|
||||
volumes:
|
||||
- ./infra/valkey/valkey.conf:/usr/local/etc/valkey/valkey.conf:ro
|
||||
- valkeydata:/data
|
||||
healthcheck:
|
||||
# valkey-cli exits 0 even on NOAUTH, so the reply itself is checked.
|
||||
test: ["CMD-SHELL", "VALKEYCLI_AUTH=\"$$(sed -n 's/^requirepass //p' /run/secrets/valkey_auth)\" valkey-cli ping | grep -q PONG"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
stop_grace_period: 10s
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
valkeydata:
|
||||
|
||||
secrets:
|
||||
database_url:
|
||||
file: ./secrets/database_url
|
||||
session_store_url:
|
||||
file: ./secrets/session_store_url
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
valkey_auth:
|
||||
file: ./secrets/valkey_auth.conf
|
||||
|
||||
Reference in New Issue
Block a user