Files
mtusi2026lab3/scripts/up.sh
T
Mlvn b1972bcfd8 Реализовать lab3: HAProxy, API×N, идемпотентность и трек 1.
Горизонтальное масштабирование за LB с общими сессиями Redis, X-Instance-Id,
обязательным Idempotency-Key в PostgreSQL, сценариями failover/persistence и
измерением цены масштабирования при фиксированном CPU/RAM бюджете.
2026-11-06 21:07:00 +03:00

38 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Единая последовательность запуска стенда lab3.
# 1) postgres+redis 2) однократные миграции 3) API×N 4) HAProxy
set -eu
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
cd "$ROOT"
if [ ! -f .env ]; then
cp .env.example .env
echo "created .env from .env.example" >&2
fi
API_REPLICAS=$(grep -E '^API_REPLICAS=' .env | cut -d= -f2- || true)
API_REPLICAS=${API_REPLICAS:-2}
docker compose --env-file .env config --quiet
docker compose --env-file .env up -d --build postgres redis
docker compose --env-file .env run --rm --build migrate
docker compose --env-file .env up -d --build --scale "api=${API_REPLICAS}" --no-deps api
docker compose --env-file .env up -d --no-deps lb
echo "waiting for http://127.0.0.1:8080/health/ready via LB..."
deadline=$(( $(date +%s) + 120 ))
while :; do
if curl -fsS "http://127.0.0.1:8080/health/ready" >/dev/null 2>&1; then
echo "ready"
docker compose --env-file .env ps
exit 0
fi
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "timeout waiting for readiness" >&2
docker compose --env-file .env ps >&2 || true
docker compose --env-file .env logs --tail=80 api lb >&2 || true
exit 1
fi
sleep 1
done