89 lines
3.2 KiB
Bash
Executable File
89 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)
|
|
# shellcheck source=process-lib.sh
|
|
source "$ROOT/tools/process-lib.sh"
|
|
ANVIL_DEV_WORDS=(test test test test test test test test test test test junk)
|
|
CLEANING=0
|
|
ANVIL_PID='' ANVIL_START='' ANVIL_PGID=''
|
|
VITE_PID='' VITE_START='' VITE_PGID=''
|
|
|
|
cleanup() {
|
|
local status=$? cleanup_status=0
|
|
((CLEANING == 0)) || return
|
|
CLEANING=1
|
|
trap - INT TERM EXIT
|
|
if [[ -n "$VITE_PID" && -n "$VITE_START" && -n "$VITE_PGID" ]]; then
|
|
demo_stop_launch "$ROOT" vite "$VITE_PID" "$VITE_START" "$VITE_PGID" || cleanup_status=1
|
|
else
|
|
demo_stop_recorded "$ROOT" vite || cleanup_status=1
|
|
fi
|
|
if [[ -n "$ANVIL_PID" && -n "$ANVIL_START" && -n "$ANVIL_PGID" ]]; then
|
|
demo_stop_launch "$ROOT" anvil "$ANVIL_PID" "$ANVIL_START" "$ANVIL_PGID" || cleanup_status=1
|
|
else
|
|
demo_stop_recorded "$ROOT" anvil || cleanup_status=1
|
|
fi
|
|
((status == 0 && cleanup_status != 0)) && status=$cleanup_status
|
|
exit "$status"
|
|
}
|
|
trap 'exit 130' INT
|
|
trap 'exit 143' TERM
|
|
trap cleanup EXIT
|
|
|
|
capture_and_publish() {
|
|
local kind=$1 pid=$2 start pgid
|
|
for _ in {1..50}; do
|
|
if demo_capture_process "$ROOT" "$kind" "$pid" start pgid; then
|
|
if [[ "$kind" == anvil ]]; then ANVIL_START=$start; ANVIL_PGID=$pgid
|
|
else VITE_START=$start; VITE_PGID=$pgid; fi
|
|
demo_publish_process "$ROOT" "$kind" "$pid" "$start" "$pgid"
|
|
return
|
|
fi
|
|
demo_pid_is_running "$pid" || break
|
|
sleep 0.02
|
|
done
|
|
printf 'Could not prove identity for launched %s PID %s; no signal will be guessed.\n' "$kind" "$pid" >&2
|
|
return 1
|
|
}
|
|
|
|
cd "$ROOT"
|
|
bash tools/reset-local.sh
|
|
bash tools/doctor.sh
|
|
install -d -m 0700 "$ROOT/.demo"
|
|
|
|
setsid anvil --host 127.0.0.1 --port 8545 --chain-id 31337 --mnemonic "${ANVIL_DEV_WORDS[*]}" >"$ROOT/.demo/anvil.log" 2>&1 &
|
|
ANVIL_PID=$!
|
|
capture_and_publish anvil "$ANVIL_PID"
|
|
for _ in {1..100}; do
|
|
if [[ $(cast chain-id --rpc-url http://127.0.0.1:8545 2>/dev/null || true) == 31337 ]]; then ANVIL_READY=1; break; fi
|
|
demo_pid_is_running "$ANVIL_PID" || break
|
|
sleep 0.1
|
|
done
|
|
[[ ${ANVIL_READY:-0} == 1 ]] || { printf '%s\n' 'Anvil did not become ready; see .demo/anvil.log' >&2; exit 1; }
|
|
|
|
make deploy-v1
|
|
make seed-v1
|
|
DEMO_EXPECTED_STAGE=v1 make check-state
|
|
npm_config_offline=true forge build --force
|
|
node tools/sync-web-artifacts.mjs
|
|
node tools/sync-web-artifacts.mjs --check
|
|
node tools/publish-web-manifest.mjs
|
|
|
|
setsid "$ROOT/web/node_modules/.bin/vite" web --host 127.0.0.1 --port 5173 >"$ROOT/.demo/vite.log" 2>&1 &
|
|
VITE_PID=$!
|
|
capture_and_publish vite "$VITE_PID"
|
|
for _ in {1..100}; do
|
|
if curl --fail --silent --output /dev/null http://127.0.0.1:5173/; then VITE_READY=1; break; fi
|
|
demo_pid_is_running "$VITE_PID" || break
|
|
sleep 0.1
|
|
done
|
|
[[ ${VITE_READY:-0} == 1 ]] || { printf '%s\n' 'Vite did not become ready; see .demo/vite.log' >&2; exit 1; }
|
|
|
|
printf '\nV1 operations console: http://127.0.0.1:5173/\n'
|
|
printf '%s\n' 'In a second terminal: DEMO_EXPECTED_STAGE=v1 make check-state'
|
|
printf '%s\n' 'Stop this attached demo with Ctrl-C; make reset-local is the recovery command.'
|
|
while demo_pid_is_running "$ANVIL_PID" && demo_pid_is_running "$VITE_PID"; do sleep 1; done
|
|
printf '%s\n' 'A demo child exited unexpectedly; inspect .demo/anvil.log and .demo/vite.log.' >&2
|
|
exit 1
|