feat: add redis

This commit is contained in:
2026-10-21 11:01:29 +03:00
parent ab2bbeef83
commit 552b74eb95
10 changed files with 240 additions and 9 deletions
+25 -1
View File
@@ -12,7 +12,9 @@ services:
cd /secrets
[ -s pg_password ] || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > pg_password
printf 'postgresql://messenger:%s@postgres:5432/messenger?connection_limit=10&pool_timeout=5&connect_timeout=5&socket_timeout=10&application_name=api&options=-c%%20statement_timeout%%3D5000' "$$(cat pg_password)" > database_url
chmod 0444 pg_password database_url
[ -s redis_password ] || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > redis_password
printf 'redis://:%s@redis:6379/0' "$$(cat redis_password)" > cache_url
chmod 0444 pg_password database_url redis_password cache_url
postgres:
image: postgres:17.2-alpine
@@ -33,6 +35,25 @@ services:
condition: service_completed_successfully
restart: unless-stopped
redis:
image: redis:7.4.1-alpine
user: redis
command:
- sh
- -c
- exec redis-server --save '' --appendonly no --maxmemory 64mb --maxmemory-policy allkeys-lru --requirepass "$$(cat /run/secrets/redis_password)"
volumes:
- secrets:/run/secrets:ro
healthcheck:
test: ["CMD-SHELL", "redis-cli --no-auth-warning -a \"$$(cat /run/secrets/redis_password)\" ping | grep -q PONG"]
interval: 5s
timeout: 3s
retries: 10
depends_on:
secrets-init:
condition: service_completed_successfully
restart: unless-stopped
migrate:
build:
context: .
@@ -57,6 +78,7 @@ services:
APP_ENV: ${APP_ENV:-lab}
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
@@ -64,6 +86,8 @@ services:
depends_on:
migrate:
condition: service_completed_successfully
redis:
condition: service_started
restart: unless-stopped
tools: