224 lines
8.0 KiB
Bash
Executable File
224 lines
8.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script de validation complète du déploiement LeCoffre Node
|
|
# Vérifie tous les services, volumes, et configurations
|
|
|
|
set -e
|
|
|
|
# Couleurs pour l'affichage
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Compteurs
|
|
TOTAL_CHECKS=0
|
|
PASSED_CHECKS=0
|
|
FAILED_CHECKS=0
|
|
|
|
# Fonction pour afficher un message avec timestamp
|
|
print_message() {
|
|
echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1"
|
|
}
|
|
|
|
# Fonction pour vérifier un service
|
|
check_service() {
|
|
local service_name="$1"
|
|
local description="$2"
|
|
local url="$3"
|
|
local expected_codes_csv="${4:-200}"
|
|
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
|
|
|
|
if docker ps --format '{{.Names}}' | grep -q "^${service_name}$"; then
|
|
local status=$(docker inspect --format='{{.State.Health.Status}}' "$service_name" 2>/dev/null || echo "no-healthcheck")
|
|
local running=$(docker inspect --format='{{.State.Running}}' "$service_name" 2>/dev/null || echo "false")
|
|
|
|
if [ "$running" = "true" ]; then
|
|
if [ -n "$url" ]; then
|
|
local response=$(curl -s -o /dev/null -w '%{http_code}' "$url" 2>/dev/null || echo "000")
|
|
# Support multiple acceptable codes, comma-separated
|
|
local ok=false
|
|
IFS=',' read -r -a expected_array <<< "$expected_codes_csv"
|
|
for code in "${expected_array[@]}"; do
|
|
if [ "$response" = "$code" ]; then ok=true; break; fi
|
|
done
|
|
# If HTTP unreachable from host but container is healthy, accept as running for known cases
|
|
if [ "$response" = "000" ] && [ "$status" = "healthy" ]; then
|
|
echo -e " ${GREEN}✓${NC} $description: Running (container healthy; HTTP check not reachable from host)"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
elif [ "$ok" = true ]; then
|
|
echo -e " ${GREEN}✓${NC} $description: Running and responding (HTTP $response)"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${YELLOW}⚠${NC} $description: Running but not responding (HTTP $response)"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
else
|
|
echo -e " ${GREEN}✓${NC} $description: Running"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗${NC} $description: Not running"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗${NC} $description: Container not found"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
}
|
|
|
|
# Fonction pour vérifier un volume
|
|
check_volume() {
|
|
local volume_name="$1"
|
|
local description="$2"
|
|
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
|
|
|
|
if docker volume inspect "$volume_name" >/dev/null 2>&1; then
|
|
echo -e " ${GREEN}✓${NC} $description: Volume exists"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${RED}✗${NC} $description: Volume not found"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
}
|
|
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE} LeCoffre Node - Deployment Validation${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo
|
|
|
|
print_message "Starting deployment validation..."
|
|
|
|
# Vérification des volumes
|
|
echo -e "${CYAN}=== Volume Validation ===${NC}"
|
|
check_volume "4nk_node_bitcoin_data" "Bitcoin Signet Data"
|
|
check_volume "4nk_node_blindbit_data" "BlindBit Oracle Data"
|
|
check_volume "4nk_node_sdk_data" "SDK Relay Data"
|
|
check_volume "4nk_node_sdk_storage_data" "SDK Storage Data"
|
|
check_volume "4nk_node_grafana_data" "Grafana Data"
|
|
check_volume "4nk_node_loki_data" "Loki Data"
|
|
echo
|
|
|
|
# Vérification des services
|
|
echo -e "${CYAN}=== Service Validation ===${NC}"
|
|
check_service "tor-proxy" "Tor Proxy" "" ""
|
|
check_service "bitcoin-signet" "Bitcoin Signet" "" ""
|
|
check_service "blindbit-oracle" "BlindBit Oracle" "http://localhost:8000/tweaks/1" "200"
|
|
check_service "sdk_storage" "SDK Storage" "http://localhost:8081/health" "200"
|
|
check_service "sdk_relay" "SDK Relay" "http://localhost:8091/" "200"
|
|
check_service "lecoffre-front" "LeCoffre Frontend" "http://localhost:3004/lecoffre/" "200,301,302,307,308"
|
|
check_service "ihm_client" "IHM Client" "http://localhost:3003/" "200"
|
|
check_service "grafana" "Grafana" "http://localhost:3005/api/health" "200"
|
|
check_service "status-api" "Status API" "http://localhost:3006/api" "200"
|
|
echo
|
|
|
|
# Vérification des URLs publiques
|
|
echo -e "${CYAN}=== Public URLs Validation ===${NC}"
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 4))
|
|
|
|
urls=(
|
|
"https://dev4.4nkweb.com/status/:Status Page"
|
|
"https://dev4.4nkweb.com/grafana/:Grafana Dashboard"
|
|
"https://dev4.4nkweb.com/:Main Site"
|
|
"https://dev4.4nkweb.com/lecoffre/:LeCoffre App"
|
|
)
|
|
|
|
for url_entry in "${urls[@]}"; do
|
|
url="${url_entry%%:*}"
|
|
name="${url_entry##*:}"
|
|
response=$(curl -s -o /dev/null -w '%{http_code}' "$url" 2>/dev/null || echo "000")
|
|
if [ "$response" = "200" ]; then
|
|
echo -e " ${GREEN}✓${NC} $name: Accessible (HTTP $response)"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${YELLOW}⚠${NC} $name: Not accessible (HTTP $response)"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
done
|
|
echo
|
|
|
|
# Vérification des WebSockets
|
|
echo -e "${CYAN}=== WebSocket Validation ===${NC}"
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 2))
|
|
|
|
ws_urls=(
|
|
"wss://dev3.4nkweb.com/ws/:Bootstrap Relay"
|
|
"wss://dev3.4nkweb.com/ws/:Signer Service"
|
|
)
|
|
|
|
for ws_entry in "${ws_urls[@]}"; do
|
|
ws_url="${ws_entry%%:*}"
|
|
ws_name="${ws_entry##*:}"
|
|
ws_test=$(timeout 3 wscat -c "$ws_url" --no-color 2>/dev/null && echo "connected" || echo "failed")
|
|
if [ "$ws_test" = "connected" ]; then
|
|
echo -e " ${GREEN}✓${NC} $ws_name: Connected"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${YELLOW}⚠${NC} $ws_name: Not connected"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
done
|
|
echo
|
|
|
|
# Vérification des scripts
|
|
echo -e "${CYAN}=== Scripts Validation ===${NC}"
|
|
scripts=(
|
|
"start.sh:Main startup script"
|
|
"backup-data.sh:Data backup script"
|
|
"restore-data.sh:Data restore script"
|
|
"update-images.sh:Image update script"
|
|
"collect-logs.sh:Log collection script"
|
|
"deploy-master.sh:Master deployment script"
|
|
)
|
|
|
|
for script_entry in "${scripts[@]}"; do
|
|
script_name="${script_entry%%:*}"
|
|
script_desc="${script_entry##*:}"
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
|
|
|
|
if [ -f "./scripts/$script_name" ] && [ -x "./scripts/$script_name" ]; then
|
|
echo -e " ${GREEN}✓${NC} $script_desc: Available and executable"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${RED}✗${NC} $script_desc: Missing or not executable"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
done
|
|
echo
|
|
|
|
# Frontend environment sanity check
|
|
echo -e "${CYAN}=== Frontend Env Validation ===${NC}"
|
|
TOTAL_CHECKS=$((TOTAL_CHECKS + 2))
|
|
if docker exec lecoffre-front sh -lc 'test -n "$NEXT_PUBLIC_4NK_URL"'; then
|
|
echo -e " ${GREEN}✓${NC} NEXT_PUBLIC_4NK_URL présent dans le conteneur front"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${YELLOW}⚠${NC} NEXT_PUBLIC_4NK_URL manquant dans le conteneur front"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
if docker exec lecoffre-front sh -lc 'test -n "$NEXT_PUBLIC_4NK_IFRAME_URL"'; then
|
|
echo -e " ${GREEN}✓${NC} NEXT_PUBLIC_4NK_IFRAME_URL présent dans le conteneur front"
|
|
PASSED_CHECKS=$((PASSED_CHECKS + 1))
|
|
else
|
|
echo -e " ${YELLOW}⚠${NC} NEXT_PUBLIC_4NK_IFRAME_URL manquant dans le conteneur front"
|
|
FAILED_CHECKS=$((FAILED_CHECKS + 1))
|
|
fi
|
|
echo
|
|
|
|
# Résumé final
|
|
echo -e "${CYAN}=== Validation Summary ===${NC}"
|
|
echo -e "Total checks: $TOTAL_CHECKS"
|
|
echo -e "Passed: ${GREEN}$PASSED_CHECKS${NC}"
|
|
echo -e "Failed: ${RED}$FAILED_CHECKS${NC}"
|
|
|
|
if [ $FAILED_CHECKS -eq 0 ]; then
|
|
echo -e "${GREEN}🎉 All validations passed! Deployment is healthy.${NC}"
|
|
exit 0
|
|
else
|
|
echo -e "${YELLOW}⚠️ Some validations failed. Please check the issues above.${NC}"
|
|
exit 1
|
|
fi
|