From 6ee4afa1e118ef359d2af3c8e35fdc64ee96e070 Mon Sep 17 00:00:00 2001 From: nav Date: Thu, 14 May 2026 14:44:04 +0000 Subject: [PATCH] chore(script): register guild node via backend-center CLI --- scripts/register-guild-node.sh | 36 ++++++---------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/scripts/register-guild-node.sh b/scripts/register-guild-node.sh index 5ff5082..8c2d33d 100755 --- a/scripts/register-guild-node.sh +++ b/scripts/register-guild-node.sh @@ -25,42 +25,18 @@ if ! docker compose ps backend-center >/dev/null 2>&1; then exit 1 fi -RESULT_JSON=$(docker compose exec -T \ - -e REG_NODE_ID="$NODE_ID" \ - -e REG_NODE_NAME="$NODE_NAME" \ - -e REG_NODE_ENDPOINT="$NODE_ENDPOINT" \ - backend-center node -e " -(async () => { - const nodeId = process.env.REG_NODE_ID; - const name = process.env.REG_NODE_NAME; - const endpoint = process.env.REG_NODE_ENDPOINT; +RESULT_JSON=$(docker compose exec -T backend-center \ + npm run -s cli -- node register --node-id "$NODE_ID" --name "$NODE_NAME" --endpoint "$NODE_ENDPOINT") - const res = await fetch('http://127.0.0.1:7001/api/nodes/register', { - method: 'POST', - headers: { - 'content-type': 'application/json', - 'x-fabric-version': '1', - }, - body: JSON.stringify({ nodeId, name, endpoint }), - }); +OK=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(!!o.ok));" "$RESULT_JSON") - const text = await res.text(); - let data; - try { data = JSON.parse(text); } catch { data = { raw: text }; } - - process.stdout.write(JSON.stringify({ status: res.status, data })); -})(); -" ) - -STATUS=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(o.status));" "$RESULT_JSON") - -if [[ "$STATUS" != "201" ]]; then +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.data?.apiKey||'');" "$RESULT_JSON") -NODE_ID_OUT=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.data?.node?.nodeId||'');" "$RESULT_JSON") +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