run.sh raw
1 #!/bin/sh
2 # Build the binaries, start the rig, run both clients, prove relay failover, tear it down.
3 set -eu
4
5 ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
6 DOCKER="$ROOT/docker"
7 export GOROOT=${GOROOT:-/home/mleku/sdk/go1.24.6}
8 export PATH="$GOROOT/bin:/home/mleku/s/.local/goroot/bin:$PATH"
9
10 echo "== building binaries"
11 mkdir -p "$DOCKER/bin"
12 (cd "$ROOT" && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-testnode" ./cmd/nostrino-testnode \
13 && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-bridge" ./cmd/nostrino-bridge \
14 && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-discover" ./cmd/nostrino-discover \
15 && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-neutrino" ./cmd/nostrino-neutrino)
16 (cd "${TORLY_REPO:-$ROOT/../torly}" && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/torly" ./cmd/torly)
17
18 cd "$DOCKER"
19 compose="docker compose -f compose.yml"
20 cleanup() { $compose --profile clients down -v --remove-orphans >/dev/null 2>&1 || true; }
21 trap cleanup EXIT INT TERM
22
23 echo "== starting relays, nodes and gateways"
24 $compose up -d --wait relay-a relay-b node-btc node-blake node-alt gw-a gw-b
25
26 echo "== waiting for the gateways to be announced on both relays"
27 for attempt in $(seq 1 60); do
28 if $compose exec -T relay-a wget -qO- http://127.0.0.1:3334/health >/dev/null 2>&1 \
29 && $compose run --rm --no-deps client-a sh -c \
30 'nostrino-discover -relay ws://relay-a:3334 -chain btc >/dev/null' >/dev/null 2>&1; then
31 break
32 fi
33 sleep 2
34 done
35
36 echo "== client A, told only about relay-a"
37 $compose run --rm --no-deps client-a
38
39 echo "== client B, told only about relay-b"
40 $compose run --rm --no-deps client-b
41
42 echo "== failover: stop relay-a, a client on relay-b still works"
43 $compose stop relay-a >/dev/null
44 $compose run --rm --no-deps client-b
45
46 echo "== recovery: start relay-a, a client on relay-a works again"
47 $compose start relay-a >/dev/null
48 sleep 4
49 $compose run --rm --no-deps client-a
50
51 echo "== all rig checks passed"
52