From c3e23fa29921a2c1d1f1e1096136338d4afc260d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Criado-P=C3=A9rez?= Date: Thu, 20 Jul 2023 09:31:48 +0200 Subject: [PATCH] Feat/script cluster (#1678) * Added help functionality on script * check if docker-compose is installed when needed * Added write-logs --- scripts/cluster | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/scripts/cluster b/scripts/cluster index 3957b292a8..f2c0d0c1ab 100755 --- a/scripts/cluster +++ b/scripts/cluster @@ -15,12 +15,37 @@ if [[ "$1" == "polybft" ]] && ! command -v nc >/dev/null 2>&1; then dp_error_flag=1 fi +# Check if docker-compose is installed +if [[ "$2" == "--docker" ]] && ! command -v docker-compose >/dev/null 2>&1; then + echo "docker-compose is not installed." + echo "Manual installation instructions: Visit https://docs.docker.com/compose/install/ for more information." + dp_error_flag=1 +fi + # Stop script if any of the dependencies have failed if [[ "$dp_error_flag" -eq 1 ]]; then echo "Missing dependencies. Please install them and run the script again." exit 1 fi +function showhelp(){ + echo "Usage: cluster {consensus} [{command}] [{flags}]" + echo "Consensus:" + echo " ibft Start Supernets test environment locally with ibft consensus" + echo " polybft Start Supernets test environment locally with polybft consensus" + echo "Commands:" + echo " stop Stop the running environment" + echo " destroy Destroy the running environment" + echo " write-logs Writes STDOUT and STDERR output to log file. Not applicable when using --docker flag." + echo "Flags:" + echo " --docker Run using Docker (requires docker-compose)." + echo " --help Display this help information" + echo "Examples:" + echo " cluster polybft -- Run the script with the polybft consensus" + echo " cluster polybtt --docker -- Run the script with the polybft consensus using docker" + echo " cluster polybft stop -- Stop the running environment" +} + function initIbftConsensus() { echo "Running with ibft consensus" ./polygon-edge secrets init --insecure --data-dir test-chain- --num 4 @@ -180,6 +205,12 @@ function stopDockerEnvironment() { set -e +# Show help if help flag is entered or no arguments are provided +if [[ "$1" == "--help" ]] || [[ $# -eq 0 ]]; then + showhelp + exit 0 +fi + # Reset test-dirs rm -rf test-chain-* rm -f genesis.json @@ -228,7 +259,8 @@ case "$2" in startServerFromBinary $2 exit 0 else - echo "Unsupported consensus mode. Supported modes are: ibft and polybft " + echo "Unsupported consensus mode. Supported modes are: ibft and polybft." + showhelp exit 1 fi ;;