Реализована лабораторная 6 на оценку 4

This commit is contained in:
MacBook
2026-11-16 15:16:54 +03:00
parent 470d9d6f1e
commit 4262a16ada
64 changed files with 8467 additions and 43 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
mkdir -p secrets
if [ ! -f secrets/postgres_password ]; then
umask 077
openssl rand -hex 24 > secrets/postgres_password
fi
if [ ! -f secrets/redis_password ]; then
umask 077
openssl rand -hex 24 > secrets/redis_password
fi
postgres_password=$(cat secrets/postgres_password)
redis_password=$(cat secrets/redis_password)
umask 077
printf 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable\n' "$postgres_password" > secrets/database_url
printf 'redis://:%s@redis:6379/0\n' "$redis_password" > secrets/cache_url
if [ ! -f .env ]; then cp .env.example .env; fi
for secret_name in s3_admin_access s3_admin_secret s3_access_key_id s3_secret_access_key; do
if [ ! -f "secrets/$secret_name" ]; then openssl rand -hex 24 > "secrets/$secret_name"; fi
done
printf '%s\n' 'S3 credentials ready; bucket and policy are bootstrapped by s3-init.'
if [ ! -f secrets/broker_password ]; then openssl rand -hex 24 > secrets/broker_password; fi
broker_password=$(cat secrets/broker_password)
printf 'redis://:%s@broker:6379/0\n' "$broker_password" > secrets/broker_url
if [ ! -f secrets/grafana_admin_password ]; then openssl rand -hex 24 > secrets/grafana_admin_password; fi
+28
View File
@@ -0,0 +1,28 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
wait_healthy() {
service=$1
container_id=$(docker compose --env-file .env ps -q "$service")
attempts=0
until [ "$(docker inspect --format '{{.State.Health.Status}}' "$container_id" 2>/dev/null || true)" = healthy ]; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 60 ]; then
printf '%s\n' "$service did not become healthy" >&2
exit 1
fi
sleep 1
done
}
docker compose --env-file .env restart postgres redis s3 broker >/dev/null
wait_healthy postgres
wait_healthy redis
wait_healthy s3
wait_healthy broker
docker compose --env-file .env restart api1 api2 cleanup dispatcher worker >/dev/null
wait_healthy api1
wait_healthy api2
docker compose --env-file .env restart nginx otel-collector prometheus loki tempo grafana >/dev/null
wait_healthy nginx
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
docker compose --env-file .env start api1 api2 >/dev/null
for service in api1 api2; do
container_id=$(docker compose --env-file .env ps -q "$service")
attempts=0
until [ "$(docker inspect --format '{{.State.Health.Status}}' "$container_id" 2>/dev/null || true)" = healthy ]; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 60 ]; then
printf '%s\n' "$service did not become healthy" >&2
exit 1
fi
sleep 1
done
done
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
case "$TARGET_INSTANCE_ID" in
api-1) service=api1 ;;
api-2) service=api2 ;;
*) printf '%s\n' "Unknown API instance alias" >&2; exit 2 ;;
esac
docker compose --env-file .env stop --timeout 3 "$service" >/dev/null