2018-10-02 20:51:19 -07:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
exitcode=0
|
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
exitcode=1
|
|
|
|
echo "Error: $*"
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
|
|
|
usage: $0 [update|up|down|logs] [command-specific options]
|
|
|
|
|
|
|
|
Operate a local testnet
|
|
|
|
|
|
|
|
update - Update the network image from dockerhub.com
|
|
|
|
up - Start the network
|
|
|
|
down - Stop the network
|
|
|
|
logs - Display network logging
|
|
|
|
|
|
|
|
|
|
|
|
logs-specific options:
|
|
|
|
-f - Follow log output
|
|
|
|
|
|
|
|
update/up-specific options:
|
|
|
|
edge - Update/start the "edge" channel network
|
|
|
|
beta - Update/start the "beta" channel network (default)
|
|
|
|
|
|
|
|
down-specific options:
|
|
|
|
none
|
|
|
|
|
|
|
|
|
|
|
|
Assumes that docker is installed
|
|
|
|
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
|
|
|
|
|
|
|
channel=beta
|
|
|
|
|
|
|
|
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
|
|
|
|
[[ $channel = edge || $channel = beta ]] || usage "Invalid channel: $channel"
|
|
|
|
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker pull solanalabs/solana:"$channel"
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
up)
|
2018-10-02 21:38:02 -07:00
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
channel="$1"
|
2018-10-02 20:51:19 -07:00
|
|
|
fi
|
|
|
|
[[ $channel = edge || $channel = beta ]] || usage "Invalid channel: $channel"
|
|
|
|
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker run \
|
|
|
|
--detach \
|
|
|
|
--name solana-localnet \
|
|
|
|
--rm \
|
|
|
|
--publish 8899:8899 \
|
|
|
|
--tty \
|
|
|
|
solanalabs/solana:"$channel"
|
|
|
|
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
down)
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker stop --time 0 solana-localnet
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
logs)
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
docker logs solana-localnet "$@"
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage "Unknown command: $cmd"
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|