Alphanet: use docker-compose
This commit is contained in:
parent
84d8b46662
commit
ea515b9551
@ -2,11 +2,16 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if ! docker > /dev/null 2>&1 ; then
|
if ! which docker > /dev/null 2>&1 ; then
|
||||||
echo "Docker does not seem to be installed."
|
echo "Docker does not seem to be installed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! which docker-compose > /dev/null 2>&1 ; then
|
||||||
|
echo "Docker-compose does not seem to be installed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
docker_version="$(docker version -f "{{ .Server.Version }}")"
|
docker_version="$(docker version -f "{{ .Server.Version }}")"
|
||||||
docker_major="$(echo "$docker_version" | cut -d . -f 1)"
|
docker_major="$(echo "$docker_version" | cut -d . -f 1)"
|
||||||
docker_minor="$(echo "$docker_version" | cut -d . -f 2)"
|
docker_minor="$(echo "$docker_version" | cut -d . -f 2)"
|
||||||
@ -22,197 +27,131 @@ current_dir="$(pwd -P)"
|
|||||||
src_dir="$(cd "$(dirname "$0")" && echo "$current_dir/")"
|
src_dir="$(cd "$(dirname "$0")" && echo "$current_dir/")"
|
||||||
cd "$src_dir"
|
cd "$src_dir"
|
||||||
|
|
||||||
default_port=9732
|
update_compose_file() {
|
||||||
port="$default_port"
|
|
||||||
|
|
||||||
docker_image=docker.io/tezos/tezos:alphanet
|
if [ "$#" -ge 2 ] && [ "$1" = "--rpc-port" ] ; then
|
||||||
docker_volume=tezos-alphanet-data$suffix
|
export_rpc="
|
||||||
suffix=
|
- \"$1:8732\""
|
||||||
|
shift 2
|
||||||
|
fi
|
||||||
|
|
||||||
data_dir="$HOME/.tezos-alphanet$suffix"
|
cat > "$docker_compose_yml" <<EOF
|
||||||
docker_container="tezos-alphanet$suffix"
|
version: "3"
|
||||||
|
services:
|
||||||
|
|
||||||
if [ ! -z "$ALPHANET_EMACS" ]; then
|
node:
|
||||||
interactive_flags="-t"
|
image: $docker_image
|
||||||
|
hostname: node
|
||||||
|
command: tezos-node $@
|
||||||
|
ports:
|
||||||
|
- "$port:$port"$export_rpc
|
||||||
|
expose:
|
||||||
|
- "8732"
|
||||||
|
volumes:
|
||||||
|
- node_data:/var/run/tezos/node
|
||||||
|
- client_data:/var/run/tezos/client
|
||||||
|
restart: on-failure
|
||||||
|
environment:
|
||||||
|
- P2P_PORT=$port
|
||||||
|
|
||||||
|
baker:
|
||||||
|
image: $docker_image
|
||||||
|
hostname: baker
|
||||||
|
command: tezos-baker --max-priority 128
|
||||||
|
links:
|
||||||
|
- node
|
||||||
|
volumes:
|
||||||
|
- client_data:/var/run/tezos/client
|
||||||
|
restart: on-failure
|
||||||
|
|
||||||
|
endorser:
|
||||||
|
image: $docker_image
|
||||||
|
hostname: endorser
|
||||||
|
command: tezos-endorser
|
||||||
|
links:
|
||||||
|
- node
|
||||||
|
volumes:
|
||||||
|
- client_data:/var/run/tezos/client
|
||||||
|
restart: on-failure
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
node_data:
|
||||||
|
client_data:
|
||||||
|
EOF
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
call_docker_compose() {
|
||||||
|
docker-compose -f "$docker_compose_yml" -p "$docker_compose_name" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_docker() {
|
||||||
|
if [ -t 0 ] && [ -t 1 ] && [ -t 2 ] && [ -z "$ALPHANET_EMACS" ]; then
|
||||||
|
local interactive_flags="-it"
|
||||||
else
|
else
|
||||||
interactive_flags="-it"
|
local interactive_flags="-t"
|
||||||
fi
|
fi
|
||||||
|
docker exec "$interactive_flags" "$docker_node_container" "$@"
|
||||||
|
|
||||||
## Saving state ############################################################
|
|
||||||
|
|
||||||
save_identity() {
|
|
||||||
if [ ! -f "$data_dir/identity.json" ]; then
|
|
||||||
echo "Saving the generated identity into '$data_dir/identity.json'..."
|
|
||||||
mkdir -p "$data_dir/"
|
|
||||||
fi
|
|
||||||
docker cp "$docker_container:var/run/tezos/node/identity.json" \
|
|
||||||
"$data_dir/"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
may_restore_identity() {
|
|
||||||
if [ -f "$data_dir/identity.json" ]; then
|
|
||||||
echo "Restoring the peer identity from '$data_dir/identity.json'..."
|
|
||||||
docker exec "$docker_container" mkdir -p /var/run/tezos/node/
|
|
||||||
docker cp "$data_dir/identity.json" \
|
|
||||||
"$docker_container:var/run/tezos/node/"
|
|
||||||
docker exec "$docker_container" \
|
|
||||||
sudo chown tezos "/var/run/tezos/node/identity.json"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
may_save_client_file() {
|
|
||||||
if docker exec "$docker_container" \
|
|
||||||
test -f "/var/run/tezos/client/$1" ; then
|
|
||||||
docker cp "$docker_container:var/run/tezos/client/$1" \
|
|
||||||
"$data_dir/$1"
|
|
||||||
elif [ -f "$data_dir/$1" ] ; then
|
|
||||||
mv "$data_dir/$1" "$data_dir/$1.bak"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
may_restore_client_file() {
|
|
||||||
if [ -f "$data_dir/$1" ]; then
|
|
||||||
docker cp "$data_dir/$1" \
|
|
||||||
"$docker_container:var/run/tezos/client/"
|
|
||||||
docker exec "$docker_container" \
|
|
||||||
sudo chown tezos "/var/run/tezos/client/$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
save_accounts() {
|
|
||||||
if ! docker exec "$docker_container" \
|
|
||||||
test -f "/var/run/tezos/client/secret keys" ; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
if [ ! -f "$data_dir/secret keys" ]; then
|
|
||||||
echo "Saving the secrets into '$data_dir/secret keys'..."
|
|
||||||
echo
|
|
||||||
echo -e "\033[33mWARNING: THE SECRET KEYS FILE IS UNENCRYPTED!!!\033[0m"
|
|
||||||
echo
|
|
||||||
mkdir -p "$data_dir/"
|
|
||||||
fi
|
|
||||||
docker cp "$docker_container:var/run/tezos/client/secret keys" \
|
|
||||||
"$data_dir/"
|
|
||||||
may_save_client_file "public key hashs"
|
|
||||||
may_save_client_file "public keys"
|
|
||||||
may_save_client_file "contracts"
|
|
||||||
}
|
|
||||||
|
|
||||||
may_restore_accounts() {
|
|
||||||
docker exec "$docker_container" mkdir -p /var/run/tezos/client/
|
|
||||||
if [ -f "$data_dir/secret keys" ]; then
|
|
||||||
echo "Restoring the secret keys from '$data_dir/secret keys'..."
|
|
||||||
may_restore_client_file "secret keys"
|
|
||||||
fi
|
|
||||||
may_restore_client_file "public key hashs"
|
|
||||||
may_restore_client_file "public keys"
|
|
||||||
may_restore_client_file "contracts"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## Container ###############################################################
|
## Container ###############################################################
|
||||||
|
|
||||||
pull_image() {
|
pull_image() {
|
||||||
if [ "$TEZOS_ALPHANET_DO_NOT_PULL" = "yes" ] || [ "$ALPHANET_EMACS" ] ; then
|
if [ "$TEZOS_ALPHANET_DO_NOT_PULL" = "yes" ] \
|
||||||
|
|| [ "$ALPHANET_EMACS" ] \
|
||||||
|
|| [ "$docker_image" = "$(echo $docker_image | tr -d '/')" ] ; then
|
||||||
return ;
|
return ;
|
||||||
fi
|
fi
|
||||||
docker pull "$docker_image"
|
docker pull "$docker_image"
|
||||||
|
date "+%s" > "$docker_pull_timestamp"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_container() {
|
may_pull_image() {
|
||||||
res=$(docker inspect \
|
if [ ! -f "$docker_pull_timestamp" ] \
|
||||||
--format="{{ .State.Running }}" \
|
|| [ 3600 -le $(($(date "+%s") - $(cat $docker_pull_timestamp))) ]; then
|
||||||
--type=container "$docker_container" 2>/dev/null \
|
pull_image
|
||||||
|| echo false)
|
|
||||||
[ "$res" = true ]
|
|
||||||
}
|
|
||||||
|
|
||||||
check_volume() {
|
|
||||||
docker volume inspect "$docker_volume" > /dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
clear_volume() {
|
|
||||||
if check_volume ; then
|
|
||||||
docker volume rm "$docker_volume" > /dev/null
|
|
||||||
echo -e "\033[32mThe blockchain data has been removed from the disk.\033[0m"
|
|
||||||
else
|
|
||||||
echo -e "\033[32mNo remaining data to be removed from the disk.\033[0m"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
uptodate_container() {
|
uptodate_container() {
|
||||||
running_image=$(docker inspect \
|
running_image=$(docker inspect \
|
||||||
--format="{{ .Image }}" \
|
--format="{{ .Image }}" \
|
||||||
--type=container "$docker_container")
|
--type=container "$1")
|
||||||
latest_image=$(docker inspect \
|
latest_image=$(docker inspect \
|
||||||
--format="{{ .Id }}" \
|
--format="{{ .Id }}" \
|
||||||
--type=image "$docker_image")
|
--type=image "$docker_image")
|
||||||
[ "$latest_image" = "$running_image" ]
|
[ "$latest_image" = "$running_image" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_container_uptodate() {
|
|
||||||
pull_image > /dev/null
|
|
||||||
if ! uptodate_container; then
|
|
||||||
echo "The current container is not the latest available."
|
|
||||||
echo "Please restart."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_container() {
|
assert_container() {
|
||||||
if ! check_container; then
|
call_docker_compose up --no-start
|
||||||
echo -e "\033[31mNo container currently running!\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start_container() {
|
|
||||||
if [ "$#" -ge 2 ] && [ "$1" = "--rpc-port" ] ; then
|
|
||||||
docker_export_rpc="-p $2:8732"
|
|
||||||
fi
|
|
||||||
if check_container; then
|
|
||||||
assert_container_uptodate
|
|
||||||
else
|
|
||||||
if ! check_volume; then
|
|
||||||
docker volume create "$docker_volume"
|
|
||||||
fi
|
|
||||||
docker rm "$docker_container" || true > /dev/null 2>&1
|
|
||||||
echo "Launching the docker container..."
|
|
||||||
docker run --rm -dit -p "$port:$port" $docker_export_rpc \
|
|
||||||
-v "$docker_volume:/var/run/tezos" \
|
|
||||||
--entrypoint /bin/sh \
|
|
||||||
--name "$docker_container" \
|
|
||||||
"$docker_image" > /dev/null
|
|
||||||
may_restore_identity
|
|
||||||
may_restore_accounts
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_container() {
|
|
||||||
if ! check_container; then
|
|
||||||
echo -e "\033[31mNo container to kill!\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
save_identity ## Saving again, just in case...
|
|
||||||
save_accounts
|
|
||||||
printf "Stopping the container... "
|
|
||||||
docker stop "$docker_container" >/dev/null
|
|
||||||
echo " done"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## Node ####################################################################
|
## Node ####################################################################
|
||||||
|
|
||||||
init_node() {
|
check_node_volume() {
|
||||||
docker exec "$docker_container" tezos init \
|
docker volume inspect "$docker_node_volume" > /dev/null 2>&1
|
||||||
"$@" --net-addr "[::]:$port"
|
}
|
||||||
save_identity
|
|
||||||
|
clear_node_volume() {
|
||||||
|
if check_node; then
|
||||||
|
echo -e "\033[31mCannot clear data while the node is running.\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if check_node_volume ; then
|
||||||
|
docker volume rm "$docker_node_volume" > /dev/null
|
||||||
|
echo -e "\033[32mThe chain data has been removed from the disk.\033[0m"
|
||||||
|
else
|
||||||
|
echo -e "\033[32mNo remaining data to be removed from the disk.\033[0m"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_node() {
|
check_node() {
|
||||||
check_container && docker exec "$interactive_flags" "$docker_container" tezos check_node
|
res=$(docker inspect \
|
||||||
|
--format="{{ .State.Running }}" \
|
||||||
|
--type=container "$docker_node_container" 2>/dev/null \
|
||||||
|
|| echo false)
|
||||||
|
[ "$res" = true ]
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_node() {
|
assert_node() {
|
||||||
@ -222,42 +161,67 @@ assert_node() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn_node_uptodate() {
|
||||||
|
if ! uptodate_container "$docker_node_container"; then
|
||||||
|
echo -e "\033[33mThe current node is not the latest available.\033[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_node_uptodate() {
|
||||||
|
may_pull_image
|
||||||
|
assert_node
|
||||||
|
if ! uptodate_container "$docker_node_container"; then
|
||||||
|
echo -e "\033[33mThe current node is not the latest available.\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
status_node() {
|
status_node() {
|
||||||
|
may_pull_image
|
||||||
if check_node; then
|
if check_node; then
|
||||||
echo -e "\033[32mNode is running\033[0m"
|
echo -e "\033[32mNode is running\033[0m"
|
||||||
|
warn_node_uptodate
|
||||||
else
|
else
|
||||||
echo -e "\033[33mNode is not running\033[0m"
|
echo -e "\033[33mNode is not running\033[0m"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start_node() {
|
start_node() {
|
||||||
|
pull_image
|
||||||
if check_node; then
|
if check_node; then
|
||||||
echo -e "\033[31mCannot run two nodes in the same container!\033[0m"
|
echo -e "\033[31mNode is already running\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if $docker_1_13; then
|
update_compose_file "$@"
|
||||||
tezos_log_env="-eTEZOS_LOG=${TEZOS_LOG:=* -> info}"
|
call_docker_compose up --no-start
|
||||||
fi
|
call_docker_compose start node
|
||||||
docker exec -d "${tezos_log_env}" \
|
|
||||||
"$docker_container" tezos run_node
|
|
||||||
sleep 1
|
|
||||||
docker exec "$docker_container" tezos wait_node
|
|
||||||
echo -e "\033[32mThe node is now running.\033[0m"
|
echo -e "\033[32mThe node is now running.\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_node() {
|
log_node() {
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos log_node
|
may_pull_image
|
||||||
|
assert_node_uptodate
|
||||||
|
call_docker_compose logs -f node
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_node() {
|
stop_node() {
|
||||||
docker exec "$docker_container" tezos stop_node
|
if ! check_node; then
|
||||||
|
echo -e "\033[31mNo node to kill!\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "\033[32mStopping the node...\033[0m"
|
||||||
|
call_docker_compose stop node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## Baker ###################################################################
|
## Baker ###################################################################
|
||||||
|
|
||||||
check_baker() {
|
check_baker() {
|
||||||
check_node && docker exec "$interactive_flags" "$docker_container" tezos check_baker
|
res=$(docker inspect \
|
||||||
|
--format="{{ .State.Running }}" \
|
||||||
|
--type=container "$docker_baker_container" 2>/dev/null \
|
||||||
|
|| echo false)
|
||||||
|
[ "$res" = true ]
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_baker() {
|
assert_baker() {
|
||||||
@ -267,9 +231,25 @@ assert_baker() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn_baker_uptodate() {
|
||||||
|
if ! uptodate_container "$docker_baker_container"; then
|
||||||
|
echo -e "\033[33mThe current baker is not the latest available.\033[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_baker_uptodate() {
|
||||||
|
assert_baker
|
||||||
|
if ! uptodate_container "$docker_baker_container"; then
|
||||||
|
echo -e "\033[33mThe current baker is not the latest available.\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
status_baker() {
|
status_baker() {
|
||||||
if check_baker; then
|
if check_baker; then
|
||||||
echo -e "\033[32mBaker is running\033[0m"
|
echo -e "\033[32mBaker is running\033[0m"
|
||||||
|
may_pull_image
|
||||||
|
warn_baker_uptodate
|
||||||
else
|
else
|
||||||
echo -e "\033[33mBaker is not running\033[0m"
|
echo -e "\033[33mBaker is not running\033[0m"
|
||||||
fi
|
fi
|
||||||
@ -277,26 +257,38 @@ status_baker() {
|
|||||||
|
|
||||||
start_baker() {
|
start_baker() {
|
||||||
if check_baker; then
|
if check_baker; then
|
||||||
echo -e "\033[31mCannot run two bakers in the same container!\033[0m"
|
echo -e "\033[31mBaker is already running\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
TEZOS_LOG="${TEZOS_LOG:=* -> info}"
|
pull_image
|
||||||
docker exec -d "$docker_container" tezos run_baker
|
assert_node_uptodate
|
||||||
|
call_docker_compose start baker
|
||||||
echo -e "\033[32mThe baker is now running.\033[0m"
|
echo -e "\033[32mThe baker is now running.\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_baker() {
|
log_baker() {
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos log_baker
|
may_pull_image
|
||||||
|
assert_baker_uptodate
|
||||||
|
call_docker_compose logs -f baker
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_baker() {
|
stop_baker() {
|
||||||
docker exec "$docker_container" tezos stop_baker
|
if ! check_baker; then
|
||||||
|
echo -e "\033[31mNo baker to kill!\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "\033[32mStopping the baker...\033[0m"
|
||||||
|
call_docker_compose stop baker
|
||||||
}
|
}
|
||||||
|
|
||||||
## Baker ###################################################################
|
## Endorser ###################################################################
|
||||||
|
|
||||||
check_endorser() {
|
check_endorser() {
|
||||||
check_node && docker exec "$interactive_flags" "$docker_container" tezos check_endorser
|
res=$(docker inspect \
|
||||||
|
--format="{{ .State.Running }}" \
|
||||||
|
--type=container "$docker_endorser_container" 2>/dev/null \
|
||||||
|
|| echo false)
|
||||||
|
[ "$res" = true ]
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_endorser() {
|
assert_endorser() {
|
||||||
@ -306,9 +298,25 @@ assert_endorser() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn_endorser_uptodate() {
|
||||||
|
if ! uptodate_container "$docker_endorser_container"; then
|
||||||
|
echo -e "\033[33mThe current endorser is not the latest available.\033[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_endorser_uptodate() {
|
||||||
|
assert_endorser
|
||||||
|
if ! uptodate_container "$docker_endorser_container"; then
|
||||||
|
echo -e "\033[33mThe current endorser is not the latest available.\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
status_endorser() {
|
status_endorser() {
|
||||||
if check_endorser; then
|
if check_endorser; then
|
||||||
echo -e "\033[32mEndorser is running\033[0m"
|
echo -e "\033[32mEndorser is running\033[0m"
|
||||||
|
may_pull_image
|
||||||
|
warn_endorser_uptodate
|
||||||
else
|
else
|
||||||
echo -e "\033[33mEndorser is not running\033[0m"
|
echo -e "\033[33mEndorser is not running\033[0m"
|
||||||
fi
|
fi
|
||||||
@ -316,109 +324,103 @@ status_endorser() {
|
|||||||
|
|
||||||
start_endorser() {
|
start_endorser() {
|
||||||
if check_endorser; then
|
if check_endorser; then
|
||||||
echo -e "\033[31mCannot run two endorsers in the same container!\033[0m"
|
echo -e "\033[31mEndorser is already running\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
TEZOS_LOG="${TEZOS_LOG:=* -> info}"
|
pull_image
|
||||||
docker exec -d "$docker_container" tezos run_endorser
|
assert_node_uptodate
|
||||||
|
call_docker_compose start endorser
|
||||||
echo -e "\033[32mThe endorser is now running.\033[0m"
|
echo -e "\033[32mThe endorser is now running.\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_endorser() {
|
log_endorser() {
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos log_endorser
|
may_pull_image
|
||||||
|
assert_endorser_uptodate
|
||||||
|
call_docker_compose logs -f endorser
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_endorser() {
|
stop_endorser() {
|
||||||
docker exec "$docker_container" tezos stop_endorser
|
if ! check_baker; then
|
||||||
|
echo -e "\033[31mNo baker to kill!\033[0m"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "\033[32mStopping the baker...\033[0m"
|
||||||
|
call_docker_compose stop endorser
|
||||||
}
|
}
|
||||||
|
|
||||||
## Misc ####################################################################
|
## Misc ####################################################################
|
||||||
|
|
||||||
|
|
||||||
run_client() {
|
run_client() {
|
||||||
|
assert_node_uptodate
|
||||||
declare -a container_args=();
|
declare -a container_args=();
|
||||||
|
tmpdir=$(exec_docker mktemp)
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ "$arg" == 'container:'* ]]; then
|
if [[ "$arg" == 'container:'* ]]; then
|
||||||
local_path="${arg#container:}"
|
local_path="${arg#container:}"
|
||||||
if [[ "$local_path" != '/'* ]]; then
|
if [[ "$local_path" != '/'* ]]; then
|
||||||
local_path="$current_dir/$local_path"
|
local_path="$current_dir/$local_path"
|
||||||
fi
|
fi
|
||||||
docker exec "$docker_container" mkdir -p -m 777 /tmp/copied/
|
docker exec "$docker_container" mkdir -p -m 777 "$tmpdir"
|
||||||
file_name=$(basename "${local_path}")
|
file_name=$(basename "${local_path}")
|
||||||
docker_path="/tmp/copied/$file_name"
|
docker_path="$tmpdir/$file_name"
|
||||||
docker cp "${local_path}" "$docker_container:${docker_path}"
|
docker cp "${local_path}" "$docker_node_container:${docker_path}"
|
||||||
docker exec "$docker_container" sudo chmod 644 "${docker_path}"
|
exec_docker chmod 644 "${docker_path}"
|
||||||
container_args+=("file:$docker_path");
|
container_args+=("file:$docker_path");
|
||||||
else
|
else
|
||||||
container_args+=("${arg}");
|
container_args+=("${arg}");
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos client "${container_args[@]}"
|
exec_docker tezos-client "${container_args[@]}"
|
||||||
docker exec "$docker_container" rm -rf /tmp/copied # Remove copied files
|
exec_docker rm -rf $tmpdir # Remove copied files
|
||||||
save_accounts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_shell() {
|
run_shell() {
|
||||||
|
assert_node_uptodate
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
docker exec -it "$docker_container" bash
|
exec_docker /bin/sh
|
||||||
else
|
else
|
||||||
docker exec -it "$docker_container" bash -c "$@"
|
exec_docker /bin/sh -c "$@"
|
||||||
fi
|
fi
|
||||||
save_accounts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display_head() {
|
display_head() {
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos \
|
assert_node_uptodate
|
||||||
client rpc call /blocks/head with '{}'
|
exec_docker tezos-client rpc call /blocks/head with '{}'
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos \
|
exec_docker tezos-client rpc call /blocks/head/proto/context/level with '{}'
|
||||||
client rpc call /blocks/head/proto/context/level with '{}'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Main ####################################################################
|
## Main ####################################################################
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
pull_image
|
pull_image
|
||||||
start_container "$@"
|
update_compose_file "$@"
|
||||||
init_node "$@"
|
call_docker_compose up -d
|
||||||
start_node
|
|
||||||
start_baker
|
|
||||||
start_endorser
|
|
||||||
save_accounts
|
|
||||||
warn_script_uptodate
|
warn_script_uptodate
|
||||||
}
|
}
|
||||||
|
|
||||||
go_alpha_go() {
|
stop() {
|
||||||
docker exec "$interactive_flags" "$docker_container" tezos client \
|
call_docker_compose down
|
||||||
activate \
|
|
||||||
protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK \
|
|
||||||
with fitness 1 \
|
|
||||||
and key dictator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
kill_() {
|
||||||
stop_node || true
|
call_docker_compose kill
|
||||||
stop_container
|
stop
|
||||||
}
|
}
|
||||||
|
|
||||||
status() {
|
status() {
|
||||||
pull_image
|
|
||||||
if ! uptodate_container; then
|
|
||||||
echo -e "\033[31mThe container is running but not the latest available.\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo -e "\033[32mThe container is running and up to date.\033[0m"
|
|
||||||
warn_script_uptodate verbose
|
|
||||||
status_node
|
status_node
|
||||||
status_baker
|
status_baker
|
||||||
status_endorser
|
status_endorser
|
||||||
|
warn_script_uptodate verbose
|
||||||
}
|
}
|
||||||
|
|
||||||
warn_script_uptodate() {
|
warn_script_uptodate() {
|
||||||
if [[ $ALPHANET_EMACS ]]; then
|
if [[ $ALPHANET_EMACS ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
docker cp "$docker_container:home/tezos/scripts/alphanet.sh" \
|
docker run --entrypoint /bin/cat "$docker_image" \
|
||||||
".alphanet.sh.new"
|
"/usr/local/share/tezos/alphanet.sh" > ".alphanet.sh.new"
|
||||||
if ! diff .alphanet.sh.new "$0" >/dev/null 2>&1 ; then
|
if ! diff .alphanet.sh.new "$0" >/dev/null 2>&1 ; then
|
||||||
echo -e "\033[33mWarning: the container contains a new version of 'alphanet.sh'.\033[0m"
|
echo -e "\033[33mWarning: the container contains a new version of 'alphanet.sh'.\033[0m"
|
||||||
echo -e "\033[33mYou might run '$0 update_script' to synchronize.\033[0m"
|
echo -e "\033[33mYou might run '$0 update_script' to synchronize.\033[0m"
|
||||||
@ -428,17 +430,9 @@ warn_script_uptodate() {
|
|||||||
rm .alphanet.sh.new
|
rm .alphanet.sh.new
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_uptodate() {
|
|
||||||
assert_container
|
|
||||||
assert_container_uptodate
|
|
||||||
warn_script_uptodate
|
|
||||||
}
|
|
||||||
|
|
||||||
update_script() {
|
update_script() {
|
||||||
pull_image
|
docker run --entrypoint /bin/cat "$docker_image" \
|
||||||
tmp="$(docker run --rm -dit --entrypoint /bin/sleep "$docker_image" 20)"
|
"/usr/local/share/tezos/alphanet.sh" > ".alphanet.sh.new"
|
||||||
docker cp "$tmp:home/tezos/scripts/alphanet.sh" ".alphanet.sh.new"
|
|
||||||
docker stop "$tmp" > /dev/null
|
|
||||||
if ! diff .alphanet.sh.new "$0" >/dev/null 2>&1 ; then
|
if ! diff .alphanet.sh.new "$0" >/dev/null 2>&1 ; then
|
||||||
mv .alphanet.sh.new "$0"
|
mv .alphanet.sh.new "$0"
|
||||||
echo -e "\033[32mThe script has been updated.\033[0m"
|
echo -e "\033[32mThe script has been updated.\033[0m"
|
||||||
@ -482,7 +476,6 @@ usage() {
|
|||||||
echo " $0 update_script"
|
echo " $0 update_script"
|
||||||
echo " Replace 'alphanet.sh' with the one found in the docker image."
|
echo " Replace 'alphanet.sh' with the one found in the docker image."
|
||||||
echo " Advanced commands:"
|
echo " Advanced commands:"
|
||||||
echo " $0 container <start|stop|status>"
|
|
||||||
echo " $0 node <start|stop|status|log>"
|
echo " $0 node <start|stop|status|log>"
|
||||||
echo " $0 baker <start|stop|status|log>"
|
echo " $0 baker <start|stop|status|log>"
|
||||||
echo " $0 endorser <start|stop|status|log>"
|
echo " $0 endorser <start|stop|status|log>"
|
||||||
@ -502,13 +495,57 @@ usage() {
|
|||||||
|
|
||||||
if [ "$#" -ge 2 ] && [ "$1" = "--port" ] ; then
|
if [ "$#" -ge 2 ] && [ "$1" = "--port" ] ; then
|
||||||
port="$2"
|
port="$2"
|
||||||
suffix=".$port"
|
suffix="$port"
|
||||||
shift 2
|
shift 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command="$1"
|
command="$1"
|
||||||
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
||||||
|
|
||||||
|
case $(basename $0) in
|
||||||
|
localnet.sh)
|
||||||
|
docker_base_dir="$HOME/.tezos-localnet"
|
||||||
|
docker_image=tezos:latest
|
||||||
|
docker_compose_base_name=localnet
|
||||||
|
default_port=14732
|
||||||
|
;;
|
||||||
|
zeronet.sh)
|
||||||
|
docker_base_dir="$HOME/.tezos-zeronet"
|
||||||
|
docker_image=tezos/tezos:zeronet
|
||||||
|
docker_compose_base_name=zeronet
|
||||||
|
default_port=19732
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
docker_base_dir="$HOME/.tezos-alphanet"
|
||||||
|
docker_image=tezos:latest
|
||||||
|
docker_compose_base_name="alphanet"
|
||||||
|
default_port=9732
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -n "$suffix" ] ; then
|
||||||
|
mkdir -p "$docker_base_dir"
|
||||||
|
echo "$port" > "$docker_base_dir/default_port"
|
||||||
|
elif [ -f "$docker_base_dir/default_port" ]; then
|
||||||
|
port=$(cat "$docker_base_dir/default_port")
|
||||||
|
suffix="$port"
|
||||||
|
else
|
||||||
|
port=$default_port
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker_dir="$docker_base_dir$suffix"
|
||||||
|
docker_compose_yml="$docker_dir/docker-compose.yml"
|
||||||
|
docker_pull_timestamp="$docker_dir/docker_pull.timestamp"
|
||||||
|
docker_compose_name="$docker_compose_base_name$suffix"
|
||||||
|
|
||||||
|
docker_node_container=${docker_compose_name}_node_1
|
||||||
|
docker_baker_container=${docker_compose_name}_baker_1
|
||||||
|
docker_endorser_container=${docker_compose_name}_endorser_1
|
||||||
|
|
||||||
|
docker_node_volume=${docker_compose_name}_node_data
|
||||||
|
docker_client_volume=${docker_compose_name}_client_data
|
||||||
|
|
||||||
|
mkdir -p "$docker_dir"
|
||||||
|
|
||||||
case "$command" in
|
case "$command" in
|
||||||
|
|
||||||
@ -518,57 +555,24 @@ case "$command" in
|
|||||||
start "$@"
|
start "$@"
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
if check_container; then
|
stop
|
||||||
stop_container
|
|
||||||
fi
|
|
||||||
update_script
|
update_script
|
||||||
export TEZOS_ALPHANET_DO_NOT_PULL=yes
|
export TEZOS_ALPHANET_DO_NOT_PULL=yes
|
||||||
exec "$0" start "$@"
|
exec "$0" start "$@"
|
||||||
;;
|
;;
|
||||||
clear)
|
clear)
|
||||||
if check_container; then
|
clear_node_volume
|
||||||
echo -e "\033[31mCannot clear data while the container is running.\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
clear_volume
|
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
assert_container
|
|
||||||
status
|
status
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
assert_container
|
|
||||||
stop
|
stop
|
||||||
;;
|
;;
|
||||||
kill)
|
kill)
|
||||||
stop_container
|
kill_
|
||||||
;;
|
;;
|
||||||
|
|
||||||
## Container
|
|
||||||
|
|
||||||
container)
|
|
||||||
subcommand="$1"
|
|
||||||
if [ "$#" -eq 0 ] ; then usage ; exit 1 ; else shift ; fi
|
|
||||||
case "$subcommand" in
|
|
||||||
start)
|
|
||||||
start_container "$@"
|
|
||||||
warn_script_uptodate
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
if check_container; then
|
|
||||||
echo -e "\033[32mContainer is running\033[0m"
|
|
||||||
else
|
|
||||||
echo -e "\033[33mContainer is not running\033[0m"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
stop_container
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
esac ;;
|
|
||||||
|
|
||||||
## Node
|
## Node
|
||||||
|
|
||||||
node)
|
node)
|
||||||
@ -576,19 +580,15 @@ case "$command" in
|
|||||||
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
||||||
case "$subcommand" in
|
case "$subcommand" in
|
||||||
start)
|
start)
|
||||||
assert_uptodate
|
start_node "$@"
|
||||||
start_node
|
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
assert_uptodate
|
|
||||||
status_node
|
status_node
|
||||||
;;
|
;;
|
||||||
log)
|
log)
|
||||||
assert_uptodate
|
|
||||||
log_node
|
log_node
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
assert_uptodate
|
|
||||||
stop_node
|
stop_node
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -602,20 +602,15 @@ case "$command" in
|
|||||||
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
||||||
case "$subcommand" in
|
case "$subcommand" in
|
||||||
status)
|
status)
|
||||||
assert_uptodate
|
|
||||||
status_baker
|
status_baker
|
||||||
;;
|
;;
|
||||||
start)
|
start)
|
||||||
assert_uptodate
|
|
||||||
assert_node
|
|
||||||
start_baker
|
start_baker
|
||||||
;;
|
;;
|
||||||
log)
|
log)
|
||||||
assert_uptodate
|
|
||||||
log_baker
|
log_baker
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
assert_uptodate
|
|
||||||
stop_baker
|
stop_baker
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -630,20 +625,15 @@ case "$command" in
|
|||||||
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
|
||||||
case "$subcommand" in
|
case "$subcommand" in
|
||||||
status)
|
status)
|
||||||
assert_uptodate
|
|
||||||
status_endorser
|
status_endorser
|
||||||
;;
|
;;
|
||||||
start)
|
start)
|
||||||
assert_uptodate
|
|
||||||
assert_node
|
|
||||||
start_endorser
|
start_endorser
|
||||||
;;
|
;;
|
||||||
log)
|
log)
|
||||||
assert_uptodate
|
|
||||||
log_endorser
|
log_endorser
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
assert_uptodate
|
|
||||||
stop_endorser
|
stop_endorser
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -654,26 +644,16 @@ case "$command" in
|
|||||||
## Misc.
|
## Misc.
|
||||||
|
|
||||||
head)
|
head)
|
||||||
assert_uptodate
|
|
||||||
assert_node
|
|
||||||
display_head
|
display_head
|
||||||
;;
|
;;
|
||||||
go_alpha_go)
|
|
||||||
assert_uptodate
|
|
||||||
assert_node
|
|
||||||
go_alpha_go
|
|
||||||
;;
|
|
||||||
shell)
|
shell)
|
||||||
assert_uptodate
|
|
||||||
run_shell "$@"
|
run_shell "$@"
|
||||||
;;
|
;;
|
||||||
client)
|
client)
|
||||||
assert_uptodate
|
|
||||||
assert_node
|
|
||||||
run_client "$@"
|
run_client "$@"
|
||||||
;;
|
;;
|
||||||
check_script)
|
check_script)
|
||||||
assert_uptodate
|
warn_script_uptodate verbose
|
||||||
;;
|
;;
|
||||||
update_script)
|
update_script)
|
||||||
update_script
|
update_script
|
||||||
|
@ -31,12 +31,14 @@ cp -a "$build_dir"/leveldb-$leveldb_version-r0.apk \
|
|||||||
"$tmp_dir"
|
"$tmp_dir"
|
||||||
|
|
||||||
mkdir -p "$tmp_dir"/bin
|
mkdir -p "$tmp_dir"/bin
|
||||||
|
mkdir -p "$tmp_dir"/scripts
|
||||||
container=$(docker create $build_image_name)
|
container=$(docker create $build_image_name)
|
||||||
for bin in tezos-client tezos-node; do
|
for bin in tezos-client tezos-node; do
|
||||||
docker cp -L $container:/home/opam/tezos/$bin "$tmp_dir"/bin
|
docker cp -L $container:/home/opam/tezos/$bin "$tmp_dir"/bin
|
||||||
done
|
done
|
||||||
cp -a "$script_dir"/docker_entrypoint.sh "$tmp_dir"/bin/tezos
|
cp -a "$script_dir"/docker "$tmp_dir"/scripts/
|
||||||
cp -a "$script_dir"/docker_entrypoint.inc.sh "$tmp_dir"/bin/
|
cp "$script_dir"/alphanet.sh "$tmp_dir"/scripts/
|
||||||
|
cp "$script_dir"/alphanet_version "$tmp_dir"/scripts/
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "### Building minimal docker image..."
|
echo "### Building minimal docker image..."
|
||||||
@ -49,37 +51,32 @@ LABEL distro_style="apk" distro="alpine" distro_long="alpine-$alpine_version" ar
|
|||||||
|
|
||||||
COPY keys /etc/apk/keys/
|
COPY keys /etc/apk/keys/
|
||||||
COPY leveldb-$leveldb_version-r0.apk .
|
COPY leveldb-$leveldb_version-r0.apk .
|
||||||
COPY bin .
|
|
||||||
|
RUN apk --no-cache add \
|
||||||
|
libssl1.0 libsodium libev gmp \
|
||||||
|
leveldb-1.18-r0.apk && \
|
||||||
|
rm leveldb-$leveldb_version-r0.apk
|
||||||
|
|
||||||
|
COPY bin/tezos-node \
|
||||||
|
bin/tezos-client \
|
||||||
|
scripts/docker/entrypoint.sh \
|
||||||
|
scripts/docker/entrypoint.inc.sh \
|
||||||
|
/usr/local/bin/
|
||||||
|
|
||||||
|
COPY scripts/alphanet_version \
|
||||||
|
scripts/alphanet.sh \
|
||||||
|
/usr/local/share/tezos/
|
||||||
|
|
||||||
RUN adduser -S tezos && \
|
RUN adduser -S tezos && \
|
||||||
adduser tezos abuild && \
|
mkdir -p /var/run/tezos/node /var/run/tezos/client && \
|
||||||
apk add --no-cache sudo bash \
|
chown -R tezos /var/run/tezos
|
||||||
libssl1.0 libsodium libev gmp git snappy \
|
|
||||||
leveldb-$leveldb_version-r0.apk && \
|
|
||||||
echo 'tezos ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/tezos && \
|
|
||||||
chmod 440 /etc/sudoers.d/tezos && \
|
|
||||||
chown root:root /etc/sudoers.d/tezos && \
|
|
||||||
sed -i 's/^Defaults.*requiretty//g' /etc/sudoers
|
|
||||||
|
|
||||||
USER tezos
|
USER tezos
|
||||||
|
|
||||||
COPY . /home/tezos
|
VOLUME /var/run/tezos/node
|
||||||
|
VOLUME /var/run/tezos/client
|
||||||
|
|
||||||
WORKDIR /home/tezos
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|
||||||
RUN sudo chown root:root bin/* && \
|
|
||||||
sudo chmod a+rx bin/* && \
|
|
||||||
sudo mv bin/* /usr/local/bin && \
|
|
||||||
rmdir bin
|
|
||||||
|
|
||||||
RUN sudo mkdir -p /var/run/tezos && \
|
|
||||||
sudo chown tezos /var/run/tezos
|
|
||||||
|
|
||||||
ENV EDITOR=vi
|
|
||||||
|
|
||||||
VOLUME /var/run/tezos
|
|
||||||
|
|
||||||
ENTRYPOINT [ "/usr/local/bin/tezos" ]
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
docker build -t "$image_name:$image_version" "$tmp_dir"
|
docker build -t "$image_name:$image_version" "$tmp_dir"
|
||||||
|
118
scripts/docker/entrypoint.inc.sh
Normal file
118
scripts/docker/entrypoint.inc.sh
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
configure_client() {
|
||||||
|
|
||||||
|
local client_config="$HOME/.tezos-client/config"
|
||||||
|
mkdir -p "$client_dir" "$HOME/.tezos-client"
|
||||||
|
|
||||||
|
if [ ! -f "$client_config" ]; then
|
||||||
|
"$client" --base-dir "$client_dir" \
|
||||||
|
--addr "$NODE_HOST" --port "$RPC_PORT" \
|
||||||
|
config init --output "$client_config" >/dev/null 2>&1
|
||||||
|
else
|
||||||
|
"$client" --base-dir "$client_dir" \
|
||||||
|
--addr "$NODE_HOST" --port "$RPC_PORT" \
|
||||||
|
config update >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_the_node_to_be_ready() {
|
||||||
|
local count=0
|
||||||
|
if "$client" rpc call /blocks/head/hash >/dev/null 2>&1; then return; fi
|
||||||
|
printf "Waiting for the node to initialize..."
|
||||||
|
sleep 1
|
||||||
|
while ! "$client" rpc call /blocks/head/hash >/dev/null 2>&1
|
||||||
|
do
|
||||||
|
count=$((count+1))
|
||||||
|
if [ "$count" -ge 30 ]; then
|
||||||
|
echo " timeout."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
printf "."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo " done."
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_the_node_to_be_bootstraped() {
|
||||||
|
wait_for_the_node_to_be_ready
|
||||||
|
echo "Waiting for the node to synchronize with the network..."
|
||||||
|
"$client" bootstrapped
|
||||||
|
}
|
||||||
|
|
||||||
|
launch_node() {
|
||||||
|
|
||||||
|
mkdir -p "$node_dir"
|
||||||
|
|
||||||
|
if [ ! -f "$node_dir/config.json" ]; then
|
||||||
|
echo "Configuring the node..."
|
||||||
|
"$node" config init \
|
||||||
|
--data-dir "$node_dir" \
|
||||||
|
--net-addr ":$P2P_PORT" \
|
||||||
|
--rpc-addr ":$RPC_PORT" \
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
echo "Updating the node configuration..."
|
||||||
|
"$node" config update \
|
||||||
|
--data-dir "$node_dir" \
|
||||||
|
--net-addr ":$port" \
|
||||||
|
--rpc-addr ":$RPC_PORT" \
|
||||||
|
"$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in "$@"; do
|
||||||
|
if [ "$i" = "--help" ] ; then exit 0; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if we have to reset the chain because the image we want to
|
||||||
|
# run has a incompatible version with the blockchain we have stored
|
||||||
|
# locally on disk
|
||||||
|
|
||||||
|
local image_version="$(cat "/usr/local/share/tezos/alphanet_version")"
|
||||||
|
echo "Current public chain: $image_version."
|
||||||
|
if [ -f "$DATA_DIR/alphanet_version" ]; then
|
||||||
|
local local_data_version="$(cat "$DATA_DIR/alphanet_version")"
|
||||||
|
echo "Local chain data: $local_data_version."
|
||||||
|
if [ "$local_data_version" != "$image_version" ]; then
|
||||||
|
echo "Removing outdated chain data..."
|
||||||
|
if [ -f "$node_dir/identities.json" ]; then \
|
||||||
|
mv "$node_dir/identities.json" /tmp
|
||||||
|
fi
|
||||||
|
rm -rf "$node_dir/*"
|
||||||
|
## TODO also remove stored nonces and endorsement...
|
||||||
|
if [ -f "/tmp/identities.json" ]; then \
|
||||||
|
mv /tmp/identities.json "$node_dir/"
|
||||||
|
fi
|
||||||
|
cp "/usr/local/share/tezos/alphanet_version" \
|
||||||
|
"$DATA_DIR/alphanet_version"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate a new identity if not present
|
||||||
|
|
||||||
|
if [ ! -f "$node_dir/identity.json" ]; then
|
||||||
|
echo "Generating a new node identity..."
|
||||||
|
"$node" identity generate 24. \
|
||||||
|
--data-dir "$node_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
configure_client
|
||||||
|
|
||||||
|
# Launching the node
|
||||||
|
|
||||||
|
exec "$node" run --data-dir "$node_dir"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
launch_baker() {
|
||||||
|
configure_client
|
||||||
|
wait_for_the_node_to_be_bootstraped
|
||||||
|
exec "$client" launch daemon --baking "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
launch_endorser() {
|
||||||
|
configure_client
|
||||||
|
wait_for_the_node_to_be_bootstraped
|
||||||
|
exec "$client" launch daemon --endorsement "$@"
|
||||||
|
}
|
54
scripts/docker/entrypoint.sh
Executable file
54
scripts/docker/entrypoint.sh
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
bin_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
|
||||||
|
|
||||||
|
: ${DATA_DIR:="/var/run/tezos"}
|
||||||
|
|
||||||
|
: ${NODE_HOST:="node"}
|
||||||
|
|
||||||
|
: ${P2P_PORT:="9732"}
|
||||||
|
: ${RPC_PORT:="8732"}
|
||||||
|
|
||||||
|
node="/usr/local/bin/tezos-node"
|
||||||
|
client="/usr/local/bin/tezos-client"
|
||||||
|
admin_client="/usr/local/bin/tezos-admin-client"
|
||||||
|
|
||||||
|
client_dir="$DATA_DIR/client"
|
||||||
|
node_dir="$DATA_DIR/node"
|
||||||
|
|
||||||
|
. "$bin_dir/entrypoint.inc.sh"
|
||||||
|
|
||||||
|
command=${1:-tezos-node}
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
case $command in
|
||||||
|
tezos-node)
|
||||||
|
launch_node "$@"
|
||||||
|
;;
|
||||||
|
tezos-baker)
|
||||||
|
launch_baker "$@"
|
||||||
|
;;
|
||||||
|
tezos-endorser)
|
||||||
|
launch_endorser "$@"
|
||||||
|
;;
|
||||||
|
tezos-client)
|
||||||
|
configure_client
|
||||||
|
exec "$client" "$@"
|
||||||
|
;;
|
||||||
|
tezos-admin-client)
|
||||||
|
configure_client
|
||||||
|
exec "$admin_client" "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
cat <<EOF
|
||||||
|
Available commands:
|
||||||
|
- tezos-node [args]
|
||||||
|
- tezos-client [args]
|
||||||
|
- tezos-baker [keys]
|
||||||
|
- tezos-endorser [keys]
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
@ -1,116 +0,0 @@
|
|||||||
#! /usr/bin/env bash
|
|
||||||
|
|
||||||
data_dir="/var/run/tezos"
|
|
||||||
node_dir="${node_dir:=/var/run/tezos/node}"
|
|
||||||
client_dir="${client_dir:=/var/run/tezos/client}"
|
|
||||||
node="${node:=tezos-node}"
|
|
||||||
client="${client:=tezos-client -base-dir \"$client_dir\"}"
|
|
||||||
|
|
||||||
save() {
|
|
||||||
[ ! -f "$1" ] || mv "$1" "$data_dir/bak"
|
|
||||||
}
|
|
||||||
|
|
||||||
restore() {
|
|
||||||
[ ! -f "$data_dir/bak/$(basename "$1")" ] || mv "$data_dir/bak/$(basename "$1")" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
init() {
|
|
||||||
if [ ! -f "$data_dir/alphanet_version" ] || \
|
|
||||||
[ "$(cat "$data_dir/alphanet_version")" \
|
|
||||||
!= "$(cat ~/scripts/alphanet_version)" ]; then
|
|
||||||
echo -e "\033[33mThe alphanet chain has been reset\033[0m"
|
|
||||||
mkdir -p "$data_dir/bak"
|
|
||||||
save "$node_dir/identity.json"
|
|
||||||
save "$client_dir/public key hashs"
|
|
||||||
save "$client_dir/public keys"
|
|
||||||
save "$client_dir/secret keys"
|
|
||||||
rm -rf "$node_dir" "$client_dir"
|
|
||||||
mkdir -p "$node_dir" "$client_dir"
|
|
||||||
restore "$node_dir/identity.json"
|
|
||||||
restore "$client_dir/public key hashs"
|
|
||||||
restore "$client_dir/public keys"
|
|
||||||
restore "$client_dir/secret keys"
|
|
||||||
rmdir "$data_dir/bak"
|
|
||||||
cp ~/scripts/alphanet_version "$data_dir/alphanet_version"
|
|
||||||
fi
|
|
||||||
if [ "$#" -ge 2 ] && [ "$1" = "--rpc-port" ] ; then
|
|
||||||
rpc_addr="[::]:8732"
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
rpc_addr="127.0.0.1:8732"
|
|
||||||
fi
|
|
||||||
if [ ! -f "$node_dir/config.json" ]; then
|
|
||||||
"$node" config init \
|
|
||||||
"$@" \
|
|
||||||
--data-dir "$node_dir" \
|
|
||||||
--rpc-addr "$rpc_addr" \
|
|
||||||
--log-output "$node_dir/log"
|
|
||||||
else
|
|
||||||
"$node" config update \
|
|
||||||
"$@" \
|
|
||||||
--data-dir "$node_dir" \
|
|
||||||
--rpc-addr "$rpc_addr" \
|
|
||||||
--log-output "$node_dir/log"
|
|
||||||
fi
|
|
||||||
if [ -f "$node_dir/identity.json" ]; then
|
|
||||||
if ! "$node" identity check \
|
|
||||||
--data-dir "$node_dir" 2> /dev/null; then
|
|
||||||
echo "Ignoring the current peer identity (not enough proof of work)."
|
|
||||||
rm "$node_dir/identity.json"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ ! -f "$node_dir/identity.json" ]; then
|
|
||||||
"$node" identity generate \
|
|
||||||
--data-dir "$node_dir"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_node() {
|
|
||||||
pgrep -x tezos-node > /dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
run_node() {
|
|
||||||
TEZOS_LOG="${TEZOS_LOG:='* -> info'}"
|
|
||||||
if check_node; then
|
|
||||||
echo "Cannot run two node instances in the same container."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
## Temporary hack until Pierre has debugged Lwt...
|
|
||||||
export LWT_ASYNC_METHOD=none
|
|
||||||
## END of temporary hack
|
|
||||||
exec "$node" run "$@" --data-dir "$node_dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_node() {
|
|
||||||
if ! check_node; then
|
|
||||||
echo "No tezos node to kill!"
|
|
||||||
exit 1 ;
|
|
||||||
fi
|
|
||||||
printf "Killing the tezos node..."
|
|
||||||
pkill -x tezos-node
|
|
||||||
sleep 1
|
|
||||||
while check_node; do
|
|
||||||
printf "."
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
echo " done."
|
|
||||||
}
|
|
||||||
|
|
||||||
log_node() {
|
|
||||||
if ! check_node ; then
|
|
||||||
echo
|
|
||||||
echo "#############################################"
|
|
||||||
echo "## ##"
|
|
||||||
echo "## Warning: The tezos node is not running! ##"
|
|
||||||
echo "## ##"
|
|
||||||
echo "#############################################"
|
|
||||||
echo
|
|
||||||
tail "$node_dir/log"
|
|
||||||
else
|
|
||||||
tail -f "$node_dir/log"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
run_client() {
|
|
||||||
exec $client "$@"
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
#! /usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
|
|
||||||
src_dir="$(dirname "$script_dir")"
|
|
||||||
cd "$src_dir"
|
|
||||||
|
|
||||||
data_dir="/var/run/tezos"
|
|
||||||
export node_dir="$data_dir/node"
|
|
||||||
export client_dir="$data_dir/client"
|
|
||||||
export node="tezos-node"
|
|
||||||
export client="tezos-client -base-dir $client_dir"
|
|
||||||
|
|
||||||
. tezos-init-sandboxed-client.sh
|
|
||||||
. "${script_dir}"/docker_entrypoint.inc.sh
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "$0 command [options]"
|
|
||||||
echo
|
|
||||||
echo "where 'command' is one of:"
|
|
||||||
echo " - run_node: ... "
|
|
||||||
echo " - log_node: ... "
|
|
||||||
echo " - run_baker: ... "
|
|
||||||
echo " - log_baker: ... "
|
|
||||||
echo " - run_endorser: ... "
|
|
||||||
echo " - log_endorser: ... "
|
|
||||||
}
|
|
||||||
|
|
||||||
command="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
case "$command" in
|
|
||||||
init)
|
|
||||||
init "$@"
|
|
||||||
;;
|
|
||||||
run_node)
|
|
||||||
run_node "$@"
|
|
||||||
;;
|
|
||||||
check_node)
|
|
||||||
check_node
|
|
||||||
;;
|
|
||||||
wait_node)
|
|
||||||
if ! check_node; then
|
|
||||||
echo "The tezos node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
wait_for_the_node_to_be_bootstraped
|
|
||||||
may_create_identity
|
|
||||||
;;
|
|
||||||
stop_node)
|
|
||||||
stop_node
|
|
||||||
;;
|
|
||||||
log_node)
|
|
||||||
log_node
|
|
||||||
;;
|
|
||||||
run_baker)
|
|
||||||
run_baker "$@"
|
|
||||||
;;
|
|
||||||
check_baker)
|
|
||||||
check_baker
|
|
||||||
;;
|
|
||||||
stop_baker)
|
|
||||||
stop_baker
|
|
||||||
;;
|
|
||||||
log_baker)
|
|
||||||
log_baker
|
|
||||||
;;
|
|
||||||
run_endorser)
|
|
||||||
run_endorser "$@"
|
|
||||||
;;
|
|
||||||
check_endorser)
|
|
||||||
check_endorser
|
|
||||||
;;
|
|
||||||
stop_endorser)
|
|
||||||
stop_endorser
|
|
||||||
;;
|
|
||||||
log_endorser)
|
|
||||||
log_endorser
|
|
||||||
;;
|
|
||||||
client)
|
|
||||||
run_client "$@"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
esac
|
|
1
scripts/localnet.sh
Symbolic link
1
scripts/localnet.sh
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
alphanet.sh
|
@ -1,36 +1,11 @@
|
|||||||
diff --git a/scripts/alphanet.sh b/scripts/alphanet.sh
|
-diff --git a/src/bin_node/node_config_file.ml b/src/bin_node/node_config_file.ml
|
||||||
--- a/scripts/alphanet.sh
|
---- a/src/bin_node/node_config_file.ml
|
||||||
+++ b/scripts/alphanet.sh
|
-+++ b/src/bin_node/node_config_file.ml
|
||||||
@@ -21,15 +21,15 @@ fi
|
-@@ -16,7 +16,7 @@ let home =
|
||||||
src_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
|
- with Not_found -> "/root"
|
||||||
cd "$src_dir"
|
-
|
||||||
|
- let default_data_dir = home // ".tezos-node"
|
||||||
-default_port=9732
|
--let default_net_port = 9732
|
||||||
+default_port=19732
|
-+let default_net_port = 19732
|
||||||
port="$default_port"
|
- let default_rpc_port = 8732
|
||||||
|
-
|
||||||
-docker_image=docker.io/tezos/tezos:alphanet
|
|
||||||
-docker_volume=tezos-alphanet-data$suffix
|
|
||||||
+docker_image=docker.io/tezos/tezos:zeronet
|
|
||||||
+docker_volume=tezos-zeronet-data$suffix
|
|
||||||
suffix=
|
|
||||||
|
|
||||||
-data_dir="$HOME/.tezos-alphanet$suffix"
|
|
||||||
-docker_container="tezos-alphanet$suffix"
|
|
||||||
+data_dir="$HOME/.tezos-zeronet$suffix"
|
|
||||||
+docker_container="tezos-zeronet$suffix"
|
|
||||||
|
|
||||||
if [ $ALPHANET_EMACS ]; then
|
|
||||||
interactive_flags="-t"
|
|
||||||
diff --git a/src/bin_node/node_config_file.ml b/src/bin_node/node_config_file.ml
|
|
||||||
--- a/src/bin_node/node_config_file.ml
|
|
||||||
+++ b/src/bin_node/node_config_file.ml
|
|
||||||
@@ -16,7 +16,7 @@ let home =
|
|
||||||
with Not_found -> "/root"
|
|
||||||
|
|
||||||
let default_data_dir = home // ".tezos-node"
|
|
||||||
-let default_net_port = 9732
|
|
||||||
+let default_net_port = 19732
|
|
||||||
let default_rpc_port = 8732
|
|
||||||
|
|
||||||
type t = {
|
|
||||||
|
1
scripts/zeronet.sh
Symbolic link
1
scripts/zeronet.sh
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
alphanet.sh
|
Loading…
Reference in New Issue
Block a user