chore(infra): redis service with AOF persistence

This commit is contained in:
Голиков Maximillian Антон
2026-10-02 14:42:55 +03:00
parent 812efa67bb
commit eaf04c4769
3 changed files with 54 additions and 13 deletions
+30
View File
@@ -21,6 +21,28 @@ services:
networks:
- internal
redis:
image: redis:7.4-alpine
restart: unless-stopped
command:
- redis-server
- --appendonly
- "yes"
- --appendfsync
- everysec
- --save
- "60 1000"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
networks:
- internal
api:
build:
context: .
@@ -33,12 +55,17 @@ services:
APP_HOST: "0.0.0.0"
APP_PORT: "8080"
DATABASE_URL_FILE: /run/secrets/database_url
CACHE_URL_FILE: /run/secrets/cache_url
SESSION_STORE: "redis"
SESSION_TTL_SECONDS: "3600"
secrets:
- database_url
- cache_url
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:8080/health/ready >/dev/null || exit 1"]
interval: 10s
@@ -53,9 +80,12 @@ secrets:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
cache_url:
file: ./secrets/cache_url
volumes:
postgres_data:
redis_data:
networks:
internal:
+5
View File
@@ -0,0 +1,5 @@
@echo off
setlocal
set SCRIPT_DIR=%~dp0
bash "%SCRIPT_DIR%restart.sh"
exit /b %ERRORLEVEL%
+19 -13
View File
@@ -3,7 +3,6 @@ set -eu
# Перезапускает API и все используемые хранилища, сохраняя volumes и данные.
# Не удаляет volumes, не пересоздаёт схему, не сидит данные заново.
# Возвращает 0 только после фактической остановки и запуска контейнеров.
cd "$(dirname "$0")/.."
@@ -16,21 +15,28 @@ if [ ! -f .env ]; then
: > .env
fi
echo "[restart] останавливаем api и postgres" >&2
$COMPOSE --env-file .env stop api postgres
echo "[restart] останавливаем api, postgres, redis" >&2
$COMPOSE --env-file .env stop api postgres redis
echo "[restart] запускаем postgres и ждём healthy" >&2
echo "[restart] запускаем postgres" >&2
$COMPOSE --env-file .env start postgres
wait_healthy() {
service="$1"
i=0
until [ "$($COMPOSE ps -q "$service" | xargs -r docker inspect -f '{{.State.Health.Status}}' 2>/dev/null)" = "healthy" ]; do
i=$((i + 1))
if [ "$i" -gt 60 ]; then
echo "[restart] $service не стал healthy за 60 секунд" >&2
exit 1
fi
sleep 1
done
}
wait_healthy postgres
i=0
until [ "$($COMPOSE ps -q postgres | xargs -r docker inspect -f '{{.State.Health.Status}}' 2>/dev/null)" = "healthy" ]; do
i=$((i + 1))
if [ "$i" -gt 60 ]; then
echo "[restart] postgres не стал healthy за 60 секунд" >&2
exit 1
fi
sleep 1
done
echo "[restart] запускаем redis" >&2
$COMPOSE --env-file .env start redis
wait_healthy redis
echo "[restart] запускаем api" >&2
$COMPOSE --env-file .env start api