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

This commit is contained in:
MacBook
2026-11-03 14:05:38 +03:00
parent 276dbdad8a
commit 9db2fa724a
41 changed files with 4267 additions and 37 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/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
+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 >/dev/null
wait_healthy nginx
+25
View File
@@ -0,0 +1,25 @@
#!/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 build migrate >/dev/null
docker compose --env-file .env run --rm --no-deps migrate >/dev/null
for service in api1 api2; do
docker compose --env-file .env up -d --no-deps --force-recreate "$service" >/dev/null
wait_healthy "$service"
docker compose --env-file .env exec -T nginx nginx -s reload >/dev/null
done
+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