лаба 4 на оценку 5

This commit is contained in:
2026-10-30 12:27:49 +03:00
parent 7860d81fa1
commit f9444a3965
59 changed files with 4696 additions and 90 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
set -eu
project_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
secrets_dir="$project_root/secrets"
command -v openssl >/dev/null 2>&1 || {
printf '%s\n' "openssl is required to generate local secrets" >&2
exit 1
}
umask 077
mkdir -p "$secrets_dir"
chmod 700 "$secrets_dir"
write_if_missing() {
destination=$1
value=$2
if [ ! -e "$destination" ]; then
printf '%s' "$value" > "$destination"
fi
chmod 600 "$destination"
}
random_hex() {
openssl rand -hex "$1"
}
write_if_missing "$secrets_dir/postgres_password.txt" "$(random_hex 24)"
postgres_password=$(cat "$secrets_dir/postgres_password.txt")
write_if_missing "$secrets_dir/database_url.txt" \
"postgres://messenger:${postgres_password}@postgres:5432/messenger?sslmode=disable"
write_if_missing "$secrets_dir/cursor_signing_key.txt" "$(random_hex 32)"
write_if_missing "$secrets_dir/minio_root_user.txt" "lab4-root"
write_if_missing "$secrets_dir/minio_root_password.txt" "$(random_hex 24)"
write_if_missing "$secrets_dir/s3_access_key_id.txt" "lab4-api"
write_if_missing "$secrets_dir/s3_secret_access_key.txt" "$(random_hex 24)"
printf '%s\n' "Local secret files are present with mode 600; existing values were not overwritten."
+12 -5
View File
@@ -6,13 +6,20 @@ cd "$project_root"
env_file=${ENV_FILE:-.env}
compose() {
docker compose --env-file "$env_file" "$@"
if [ -f "$env_file" ]; then
docker compose --env-file "$env_file" "$@"
else
docker compose "$@"
fi
}
# PostgreSQL хранит все обязательные данные и сессии в named volume.
# Redis содержит только восстанавливаемый кеш и намеренно не имеет volume.
compose restart postgres redis
compose up -d --wait postgres redis
# PostgreSQL хранит метаданные и сессии, MinIO — исходные байты вложений;
# оба используют named volumes. Redis содержит только восстанавливаемый кеш.
compose restart postgres redis minio
compose up -d --wait postgres redis minio
# Повторный bootstrap приватного bucket/policy/user обязан быть идемпотентным.
compose run --rm minio-bootstrap >/dev/null
# up восстанавливает желаемое число реплик, включая ранее вручную остановленную.
compose up -d --no-deps api
+9 -1
View File
@@ -9,7 +9,15 @@ cd "$project_root"
env_file=${ENV_FILE:-.env}
matched_container=
for container_id in $(docker compose --env-file "$env_file" ps -a -q api); do
compose() {
if [ -f "$env_file" ]; then
docker compose --env-file "$env_file" "$@"
else
docker compose "$@"
fi
}
for container_id in $(compose ps -a -q api); do
instance_id=$(docker inspect --format '{{.Config.Hostname}}' "$container_id")
if [ "$instance_id" = "$TARGET_INSTANCE_ID" ]; then
if [ -n "$matched_container" ]; then