2018-11-11 08:13:20 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2018-10-02 20:51:19 -07:00
|
|
|
|
2019-06-19 10:30:44 -07:00
|
|
|
channel=$(
|
|
|
|
cd "$(dirname "$0")";
|
|
|
|
node -p '
|
|
|
|
let p = [
|
2019-12-12 22:52:54 -08:00
|
|
|
"../../package.json",
|
2019-06-19 10:30:44 -07:00
|
|
|
"../lib/node_modules/@solana/web3.js/package.json",
|
|
|
|
"../@solana/web3.js/package.json",
|
|
|
|
"../package.json"
|
|
|
|
].find(require("fs").existsSync);
|
2019-12-12 22:52:54 -08:00
|
|
|
if (!p) throw new Error("Unable to locate package.json");
|
2019-06-19 10:30:44 -07:00
|
|
|
require(p)["testnetDefaultChannel"]
|
|
|
|
'
|
|
|
|
)
|
2018-11-30 07:49:40 -08:00
|
|
|
|
2018-10-02 20:51:19 -07:00
|
|
|
usage() {
|
|
|
|
exitcode=0
|
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
exitcode=1
|
|
|
|
echo "Error: $*"
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
2019-07-16 14:53:23 -07:00
|
|
|
usage: $0 [update|up|down|logs] [command-specific options]
|
2018-10-02 20:51:19 -07:00
|
|
|
|
|
|
|
Operate a local testnet
|
|
|
|
|
2019-02-15 19:59:42 -08:00
|
|
|
update - Update the image from dockerhub.com
|
2019-03-04 08:16:13 -08:00
|
|
|
up - Start the cluster
|
|
|
|
down - Stop the cluster
|
|
|
|
logs - Display cluster logging
|
2018-10-02 20:51:19 -07:00
|
|
|
|
|
|
|
logs-specific options:
|
2019-12-12 15:33:24 -08:00
|
|
|
-f - Follow log output
|
2018-10-02 20:51:19 -07:00
|
|
|
|
2019-02-15 19:59:42 -08:00
|
|
|
update-specific options:
|
2019-12-12 15:33:24 -08:00
|
|
|
<tag> - Optional Docker image tag to use
|
2019-02-15 19:59:42 -08:00
|
|
|
|
|
|
|
up-specific options:
|
2019-12-12 15:33:24 -08:00
|
|
|
<tag> - Optional Docker image tag to use
|
|
|
|
-n - Optional Docker network to join
|
2018-11-30 07:49:40 -08:00
|
|
|
|
|
|
|
Default channel: $channel
|
2018-10-02 20:51:19 -07:00
|
|
|
|
|
|
|
down-specific options:
|
|
|
|
none
|
|
|
|
|
|
|
|
EOF
|
|
|
|
exit $exitcode
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ -n $1 ]] || usage
|
|
|
|
cmd="$1"
|
2018-10-02 21:38:02 -07:00
|
|
|
shift
|
2018-10-02 20:51:19 -07:00
|
|
|
|
|
|
|
docker --version || usage "It appears that docker is not installed"
|
|
|
|
case $cmd in
|
|
|
|
update)
|
2018-10-02 21:38:02 -07:00
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
channel="$1"
|
2018-10-02 20:51:19 -07:00
|
|
|
fi
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker pull solanalabs/solana:"$channel"
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
up)
|
2019-02-15 19:59:42 -08:00
|
|
|
while [[ -n $1 ]]; do
|
|
|
|
if [[ $1 = -n ]]; then
|
|
|
|
[[ -n $2 ]] || usage "Invalid $1 argument"
|
|
|
|
network="$2"
|
|
|
|
shift 2
|
|
|
|
else
|
2019-12-12 15:28:45 -08:00
|
|
|
channel=$1
|
|
|
|
shift 1
|
2019-02-15 19:59:42 -08:00
|
|
|
fi
|
|
|
|
done
|
2018-12-10 14:58:05 -08:00
|
|
|
|
2018-10-02 20:51:19 -07:00
|
|
|
(
|
|
|
|
set -x
|
2020-11-12 12:44:37 -08:00
|
|
|
RUST_LOG=${RUST_LOG:-solana=info,solana_runtime::message_processor=debug}
|
2019-02-15 19:59:42 -08:00
|
|
|
ARGS=(
|
|
|
|
--detach
|
|
|
|
--name solana-localnet
|
|
|
|
--rm
|
2020-10-09 23:21:47 -07:00
|
|
|
--publish 8001:8001/tcp # entrypoint
|
|
|
|
--publish 8899:8899/tcp # rpc http
|
|
|
|
--publish 8900:8900/tcp # rpc pubsub
|
|
|
|
--publish 8901:8901/tcp # (future) bank service
|
|
|
|
--publish 8902:8902/tcp # bank service
|
|
|
|
--publish 9900:9900/tcp # faucet
|
|
|
|
--publish 8000:8000/udp # tvu
|
|
|
|
--publish 8001:8001/udp # gossip
|
|
|
|
--publish 8002:8002/udp # tvu_forwards
|
|
|
|
--publish 8003:8003/udp # tpu
|
|
|
|
--publish 8004:8004/udp # tpu_forwards
|
|
|
|
--publish 8005:8005/udp # retransmit
|
|
|
|
--publish 8006:8006/udp # repair
|
|
|
|
--publish 8007:8007/udp # serve_repair
|
|
|
|
--publish 8008:8008/udp # broadcast
|
2019-02-15 19:59:42 -08:00
|
|
|
--tty
|
2020-08-27 10:30:58 -07:00
|
|
|
--ulimit "nofile=500000"
|
2019-02-15 19:59:42 -08:00
|
|
|
--env "RUST_LOG=$RUST_LOG"
|
|
|
|
)
|
2019-08-01 09:12:23 -07:00
|
|
|
if [[ -n $network ]]; then
|
|
|
|
ARGS+=(--network "$network")
|
|
|
|
fi
|
2019-02-15 19:59:42 -08:00
|
|
|
|
|
|
|
docker run "${ARGS[@]}" solanalabs/solana:"$channel"
|
2018-10-02 20:51:19 -07:00
|
|
|
|
2018-10-25 18:13:32 -07:00
|
|
|
for _ in 1 2 3 4 5; do
|
|
|
|
if curl \
|
|
|
|
-X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d '{"jsonrpc":"2.0","id":1, "method":"getTransactionCount"}' \
|
|
|
|
http://localhost:8899; then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
2018-10-02 20:51:19 -07:00
|
|
|
)
|
|
|
|
;;
|
|
|
|
down)
|
|
|
|
(
|
|
|
|
set -x
|
2020-09-11 09:34:27 -07:00
|
|
|
if [[ $(docker ps --filter "name=^/solana-localnet$" -q) ]]; then
|
2018-12-11 14:08:36 -08:00
|
|
|
docker stop --time 0 solana-localnet
|
|
|
|
fi
|
2018-10-02 20:51:19 -07:00
|
|
|
)
|
|
|
|
;;
|
|
|
|
logs)
|
2018-10-13 10:54:37 -07:00
|
|
|
follow=false
|
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
if [[ $1 = "-f" ]]; then
|
|
|
|
follow=true
|
|
|
|
else
|
|
|
|
usage "Unknown argument: $1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
while $follow; do
|
2020-09-11 09:34:27 -07:00
|
|
|
if [[ $(docker ps -q -f "name=^/solana-localnet$") ]]; then
|
2018-10-13 10:54:37 -07:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker logs solana-localnet -f
|
|
|
|
) || true
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2018-10-02 20:51:19 -07:00
|
|
|
(
|
|
|
|
set -x
|
2018-10-13 10:54:37 -07:00
|
|
|
docker logs solana-localnet
|
2018-10-02 20:51:19 -07:00
|
|
|
)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage "Unknown command: $cmd"
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|