48 lines
1.4 KiB
Bash
Executable File
48 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Usage:
|
|
# scripts/register-guild-node.sh <node_id> <name> <endpoint>
|
|
# Example:
|
|
# scripts/register-guild-node.sh guild-node-1 "Guild Node 1" "http://backend-guild:7002"
|
|
|
|
if [[ $# -ne 3 ]]; then
|
|
echo "Usage: $0 <node_id> <name> <endpoint>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
NODE_ID="$1"
|
|
NODE_NAME="$2"
|
|
NODE_ENDPOINT="$3"
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "docker not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! docker compose ps backend-center >/dev/null 2>&1; then
|
|
echo "backend-center service is not available in current docker compose project" >&2
|
|
exit 1
|
|
fi
|
|
|
|
RESULT_JSON=$(docker compose exec -T backend-center \
|
|
npm run -s cli -- node register --node-id "$NODE_ID" --name "$NODE_NAME" --endpoint "$NODE_ENDPOINT")
|
|
|
|
OK=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(!!o.ok));" "$RESULT_JSON")
|
|
|
|
if [[ "$OK" != "true" ]]; then
|
|
echo "registration failed: $RESULT_JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
API_KEY=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.apiKey||'');" "$RESULT_JSON")
|
|
NODE_ID_OUT=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.node?.nodeId||'');" "$RESULT_JSON")
|
|
|
|
if [[ -z "$API_KEY" ]]; then
|
|
echo "registration succeeded but no apiKey returned: $RESULT_JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Node registered: $NODE_ID_OUT"
|
|
echo "FABRIC_BACKEND_GUILD_CENTER_API_KEY=$API_KEY"
|