forked from mtusi2026/mtusi2026lab4
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
||
# Единая последовательность запуска стенда lab4 (postgres, redis, minio, minio-init, migrate, api×N, lb).
|
||
set -eu
|
||
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||
cd "$ROOT"
|
||
COMPOSE="docker compose -p gavrilenko-lab4 --env-file .env"
|
||
|
||
if [ ! -f .env ]; then
|
||
cp .env.example .env
|
||
echo "created .env from .env.example" >&2
|
||
fi
|
||
|
||
API_REPLICAS=$(grep -E '^API_REPLICAS=' .env | tail -n1 | cut -d= -f2- || true)
|
||
API_REPLICAS=${API_REPLICAS:-2}
|
||
LB_PORT=$(grep -E '^LB_HOST_PORT=' .env | tail -n1 | cut -d= -f2- || true)
|
||
LB_PORT=${LB_PORT:-8081}
|
||
|
||
$COMPOSE config --quiet
|
||
$COMPOSE up -d --build --wait postgres redis minio
|
||
$COMPOSE run --rm minio-init
|
||
$COMPOSE run --rm --build migrate
|
||
$COMPOSE up -d --build --scale "api=${API_REPLICAS}" --no-deps api
|
||
$COMPOSE up -d --no-deps lb
|
||
|
||
echo "waiting for http://127.0.0.1:${LB_PORT}/health/ready via LB..."
|
||
deadline=$(( $(date +%s) + 120 ))
|
||
while :; do
|
||
if curl -fsS "http://127.0.0.1:${LB_PORT}/health/ready" >/dev/null 2>&1; then
|
||
echo "ready"
|
||
$COMPOSE ps
|
||
exit 0
|
||
fi
|
||
if [ "$(date +%s)" -ge "$deadline" ]; then
|
||
echo "timeout waiting for readiness" >&2
|
||
$COMPOSE ps >&2 || true
|
||
$COMPOSE logs --tail=80 api lb minio >&2 || true
|
||
exit 1
|
||
fi
|
||
sleep 1
|
||
done |