Docker: handle multiple protocols

This commit is contained in:
Grégoire Henry 2018-07-18 20:27:06 +02:00
parent ae1f325b76
commit 572bcf12fc
5 changed files with 191 additions and 48 deletions

1
active_protocol_versions Normal file
View File

@ -0,0 +1 @@
alpha

View File

@ -29,6 +29,8 @@ cd "$src_dir"
update_compose_file() { update_compose_file() {
update_active_protocol_version
if [ "$#" -ge 2 ] && [ "$1" = "--rpc-port" ] ; then if [ "$#" -ge 2 ] && [ "$1" = "--rpc-port" ] ; then
export_rpc=" export_rpc="
- \"$2:8732\"" - \"$2:8732\""
@ -37,6 +39,11 @@ update_compose_file() {
cat > "$docker_compose_yml" <<EOF cat > "$docker_compose_yml" <<EOF
version: "2" version: "2"
volumes:
node_data:
client_data:
services: services:
node: node:
@ -52,9 +59,16 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
baker: EOF
for proto in $(cat "$active_protocol_versions") ; do
cat >> "$docker_compose_yml" <<EOF
baker-$proto:
image: $docker_image image: $docker_image
hostname: baker hostname: baker-$proto
environment:
- PROTOCOL=$proto
command: tezos-baker --max-priority 128 command: tezos-baker --max-priority 128
links: links:
- node - node
@ -63,9 +77,11 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
endorser: endorser-$proto:
image: $docker_image image: $docker_image
hostname: endorser hostname: endorser-$proto
environment:
- PROTOCOL=$proto
command: tezos-endorser command: tezos-endorser
links: links:
- node - node
@ -73,11 +89,22 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
volumes: accuser-$proto:
node_data: image: $docker_image
client_data: hostname: accuser-$proto
environment:
- PROTOCOL=$proto
command: tezos-accuser
links:
- node
volumes:
- client_data:/var/run/tezos/client
restart: on-failure
EOF EOF
done
} }
call_docker_compose() { call_docker_compose() {
@ -111,6 +138,17 @@ exec_docker() {
## Container ############################################################### ## Container ###############################################################
update_active_protocol_version() {
docker run --entrypoint /bin/cat "$docker_image" \
/usr/local/share/tezos/active_protocol_versions > "$active_protocol_versions"
}
may_update_active_protocol_version() {
if [ ! -f "$active_protocol_versions" ] ; then
update_active_protocol_version
fi
}
pull_image() { pull_image() {
if [ "$TEZOS_ALPHANET_DO_NOT_PULL" = "yes" ] \ if [ "$TEZOS_ALPHANET_DO_NOT_PULL" = "yes" ] \
|| [ "$ALPHANET_EMACS" ] \ || [ "$ALPHANET_EMACS" ] \
@ -118,6 +156,7 @@ pull_image() {
return ; return ;
fi fi
docker pull "$docker_image" docker pull "$docker_image"
update_active_protocol_version
date "+%s" > "$docker_pull_timestamp" date "+%s" > "$docker_pull_timestamp"
} }
@ -138,6 +177,14 @@ uptodate_container() {
[ "$latest_image" = "$running_image" ] [ "$latest_image" = "$running_image" ]
} }
uptodate_containers() {
container=$1
if [ ! -z "$container" ]; then
shift 1
uptodate_container $container && uptodate_containers $@
fi
}
assert_container() { assert_container() {
call_docker_compose up --no-start call_docker_compose up --no-start
} }
@ -232,11 +279,13 @@ stop_node() {
## Baker ################################################################### ## Baker ###################################################################
check_baker() { check_baker() {
update_active_protocol_version
bakers="$(sed s/^/baker-/g "$active_protocol_versions")"
docker_baker_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_baker-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$docker_baker_container" 2>/dev/null \ --type=container $docker_baker_containers 2>/dev/null | grep false)
|| echo false) [ -z "$res" ]
[ "$res" = true ]
} }
assert_baker() { assert_baker() {
@ -246,15 +295,9 @@ 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_uptodate() {
assert_baker assert_baker
if ! uptodate_container "$docker_baker_container"; then if ! uptodate_containers $docker_baker_containers; then
echo -e "\033[33mThe current baker is not the latest available.\033[0m" echo -e "\033[33mThe current baker is not the latest available.\033[0m"
exit 1 exit 1
fi fi
@ -264,7 +307,9 @@ 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 may_pull_image
warn_baker_uptodate if ! uptodate_containers $docker_baker_containers; then
echo -e "\033[33mThe current baker is not the latest available.\033[0m"
fi
else else
echo -e "\033[33mBaker is not running\033[0m" echo -e "\033[33mBaker is not running\033[0m"
fi fi
@ -277,14 +322,14 @@ start_baker() {
fi fi
pull_image pull_image
assert_node_uptodate assert_node_uptodate
call_docker_compose start baker call_docker_compose start $bakers
echo -e "\033[32mThe baker is now running.\033[0m" echo -e "\033[32mThe baker is now running.\033[0m"
} }
log_baker() { log_baker() {
may_pull_image may_pull_image
assert_baker_uptodate assert_baker_uptodate
call_docker_compose logs -f baker call_docker_compose logs -f $bakers
} }
stop_baker() { stop_baker() {
@ -293,15 +338,18 @@ stop_baker() {
exit 1 exit 1
fi fi
echo -e "\033[32mStopping the baker...\033[0m" echo -e "\033[32mStopping the baker...\033[0m"
call_docker_compose stop baker call_docker_compose stop $bakers
} }
## Endorser ################################################################### ## Endorser ###################################################################
check_endorser() { check_endorser() {
update_active_protocol_version
endorsers="$(sed s/^/endorser-/g "$active_protocol_versions")"
docker_endorser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_endorser-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$docker_endorser_container" 2>/dev/null \ --type=container $docker_endorser_containers 2>/dev/null \
|| echo false) || echo false)
[ "$res" = true ] [ "$res" = true ]
} }
@ -313,15 +361,9 @@ 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_uptodate() {
assert_endorser assert_endorser
if ! uptodate_container "$docker_endorser_container"; then if ! uptodate_containers $docker_endorser_containers; then
echo -e "\033[33mThe current endorser is not the latest available.\033[0m" echo -e "\033[33mThe current endorser is not the latest available.\033[0m"
exit 1 exit 1
fi fi
@ -331,7 +373,9 @@ 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 may_pull_image
warn_endorser_uptodate if ! uptodate_containers $docker_endorser_containers; then
echo -e "\033[33mThe current endorser is not the latest available.\033[0m"
fi
else else
echo -e "\033[33mEndorser is not running\033[0m" echo -e "\033[33mEndorser is not running\033[0m"
fi fi
@ -344,14 +388,14 @@ start_endorser() {
fi fi
pull_image pull_image
assert_node_uptodate assert_node_uptodate
call_docker_compose start endorser call_docker_compose start $endorsers
echo -e "\033[32mThe endorser is now running.\033[0m" echo -e "\033[32mThe endorser is now running.\033[0m"
} }
log_endorser() { log_endorser() {
may_pull_image may_pull_image
assert_endorser_uptodate assert_endorser_uptodate
call_docker_compose logs -f endorser call_docker_compose logs -f $endorsers
} }
stop_endorser() { stop_endorser() {
@ -360,7 +404,73 @@ stop_endorser() {
exit 1 exit 1
fi fi
echo -e "\033[32mStopping the baker...\033[0m" echo -e "\033[32mStopping the baker...\033[0m"
call_docker_compose stop endorser call_docker_compose stop $endorsers
}
## Accuser ###################################################################
check_accuser() {
update_active_protocol_version
accusers="$(sed s/^/accuser-/g "$active_protocol_versions")"
docker_accuser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_accuser-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \
--format="{{ .State.Running }}" \
--type=container $docker_accuser_containers 2>/dev/null \
|| echo false)
[ "$res" = true ]
}
assert_accuser() {
if ! check_accuser; then
echo -e "\033[31mAccuser is not running!\033[0m"
exit 0
fi
}
assert_accuser_uptodate() {
assert_accuser
if ! uptodate_containers $docker_accuser_containers; then
echo -e "\033[33mThe current accuser is not the latest available.\033[0m"
exit 1
fi
}
status_accuser() {
if check_accuser; then
echo -e "\033[32mAccuser is running\033[0m"
may_pull_image
if ! uptodate_containers $docker_accuser_containers; then
echo -e "\033[33mThe current accuser is not the latest available.\033[0m"
fi
else
echo -e "\033[33mAccuser is not running\033[0m"
fi
}
start_accuser() {
if check_accuser; then
echo -e "\033[31mAccuser is already running\033[0m"
exit 1
fi
pull_image
assert_node_uptodate
call_docker_compose start $accusers
echo -e "\033[32mThe accuser is now running.\033[0m"
}
log_accuser() {
may_pull_image
assert_accuser_uptodate
call_docker_compose logs -f $accusers
}
stop_accuser() {
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 $accusers
} }
## Misc #################################################################### ## Misc ####################################################################
@ -395,7 +505,7 @@ display_head() {
start() { start() {
pull_image pull_image
update_compose_file "$@" update_compose_file "$@"
call_docker_compose up -d call_docker_compose up -d --remove-orphans
warn_script_uptodate warn_script_uptodate
} }
@ -540,11 +650,10 @@ fi
docker_dir="$docker_base_dir$suffix" docker_dir="$docker_base_dir$suffix"
docker_compose_yml="$docker_dir/docker-compose.yml" docker_compose_yml="$docker_dir/docker-compose.yml"
docker_pull_timestamp="$docker_dir/docker_pull.timestamp" docker_pull_timestamp="$docker_dir/docker_pull.timestamp"
active_protocol_versions="$docker_dir/active_protocol_versions"
docker_compose_name="$docker_compose_base_name$suffix" docker_compose_name="$docker_compose_base_name$suffix"
docker_node_container=${docker_compose_name}_node_1 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_node_volume=${docker_compose_name}_node_data
docker_client_volume=${docker_compose_name}_client_data docker_client_volume=${docker_compose_name}_client_data
@ -645,6 +754,29 @@ case "$command" in
exit 1 exit 1
esac ;; esac ;;
## Accuser
accuser)
subcommand="$1"
if [ "$#" -eq 0 ] ; then usage ; exit 1; else shift ; fi
case "$subcommand" in
status)
status_accuser
;;
start)
start_accuser
;;
log)
log_accuser
;;
stop)
stop_accuser
;;
*)
usage
exit 1
esac ;;
## Misc. ## Misc.
head) head)

View File

@ -27,9 +27,8 @@ trap cleanup EXIT INT
mkdir -p "$tmp_dir"/bin mkdir -p "$tmp_dir"/bin
mkdir -p "$tmp_dir"/scripts mkdir -p "$tmp_dir"/scripts
container=$(docker create $build_image) container=$(docker create $build_image)
for bin in tezos-client tezos-admin-client tezos-node \ versioned_daemons="$(sed "s/^\(.*\)$/tezos-\1-baker tezos-\1-endorser tezos-\1-accuser/g" "active_protocol_versions")"
tezos-alpha-baker tezos-alpha-endorser tezos-alpha-accuser \ for bin in tezos-client tezos-admin-client tezos-node $versioned_daemons tezos-signer; do
tezos-signer; do
docker cp -L $container:/home/tezos/tezos/$bin "$tmp_dir"/bin docker cp -L $container:/home/tezos/tezos/$bin "$tmp_dir"/bin
done done
cp -a "$script_dir"/docker/entrypoint.sh "$tmp_dir"/bin/ cp -a "$script_dir"/docker/entrypoint.sh "$tmp_dir"/bin/
@ -37,6 +36,7 @@ cp -a "$script_dir"/docker/entrypoint.inc.sh "$tmp_dir"/bin/
cp "$script_dir"/alphanet.sh "$tmp_dir"/scripts/ cp "$script_dir"/alphanet.sh "$tmp_dir"/scripts/
cp "$script_dir"/alphanet_version "$tmp_dir"/scripts/ cp "$script_dir"/alphanet_version "$tmp_dir"/scripts/
cp "$src_dir"/src/bin_client/bash-completion.sh "$tmp_dir"/scripts/ cp "$src_dir"/src/bin_client/bash-completion.sh "$tmp_dir"/scripts/
cp "$src_dir"/active_protocol_versions "$tmp_dir"/scripts/
echo echo
echo "### Building minimal docker image..." echo "### Building minimal docker image..."

View File

@ -14,9 +14,13 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
baker: ## Duplicate the `baker/endorser/accuser` containers for each PROTOCOL
## in file `active_protocol_versions`
baker-alpha:
image: tezos/tezos:latest image: tezos/tezos:latest
hostname: baker hostname: baker-alpha
environment:
- PROTOCOL=alpha
command: tezos-baker command: tezos-baker
links: links:
- node - node
@ -24,9 +28,11 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
endorser: endorser-alpha:
image: tezos/tezos:latest image: tezos/tezos:latest
hostname: endorser hostname: endorser-alpha
environment:
- PROTOCOL=alpha
command: tezos-endorser command: tezos-endorser
links: links:
- node - node
@ -34,9 +40,11 @@ services:
- client_data:/var/run/tezos/client - client_data:/var/run/tezos/client
restart: on-failure restart: on-failure
accuser: accuser-alpha:
image: tezos/tezos:latest image: tezos/tezos:latest
hostname: accuser hostname: accuser-alpha
environment:
- PROTOCOL=alpha
command: tezos-accuser command: tezos-accuser
links: links:
- node - node

View File

@ -9,12 +9,14 @@ bin_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
: ${NODE_HOST:="node"} : ${NODE_HOST:="node"}
: ${NODE_RPC_PORT:="8732"} : ${NODE_RPC_PORT:="8732"}
: ${PROTOCOL:="unspecified-PROTOCOL-variable"}
node="/usr/local/bin/tezos-node" node="/usr/local/bin/tezos-node"
client="/usr/local/bin/tezos-client" client="/usr/local/bin/tezos-client"
admin_client="/usr/local/bin/tezos-admin-client" admin_client="/usr/local/bin/tezos-admin-client"
baker="/usr/local/bin/tezos-alpha-baker" baker="/usr/local/bin/tezos-$PROTOCOL-baker"
endorser="/usr/local/bin/tezos-alpha-endorser" endorser="/usr/local/bin/tezos-$PROTOCOL-endorser"
accuser="/usr/local/bin/tezos-alpha-accuser" accuser="/usr/local/bin/tezos-$PROTOCOL-accuser"
signer="/usr/local/bin/tezos-signer" signer="/usr/local/bin/tezos-signer"
client_dir="$DATA_DIR/client" client_dir="$DATA_DIR/client"