From d8d54ce321957af87de718fb87667a9c7c52664b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 6 Dec 2017 19:51:57 +0100 Subject: [PATCH] Jbuilder: install `tezos-sandboxed-node.sh/tezos-init-sandboxed-client.sh` --- README.md | 12 ++-- bin_client/jbuild | 4 ++ .../tezos-init-sandboxed-client.sh | 65 ++++++++++++++++++- bin_node/jbuild | 4 ++ .../tezos-sandboxed-node.sh | 38 ++++++++++- scripts/Dockerfile.build.in | 4 +- scripts/Dockerfile.minimal.in | 1 - scripts/create_docker_image.minimal.sh | 11 ++-- scripts/docker_entrypoint.sh | 2 +- scripts/init-sandboxed-client.sh | 58 ----------------- scripts/launch-sandboxed-node.sh | 27 -------- test/jbuild | 42 ++++++------ test/lib/test_lib.inc.sh | 11 ++-- test/test_basic.sh | 2 +- test/test_contracts.sh | 2 +- test/test_multinode.sh | 2 +- 16 files changed, 153 insertions(+), 132 deletions(-) rename scripts/client_lib.inc.sh => bin_client/tezos-init-sandboxed-client.sh (77%) mode change 100644 => 100755 rename scripts/node_lib.inc.sh => bin_node/tezos-sandboxed-node.sh (58%) mode change 100644 => 100755 delete mode 100755 scripts/init-sandboxed-client.sh delete mode 100755 scripts/launch-sandboxed-node.sh diff --git a/README.md b/README.md index 1e00b73b5..4f7a3fb30 100644 --- a/README.md +++ b/README.md @@ -141,15 +141,15 @@ Running the node in a sandbox To run a 'localhost-only' instance of a Tezos network, we provide two helper scripts: -- `./scripts/launch-sandboxed-node.sh` -- `./scripts/init-sandboxed-client.sh` +- `./bin_node/tezos-sandboxed-node.sh` +- `./bin_client/tezos-init-sandboxed-client.sh` For instance, if you want to run local network with two nodes, in a first terminal, the following command will initialize a node listening for peers on port `19731` and listening for RPC on port `18731`. ``` -./scripts/launch-sandboxed-node.sh 1 +./bin_node/tezos-sandboxed-node.sh 1 ``` This node will store its data in a temporary directory which will be @@ -159,7 +159,7 @@ To launch the second node, just run the following command, it will listen on port `19739` and `18739`: ``` -./scripts/launch-sandboxed-node.sh 9 +./bin_node/tezos-sandboxed-node.sh 9 ``` You might replace `1` or `9` by any number in between if you want to @@ -169,14 +169,14 @@ by lowering the number of expected connection, by running the following command instead: ``` -./scripts/launch-sandboxed-node.sh 1 --connections 0 +./bin_node/tezos-sandboxed-node.sh 1 --connections 0 ``` Once your node(s) is/are running, open a new terminal and initialize the "sandboxed" client data: ``` -eval `./scripts/init-sandboxed-client.sh 1` +eval `./bin_client/tezos-init-sandboxed-client.sh 1` ``` It will initialize the client data in a temporary directory. It will diff --git a/bin_client/jbuild b/bin_client/jbuild index ac0000176..f3cd2b790 100644 --- a/bin_client/jbuild +++ b/bin_client/jbuild @@ -13,6 +13,10 @@ -open Tezos_client_base -linkall)))) +(install + ((section bin) + (files ((tezos-init-sandboxed-client.sh as tezos-init-sandboxed-client.sh))))) + (alias ((name runtest_indent) (deps ((glob_files *.ml) (glob_files *.mli))) diff --git a/scripts/client_lib.inc.sh b/bin_client/tezos-init-sandboxed-client.sh old mode 100644 new mode 100755 similarity index 77% rename from scripts/client_lib.inc.sh rename to bin_client/tezos-init-sandboxed-client.sh index eff976ba8..18b5cdd86 --- a/scripts/client_lib.inc.sh +++ b/bin_client/tezos-init-sandboxed-client.sh @@ -1,5 +1,7 @@ #! /usr/bin/env bash +set -e + client_dir="${client_dir:=$HOME/.tezos-client}" client="${client:=tezos-client -base-dir $client_dir}" @@ -13,7 +15,6 @@ init_sandboxed_client() { rpc=$((18730 + id)) client_dir="$(mktemp -d -t tezos-client.XXXXXXXX)" client_dirs+=("$client_dir") - local_client=${local_client:-$src_dir/_build/default/bin_client/main.exe} client="$local_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc" } @@ -211,3 +212,65 @@ activate_alpha() { and key dictator } + +usage() { + echo "Small script to initialize a client to a local and closed test network with a maximum of 9 nodes." + echo + echo "Usage: eval \`$0 \`" + echo " where should be an integer between 1 and 9." +} + +main () { + + local bin_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")" + if [ $(basename "$bin_dir") = "bin_client" ]; then + local_client="${local_client:-$bin_dir/../_build/default/bin_client/main.exe}" + fi + + if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then + usage + exit 1 + fi + + init_sandboxed_client "$1" + + add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2 + + cat </dev/null 2>&1 ; then tezos-client-reset; fi ; +alias tezos-client="$client" ; +alias tezos-activate-alpha="$client -block genesis activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK with fitness 1 and passes 1 and key dictator" ; +alias tezos-client-reset="rm -rf \"$client_dir\"; unalias tezos-client tezos-activate-alpha tezos-client-reset" ; +alias tezos-autocomplete="source \"$script_dir/bash-completion.sh\"" ; +trap tezos-client-reset EXIT ; +EOF + + (cat | sed -e 's/^/## /') 1>&2 <" + echo " where should be an integer between 1 and 9." + exit 1 + fi + + cleanup () { + set +e + echo Cleaning up... + cleanup_nodes + } + trap cleanup EXIT INT + + start_sandboxed_node "$@" + wait $node_pids + +} + +if [ "$0" == "$BASH_SOURCE" ]; then + main "$@" +fi diff --git a/scripts/Dockerfile.build.in b/scripts/Dockerfile.build.in index a77abdbb7..e85c791fd 100644 --- a/scripts/Dockerfile.build.in +++ b/scripts/Dockerfile.build.in @@ -4,5 +4,5 @@ COPY . tezos RUN sudo chown -R opam /home/opam/tezos && \ cd tezos && \ - opam config exec -- make all && \ - opam config exec -- make build-test + opam config exec -- jbuilder build @install && \ + opam config exec -- jbuilder install diff --git a/scripts/Dockerfile.minimal.in b/scripts/Dockerfile.minimal.in index 7938f97e3..94b4217fc 100644 --- a/scripts/Dockerfile.minimal.in +++ b/scripts/Dockerfile.minimal.in @@ -39,7 +39,6 @@ RUN sudo chown root:root bin/* && \ RUN sudo cp scripts/docker_entrypoint.sh /usr/local/bin/tezos && \ sudo cp scripts/docker_entrypoint.inc.sh \ - scripts/client_lib.inc.sh \ /usr/local/bin/ && \ sudo chmod a+rx /usr/local/bin/tezos diff --git a/scripts/create_docker_image.minimal.sh b/scripts/create_docker_image.minimal.sh index a19d135e2..2e9418f9d 100755 --- a/scripts/create_docker_image.minimal.sh +++ b/scripts/create_docker_image.minimal.sh @@ -14,17 +14,14 @@ build_image_name="${3:-${image_name}_build:${image_version}}" cleanup () { set +e echo Cleaning up... - [ -z "$tmp_container" ] || docker rm -f "$tmp_container" rm -rf Dockerfile bin } trap cleanup EXIT INT -tmp_container="$(docker run -dit "$build_image_name" /bin/sh -c "mkdir /home/opam/bin && cp /home/opam/tezos/tezos-* /home/opam/bin")" +docker run -dit --rm --volume $(pwd)/bin:/home/opam/bin "$build_image_name" \ + /bin/sh -c "sudo cp -L /home/opam/tezos/_build/install/default/bin/* /home/opam/bin" -ret=$(docker wait "$tmp_container") -if [ "$ret" -ne 0 ]; then exit $ret; fi - -docker cp "$tmp_container":/home/opam/bin/ bin +ls bin echo echo "### Building minimal docker image..." @@ -37,3 +34,5 @@ docker build -t "$image_name:$image_version" . echo echo "### Succesfully build docker image: $image_name:$image_version" echo + +rm -r bin diff --git a/scripts/docker_entrypoint.sh b/scripts/docker_entrypoint.sh index e9fe9e98f..eefff8237 100755 --- a/scripts/docker_entrypoint.sh +++ b/scripts/docker_entrypoint.sh @@ -12,7 +12,7 @@ export client_dir="$data_dir/client" export node="tezos-node" export client="tezos-client -base-dir $client_dir" -. "${script_dir}"/client_lib.inc.sh +. tezos-init-sandboxed-client.sh . "${script_dir}"/docker_entrypoint.inc.sh usage() { diff --git a/scripts/init-sandboxed-client.sh b/scripts/init-sandboxed-client.sh deleted file mode 100755 index 63fd039a3..000000000 --- a/scripts/init-sandboxed-client.sh +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env bash - -set -e - -script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")" -src_dir="$(dirname "$script_dir")" -cd "$src_dir" - -usage() { - echo "Small script to initialize a client to a local and closed test network with a maximum of 9 nodes." - echo - echo "Usage: eval \`$0 \`" - echo " where should be an integer between 1 and 9." -} - -if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then - usage - exit 1 -fi - -. "$script_dir/client_lib.inc.sh" - -init_sandboxed_client "$1" - -add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2 - -cat </dev/null 2>&1 ; then tezos-client-reset; fi ; -alias tezos-client="$client" ; -alias tezos-activate-alpha="$client -block genesis activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK with fitness 1 and passes 1 and key dictator" ; -alias tezos-client-reset="rm -rf \"$client_dir\"; unalias tezos-client tezos-activate-alpha tezos-client-reset" ; -alias tezos-autocomplete="source \"$script_dir/bash-completion.sh\"" ; -trap tezos-client-reset EXIT ; -EOF - -(cat | sed -e 's/^/## /') 1>&2 <" - echo " where should be an integer between 1 and 9." - exit 1 -fi - -cleanup () { - set +e - echo Cleaning up... - cleanup_nodes -} -trap cleanup EXIT INT - -start_sandboxed_node "$@" -wait $node_pids diff --git a/test/jbuild b/test/jbuild index 8d29eb133..098dde4ea 100644 --- a/test/jbuild +++ b/test/jbuild @@ -2,50 +2,50 @@ (alias ((name runtest_basic.sh) - (deps (../bin_node/main.exe - ../bin_client/main.exe - sandbox.json - test_basic.sh + (deps (sandbox.json lib/test_lib.inc.sh - ../scripts/node_lib.inc.sh - ../scripts/client_lib.inc.sh (glob_files contracts/*) )) (locks (/tcp-port/18731 /tcp-port/19731)) - (action (run bash ${path:test_basic.sh})))) + (action (run bash ${path:test_basic.sh} + ${bin:tezos-sandboxed-node.sh} + ${bin:tezos-node} + ${bin:tezos-init-sandboxed-client.sh} + ${bin:tezos-client} + )))) (alias ((name runtest_contracts.sh) - (deps (../bin_node/main.exe - ../bin_client/main.exe - sandbox.json - test_contracts.sh + (deps (sandbox.json lib/test_lib.inc.sh - ../scripts/node_lib.inc.sh - ../scripts/client_lib.inc.sh (glob_files contracts/*) )) (locks (/tcp-port/18731 /tcp-port/19731)) - (action (run bash ${path:test_contracts.sh})))) + (action (run bash ${path:test_contracts.sh} + ${bin:tezos-sandboxed-node.sh} + ${bin:tezos-node} + ${bin:tezos-init-sandboxed-client.sh} + ${bin:tezos-client} + )))) (alias ((name runtest_multinode.sh) - (deps (../bin_node/main.exe - ../bin_client/main.exe - sandbox.json - test_multinode.sh + (deps (sandbox.json lib/test_lib.inc.sh - ../scripts/node_lib.inc.sh - ../scripts/client_lib.inc.sh (glob_files contracts/*) )) (locks (/tcp-port/18731 /tcp-port/18732 /tcp-port/18733 /tcp-port/18734 /tcp-port/18735 /tcp-port/18736 /tcp-port/18737 /tcp-port/18738 /tcp-port/19731 /tcp-port/19732 /tcp-port/19733 /tcp-port/19734 /tcp-port/19735 /tcp-port/19736 /tcp-port/19737 /tcp-port/19738)) - (action (run bash ${path:test_multinode.sh})))) + (action (run bash ${path:test_multinode.sh} + ${bin:tezos-sandboxed-node.sh} + ${bin:tezos-node} + ${bin:tezos-init-sandboxed-client.sh} + ${bin:tezos-client} + )))) (alias ((name runtest) diff --git a/test/lib/test_lib.inc.sh b/test/lib/test_lib.inc.sh index 4a9957575..60568de56 100755 --- a/test/lib/test_lib.inc.sh +++ b/test/lib/test_lib.inc.sh @@ -6,11 +6,14 @@ src_dir="$(dirname "$test_dir")" cd "$test_dir" sandbox_file="$test_dir/sandbox.json" -local_node="$src_dir/bin_node/main.exe" -local_client="$src_dir/bin_client/main.exe" -source $src_dir/scripts/node_lib.inc.sh -source $src_dir/scripts/client_lib.inc.sh +tezos_sandboxed_node="${1:-$test_dir/../bin_node/tezos-sandboxed-node.sh}" +local_node="${2:-$test_dir/../_build/default/bin_node/main.exe}" +tezos_init_sandboxed_client="${3:-$test_dir/../bin_client/tezos-init-sandboxed-client.sh}" +local_client="${4:-$test_dir/../_build/default/bin_client/main.exe}" + +source $tezos_sandboxed_node +source $tezos_init_sandboxed_client ### Log files handling diff --git a/test/test_basic.sh b/test/test_basic.sh index 863ec7b21..c0b439dfe 100755 --- a/test/test_basic.sh +++ b/test/test_basic.sh @@ -3,7 +3,7 @@ set -e test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" -source $test_dir/lib/test_lib.inc.sh +source $test_dir/lib/test_lib.inc.sh "$@" start_node 1 activate_alpha diff --git a/test/test_contracts.sh b/test/test_contracts.sh index 7e0093ce5..849a27030 100755 --- a/test/test_contracts.sh +++ b/test/test_contracts.sh @@ -4,7 +4,7 @@ set -e set -o pipefail test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" -source $test_dir/lib/test_lib.inc.sh +source $test_dir/lib/test_lib.inc.sh "$@" start_node 1 activate_alpha diff --git a/test/test_multinode.sh b/test/test_multinode.sh index 94b0aeaf8..0091c739c 100755 --- a/test/test_multinode.sh +++ b/test/test_multinode.sh @@ -3,7 +3,7 @@ set -e test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" -source $test_dir/lib/test_lib.inc.sh +source $test_dir/lib/test_lib.inc.sh "$@" expected_connections=4 max_peer_id=8