ЛР 5 — асинхронная обработка и версии pipeline

This commit is contained in:
2026-11-16 02:38:13 +03:00
parent 276dbdad8a
commit 1f535f1b5b
163 changed files with 17194 additions and 24 deletions
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
set -eu
umask 077
cd "$(dirname "$0")/.."
command -v openssl >/dev/null 2>&1 || { echo 'openssl is required' >&2; exit 1; }
mkdir -p secrets
if [ ! -e secrets/postgres_password ] && [ ! -e secrets/database_url ]; then
password=$(openssl rand -hex 24)
printf '%s' "$password" > secrets/postgres_password
printf 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable' "$password" > secrets/database_url
elif [ ! -s secrets/postgres_password ] || [ ! -s secrets/database_url ]; then
echo 'incomplete PostgreSQL secrets; restore the matching pair' >&2
exit 1
fi
if [ ! -e secrets/rustfs_root_access_key ] && [ ! -e secrets/rustfs_root_secret_key ]; then
openssl rand -hex 16 > secrets/rustfs_root_access_key
openssl rand -hex 32 > secrets/rustfs_root_secret_key
elif [ ! -s secrets/rustfs_root_access_key ] || [ ! -s secrets/rustfs_root_secret_key ]; then
echo 'incomplete RustFS root secrets; restore the matching pair' >&2
exit 1
fi
if [ ! -e secrets/s3_access_key_id ] && [ ! -e secrets/s3_secret_access_key ]; then
openssl rand -hex 16 > secrets/s3_access_key_id
openssl rand -hex 32 > secrets/s3_secret_access_key
elif [ ! -s secrets/s3_access_key_id ] || [ ! -s secrets/s3_secret_access_key ]; then
echo 'incomplete API S3 secrets; restore the matching pair' >&2
exit 1
fi
if [ ! -e secrets/rabbitmq_password ] && [ ! -e secrets/broker_url ]; then
broker_password=$(openssl rand -hex 24)
printf '%s' "$broker_password" > secrets/rabbitmq_password
printf 'amqp://messenger:%s@rabbitmq:5672/messenger' "$broker_password" > secrets/broker_url
elif [ ! -s secrets/rabbitmq_password ] || [ ! -s secrets/broker_url ]; then
echo 'incomplete RabbitMQ secrets; restore the matching pair' >&2
exit 1
fi
if [ ! -e .env ]; then
cp .env.example .env
fi
echo 'Local .env and secret files are present. Existing values were kept.'
+43
View File
@@ -0,0 +1,43 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
if [ -f .env ]; then
compose() { docker compose --env-file .env "$@"; }
else
: "${COMPOSE_PROJECT_NAME:?COMPOSE_PROJECT_NAME is required when .env is absent}"
compose() { docker compose "$@"; }
fi
wait_healthy() {
for service in "$@"; do
containers=$(compose ps -q "$service")
[ -n "$containers" ] || { echo "$service has no running containers" >&2; return 1; }
for container in $containers; do
attempts=0
until [ "$(docker inspect --format '{{.State.Health.Status}}' "$container")" = healthy ]; do
attempts=$((attempts + 1))
[ "$attempts" -lt 30 ] || { echo "$service did not become healthy" >&2; return 1; }
sleep 1
done
done
done
}
restart_services() {
for service in "$@"; do
containers=$(compose ps -a -q "$service")
[ -n "$containers" ] || { echo "$service has no containers" >&2; return 1; }
docker restart --timeout 20 $containers >/dev/null
done
}
# Restart only long-running services and preserve their containers and volumes.
compose stop worker relay attachment-cleanup >/dev/null
restart_services postgres redis s3 rabbitmq
wait_healthy postgres redis s3 rabbitmq
restart_services api
wait_healthy api
restart_services lb
restart_services relay worker attachment-cleanup
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
set -eu
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
cd "$(dirname "$0")/.."
for container_id in $(docker compose --env-file .env ps -q api); do
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$container_id")
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
docker stop --timeout 5 "$container_id" >/dev/null
exit 0
fi
done
printf 'API replica %s not found\n' "$TARGET_INSTANCE_ID" >&2
exit 1