137 lines
4.9 KiB
Bash

#!/usr/bin/env sh
set -euo pipefail
# Determine project root and compose dir
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
COMPOSE_DIR="$ROOT_DIR/lecoffre_node"
# Healthcheck helpers now colocated here
HC_TOR="$SCRIPT_DIR/tor-progress.sh"
HC_BITCOIN="$SCRIPT_DIR/bitcoin-progress.sh"
HC_BLINDBIT="$SCRIPT_DIR/blindbit-progress.sh"
HC_RELAY="$SCRIPT_DIR/sdk-relay-progress.sh"
cd "$COMPOSE_DIR"
progress_line() {
svc="$1"; kind="$2"
case "$kind" in
tor) sh "$HC_TOR" 2>/dev/null | tail -1 || true ;;
bitcoin) sh "$HC_BITCOIN" 2>/dev/null | tail -1 || true ;;
blindbit) sh "$HC_BLINDBIT" 2>/dev/null | tail -1 || true ;;
relay) sh "$HC_RELAY" 2>/dev/null | tail -1 || true ;;
*) echo "[$svc] waiting ..." ;;
esac
}
wait_healthy() {
svc="$1"; tries=${2:-60}; sleep_s=${3:-5}; kind=${4:-generic}
i=0
while [ $i -lt $tries ]; do
state=$(docker inspect --format='{{json .State.Health.Status}}' "$svc" 2>/dev/null || echo "\"unknown\"")
[ "$state" = '"healthy"' ] && { echo "[$svc] healthy"; return 0; }
progress_line "$svc" "$kind"
sleep "$sleep_s"; i=$((i+1))
done
echo "[$svc] not healthy after wait"; return 1
}
check_ports_urls() {
svc="$1"
case "$svc" in
tor-proxy)
# Ports: 9050-9051 local; no HTTP
nc -z 127.0.0.1 9050 && echo "[tor] port 9050 OK" || echo "[tor] 9050 FAIL" || true
nc -z 127.0.0.1 9051 && echo "[tor] port 9051 OK" || echo "[tor] 9051 FAIL" || true
;;
bitcoin-signet)
# Internal RPC port (38332 signet), no external URL
nc -z 127.0.0.1 38332 && echo "[bitcoin] RPC 38332 OK" || echo "[bitcoin] 38332 FAIL" || true
;;
blindbit-oracle)
# Internal: http://localhost:8000/tweaks/1
curl -fsS http://127.0.0.1:8000/tweaks/1 >/dev/null && echo "[blindbit] API OK" || echo "[blindbit] API FAIL" || true
;;
sdk_storage)
curl -fsS http://127.0.0.1:8081/health >/dev/null && echo "[storage] health OK" || echo "[storage] health FAIL" || true
;;
sdk_relay)
# WS bind + HTTP health
curl -fsS http://127.0.0.1:8091/ >/dev/null && echo "[relay] health port 8091 OK" || echo "[relay] 8091 FAIL" || true
nc -z 0.0.0.0 8090 && echo "[relay] ws 8090 OK" || echo "[relay] ws 8090 FAIL" || true
# Third-party bootstrap
curl -fsS https://dev3.4nkweb.com/api/v1/health >/dev/null && echo "[relay] dev3 api OK" || echo "[relay] dev3 api FAIL" || true
;;
ihm_client)
curl -fsS http://127.0.0.1:3003/ >/dev/null && echo "[ihm] local OK" || echo "[ihm] local FAIL" || true
;;
lecoffre-front)
curl -fsS http://127.0.0.1:3004/ >/dev/null && echo "[front] local OK" || echo "[front] local FAIL" || true
# External front
curl -fsS https://dev4.4nkweb.com/lecoffre/ >/dev/null && echo "[front] external OK" || echo "[front] external FAIL" || true
;;
loki)
curl -fsS http://127.0.0.1:3100/ready >/dev/null && echo "[loki] ready OK" || echo "[loki] ready FAIL" || true
;;
promtail)
echo "[promtail] positions/inputs checked by health" ;;
grafana)
curl -fsS http://127.0.0.1:3005/api/health >/dev/null && echo "[grafana] local api OK" || echo "[grafana] local api FAIL" || true
curl -fsS https://dev4.4nkweb.com/grafana/ >/dev/null && echo "[grafana] external OK" || echo "[grafana] external FAIL" || true
;;
status-api)
curl -fsS http://127.0.0.1:3006/api >/dev/null && echo "[status] api OK" || echo "[status] api FAIL" || true
;;
esac
}
# Phase 1: base
docker compose up -d tor || true
wait_healthy tor-proxy 80 3 tor || true
check_ports_urls tor-proxy || true
# Phase 2: blockchain
docker compose up -d bitcoin || true
wait_healthy bitcoin-signet 120 5 bitcoin || true
check_ports_urls bitcoin-signet || true
docker compose up -d blindbit || true
wait_healthy blindbit-oracle 120 5 blindbit || true
check_ports_urls blindbit-oracle || true
# Phase 3: apps (storage -> relay -> ihm/front)
docker compose up -d sdk_storage || true
wait_healthy sdk_storage 60 5 || true
check_ports_urls sdk_storage || true
docker compose up -d sdk_relay || true
wait_healthy sdk_relay 120 5 relay || true
check_ports_urls sdk_relay || true
docker compose up -d ihm_client lecoffre-front || true
wait_healthy ihm_client 60 5 || true
check_ports_urls ihm_client || true
wait_healthy lecoffre-front 60 5 || true
check_ports_urls lecoffre-front || true
# Phase 4: monitoring (loki -> promtail -> grafana)
docker compose up -d loki || true
wait_healthy loki 120 5 || true
check_ports_urls loki || true
docker compose up -d promtail || true
wait_healthy promtail 60 5 || true
check_ports_urls promtail || true
docker compose up -d grafana || true
wait_healthy grafana 120 5 || true
check_ports_urls grafana || true
# Phase 5: utils
docker compose up -d status-api watchtower || true
wait_healthy status-api 60 5 || true
check_ports_urls status-api || true
echo "[OK] Déploiement séquentiel terminé"