/
kreyndelHam
/
Konstructorium
Обзор
Документация
Войти
/
kreyndelHam
/
Konstructorium
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
dev
scripts/docker/verify_dev_stack.sh
81 строка
2 KB
Server
Harden Docker Postgres bind mount and add dev stack verify scripts.
16 май 2026, 00:14
16 май 2026, 00:14
fab433b
Код
Авторство
О чём код?
#!/usr/bin/env bash # Readiness check for docker-compose.services.yml: data dir, infra health, HTTP smoke. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.services.yml}" WAIT_SEC="${WAIT_SEC:-240}" cd "$ROOT" compose() { docker compose -f "$COMPOSE_FILE" "$@" } health_status() { local svc="$1" local cid cid="$(compose ps -q "$svc" 2>/dev/null || true)" if [[ -z "$cid" ]]; then echo "missing" return fi docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}no-healthcheck{{end}}' "$cid" 2>/dev/null || echo "unknown" } wait_healthy() { local svc="$1" local deadline=$((SECONDS + WAIT_SEC)) local st="" while (( SECONDS < deadline )); do st="$(health_status "$svc")" if [[ "$st" == "healthy" ]]; then return 0 fi if [[ "$st" == "missing" ]]; then echo "Service '$svc' has no running container yet (status=$st)." else echo "Waiting for $svc: $st" fi sleep 3 done echo "Timeout waiting for healthy: $svc (last='$st')" return 1 } if ! compose config -q 2>/dev/null; then echo "Invalid compose file: $COMPOSE_FILE" exit 1 fi echo "[1/4] PostgreSQL data directory permissions..." bash "$SCRIPT_DIR/ensure_postgres_data_dir.sh" echo "[2/4] Waiting for db and redis health (timeout ${WAIT_SEC}s)..." wait_healthy db wait_healthy redis echo "[3/4] Waiting for core API health endpoints (timeout ${WAIT_SEC}s)..." deadline=$((SECONDS + WAIT_SEC)) while (( SECONDS < deadline )); do ok=1 curl -fsS "http://127.0.0.1:8001/api/health/" >/dev/null 2>&1 || ok=0 curl -fsS "http://127.0.0.1:8002/api/health/" >/dev/null 2>&1 || ok=0 curl -fsS "http://127.0.0.1:8003/api/models/" >/dev/null 2>&1 || ok=0 if [[ "$ok" -eq 1 ]]; then break fi sleep 4 done curl -fsS "http://127.0.0.1:8001/api/health/" >/dev/null curl -fsS "http://127.0.0.1:8002/api/health/" >/dev/null curl -fsS "http://127.0.0.1:8003/api/models/" >/dev/null echo "[4/4] Redis PING..." if command -v redis-cli >/dev/null 2>&1; then redis-cli -h 127.0.0.1 -p 6379 ping | grep -q PONG else compose exec -T redis redis-cli ping | grep -q PONG fi echo "OK: db/redis healthy; auth, user, product API respond; Redis PONG."