Skip to content

Commit

Permalink
Merge pull request #1328 from ainblockchain/bugfix/platfowner/bugfix
Browse files Browse the repository at this point in the history
Improve deploy-related scripts
  • Loading branch information
platfowner authored Sep 13, 2024
2 parents c040808 + 8ecd02d commit 6e6ffdb
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 81 deletions.
51 changes: 31 additions & 20 deletions config_client_api_ip_whitelist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,54 @@

function usage() {
printf "\n"
printf "Usage: bash config_client_api_ip_whitelist.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [get|add|remove] [<IP Address>]\n"
printf "Example: bash config_client_api_ip_whitelist.sh dev get\n"
printf "Example: bash config_client_api_ip_whitelist.sh dev add 32.190.239.181\n"
printf "Example: bash config_client_api_ip_whitelist.sh dev add '*'\n"
printf "Example: bash config_client_api_ip_whitelist.sh dev remove 32.190.239.181\n"
printf "Usage: bash config_client_api_ip_whitelist.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [gcp|onprem] [get|add|remove] [<IP Address>]\n"
printf "Example: bash config_client_api_ip_whitelist.sh staging onprem get\n"
printf "Example: bash config_client_api_ip_whitelist.sh staging onprem add 32.190.239.181\n"
printf "Example: bash config_client_api_ip_whitelist.sh staging onprem add '*'\n"
printf "Example: bash config_client_api_ip_whitelist.sh staging onprem remove 32.190.239.181\n"
printf "\n"
exit
}

if [[ $# -lt 2 ]] || [[ $# -gt 3 ]]; then
if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then
usage
fi
printf "\n[[[[[ config_client_api_ip_whitelist.sh ]]]]]\n\n"

if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
else
printf "Invalid <Project/Season> argument: $1\n"
printf "\nInvalid <Season> argument: $1\n"
usage
fi
printf "SEASON=$SEASON\n"

if [[ "$2" = 'get' ]]; then
COMMAND="$2"
IP_ADDR="$3"
if [[ "$2" = 'gcp' ]] || [[ "$2" = 'onprem' ]]; then
BLOCKCHAIN_HOSTING="$2"
else
printf "\nInvalid <Blockchain Hosting> argument: $2\n"
usage
fi
printf "BLOCKCHAIN_HOSTING=$BLOCKCHAIN_HOSTING\n"

COMMAND="$3"
IP_ADDR=""
if [[ $# = 4 ]]; then
IP_ADDR="$4"
fi

if [[ "$COMMAND" = 'get' ]]; then
if [[ ! "$IP_ADDR" = "" ]]; then
printf "\nInvalid argument: $IP_ADDR\n"
printf "\nInvalid <IP Address> argument: $IP_ADDR\n"
usage
fi
elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]]; then
COMMAND="$2"
IP_ADDR="$3"
elif [[ "$COMMAND" = 'add' ]] || [[ "$COMMAND" = 'remove' ]]; then
if [[ "$IP_ADDR" = "" ]]; then
printf "\nInvalid <IP Address> argument: $IP_ADDR\n"
usage
fi
else
printf "Invalid <Command> argument: $2\n"
printf "\nInvalid <Command> argument: $COMMAND\n"
usage
fi
printf "COMMAND=$COMMAND\n"
Expand All @@ -65,7 +75,7 @@ else
fi

# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_${BLOCKCHAIN_HOSTING}.txt

# Get keystore password
printf "Enter keystore password: "
Expand Down Expand Up @@ -101,16 +111,17 @@ function config_node() {
printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n"

KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json"
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH"
if [[ ! $COMMAND = "get" ]]; then
CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$IP_ADDR'"
if [[ $COMMAND = "get" ]]; then
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH"
else
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $IP_ADDR keystore $KEYSTORE_FILE_PATH"
fi

printf "\n"
printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n"
eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD"
}

for j in `seq $(( 0 )) $(( 9 ))`; do
for j in `seq $(( 0 )) $(( 4 ))`; do
config_node "$j"
done
60 changes: 35 additions & 25 deletions config_node_param.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,51 @@

function usage() {
printf "\n"
printf "Usage: bash config_node_param.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [get|add|remove] <Param> [<Value>]\n"
printf "Example: bash config_node_param.sh dev get DEV_CLIENT_API_IP_WHITELIST\n"
printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh dev remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh dev set DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh dev get CORS_WHITELIST\n"
printf "Usage: bash config_node_param.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [gcp|onprem] [get|add|remove] <Param> [<Value>]\n"
printf "Example: bash config_node_param.sh staging onprem get DEV_CLIENT_API_IP_WHITELIST\n"
printf "Example: bash config_node_param.sh staging onprem add DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh staging onprem add DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh staging onprem remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n"
printf "Example: bash config_node_param.sh staging onprem set DEV_CLIENT_API_IP_WHITELIST '*'\n"
printf "Example: bash config_node_param.sh staging onprem get CORS_WHITELIST\n"
printf "\n"
exit
}

if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then
if [[ $# -lt 4 ]] || [[ $# -gt 5 ]]; then
usage
fi
printf "\n[[[[[ config_node_param.sh ]]]]]\n\n"

if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
else
printf "Invalid <Project/Season> argument: $1\n"
printf "\nInvalid <Season> argument: $1\n"
usage
fi
printf "SEASON=$SEASON\n"

if [[ "$2" = 'get' ]]; then
COMMAND="$2"
PARAM="$3"
VALUE="$4"
if [[ "$2" = 'gcp' ]] || [[ "$2" = 'onprem' ]]; then
BLOCKCHAIN_HOSTING="$2"
else
printf "\nInvalid <Blockchain Hosting> argument: $2\n"
usage
fi
printf "BLOCKCHAIN_HOSTING=$BLOCKCHAIN_HOSTING\n"

COMMAND="$3"
PARAM="$4"
VALUE=""
if [[ $# = 5 ]]; then
VALUE="$5"
fi

if [[ "$COMMAND" = 'get' ]]; then
if [[ ! "$VALUE" = "" ]]; then
printf "\nInvalid argument: $VALUE\n"
printf "\nInvalid <Value> argument: $VALUE\n"
usage
fi
elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]] || [[ "$2" = 'set' ]]; then
COMMAND="$2"
PARAM="$3"
VALUE="$4"
elif [[ "$COMMAND" = 'add' ]] || [[ "$COMMAND" = 'remove' ]] || [[ "$COMMAND" = 'set' ]]; then
if [[ "$PARAM" = "" ]]; then
printf "\nInvalid <Param> argument: $PARAM\n"
usage
Expand All @@ -47,7 +56,7 @@ elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]] || [[ "$2" = 'set' ]]; then
usage
fi
else
printf "Invalid <Command> argument: $2\n"
printf "\nInvalid <Command> argument: $COMMAND\n"
usage
fi
printf "COMMAND=$COMMAND\n"
Expand All @@ -74,7 +83,7 @@ else
fi

# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_${BLOCKCHAIN_HOSTING}.txt

# Get keystore password
printf "Enter keystore password: "
Expand Down Expand Up @@ -109,19 +118,20 @@ function config_node() {
local node_index="$1"
local node_url=${NODE_URL_LIST[${node_index}]}

printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n"
printf "\n\n<<< Configuring node params of node $node_index ($node_url) >>>\n\n"

KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json"
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM"
if [[ ! $COMMAND = "get" ]]; then
CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'"
if [[ $COMMAND = "get" ]]; then
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $PARAM $VALUE keystore $KEYSTORE_FILE_PATH"
else
CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $PARAM $VALUE keystore $KEYSTORE_FILE_PATH"
fi

printf "\n"
printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n"
eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD"
}

for j in `seq $(( 0 )) $(( 9 ))`; do
for j in `seq $(( 0 )) $(( 4 ))`; do
config_node "$j"
done
38 changes: 33 additions & 5 deletions copy_blockchain_data_gcp.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

function usage() {
printf "Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <Node Index> [download|upload]\n"
printf "Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <Node Index> [download|upload] [<Old Port Number> <New Port Number>]\n"
printf "Example: bash copy_blockchain_data_gcp.sh spring 0 download\n"
printf "Example: bash copy_blockchain_data_gcp.sh spring 1 upload\n"
printf "Example: bash copy_blockchain_data_gcp.sh spring 1 upload 8079 8080\n"
printf "\n"
exit
}

if [[ $# -lt 3 ]] || [[ $# -gt 3 ]]; then
if [[ $# != 3 ]] && [[ $# != 5 ]]; then
usage
fi

Expand All @@ -22,7 +22,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[
PROJECT_ID="testnet-$1-ground"
fi
else
printf "Invalid <Project/Season> argument: $1\n"
printf "Invalid <Season> argument: $1\n"
exit
fi
printf "\n"
Expand Down Expand Up @@ -56,6 +56,28 @@ else
fi
printf "COMMAND=$COMMAND\n"

if [[ "$COMMAND" = 'download' ]]; then
if [[ $# != 3 ]]; then
printf "\n"
printf "<Old Port Number> and <New Port Number> can be used only with 'upload' command.\n"
printf "\n"
usage
fi
OLD_PORT=""
NEW_PORT=""
else
if [[ $# != 5 ]]; then
printf "\n"
printf "<Old Port Number> and <New Port Number> should be specified with 'upload' command.\n"
printf "\n"
usage
fi
OLD_PORT="$4"
NEW_PORT="$5"
fi
printf "OLD_PORT=$OLD_PORT\n"
printf "NEW_PORT=$NEW_PORT\n"

# Get confirmation.
if [[ "$SEASON" = "mainnet" ]]; then
printf "\n"
Expand Down Expand Up @@ -151,7 +173,13 @@ function upload_data() {
printf "TGZ_CMD=$TGZ_CMD\n\n"
eval $TGZ_CMD

# 3. Clean up tgz file for node
# 3. Change port number directory
printf "\n\n<<< Changing port number directory for node $node_index >>>\n\n"
MV_CMD="gcloud compute ssh $node_target_addr --command 'mv /home/ain_blockchain_data/chains/${OLD_PORT} /home/ain_blockchain_data/chains/${NEW_PORT}; mv /home/ain_blockchain_data/snapshots/${OLD_PORT} /home/ain_blockchain_data/snapshots/${NEW_PORT}' --project $PROJECT_ID --zone $node_zone"
printf "MV_CMD=$MV_CMD\n\n"
eval $MV_CMD

# 4. Clean up tgz file for node
printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n"
CLEANUP_CMD="gcloud compute ssh $node_target_addr --command 'rm ~/ain_blockchain_data.tar.gz' --project $PROJECT_ID --zone $node_zone"
printf "CLEANUP_CMD=$CLEANUP_CMD\n\n"
Expand Down
38 changes: 33 additions & 5 deletions copy_blockchain_data_onprem.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash

function usage() {
printf "Usage: bash copy_blockchain_data_onprem.sh [staging|spring|mainnet] <Node Index> [download|upload]\n"
printf "Usage: bash copy_blockchain_data_onprem.sh [staging|spring|mainnet] <Node Index> [download|upload] [<Old Port Number> <New Port Number>]\n"
printf "Example: bash copy_blockchain_data_onprem.sh staging 0 download\n"
printf "Example: bash copy_blockchain_data_onprem.sh staging 1 upload\n"
printf "Example: bash copy_blockchain_data_onprem.sh staging 1 upload 8080 8079\n"
printf "\n"
exit
}

if [[ $# -lt 3 ]] || [[ $# -gt 3 ]]; then
if [[ $# != 3 ]] && [[ $# != 5 ]]; then
usage
fi

if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
else
printf "Invalid <Project/Season> argument: $1\n"
printf "Invalid <Season> argument: $1\n"
exit
fi
printf "\n"
Expand Down Expand Up @@ -48,6 +48,28 @@ else
fi
printf "COMMAND=$COMMAND\n"

if [[ "$COMMAND" = 'download' ]]; then
if [[ $# != 3 ]]; then
printf "\n"
printf "<Old Port Number> and <New Port Number> can be used only with 'upload' command.\n"
printf "\n"
usage
fi
OLD_PORT=""
NEW_PORT=""
else
if [[ $# != 5 ]]; then
printf "\n"
printf "<Old Port Number> and <New Port Number> should be specified with 'upload' command.\n"
printf "\n"
usage
fi
OLD_PORT="$4"
NEW_PORT="$5"
fi
printf "OLD_PORT=$OLD_PORT\n"
printf "NEW_PORT=$NEW_PORT\n"

# Get confirmation.
if [[ "$SEASON" = "mainnet" ]]; then
printf "\n"
Expand Down Expand Up @@ -120,7 +142,13 @@ function upload_data() {
printf "TGZ_CMD=$TGZ_CMD\n\n"
eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${TGZ_CMD}"

# 3. Clean up tgz file for node
# 3. Change port number directory
printf "\n\n<<< Changing port number directory for node $node_index >>>\n\n"
MV_CMD="ssh $node_target_addr 'mv /home/${SEASON}/ain_blockchain_data/chains/${OLD_PORT} /home/${SEASON}/ain_blockchain_data/chains/${NEW_PORT}; mv /home/${SEASON}/ain_blockchain_data/snapshots/${OLD_PORT} /home/${SEASON}/ain_blockchain_data/snapshots/${NEW_PORT}'"
printf "MV_CMD=$MV_CMD\n\n"
eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${MV_CMD}"

# 4. Clean up tgz file for node
printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n"
CLEANUP_CMD="ssh $node_target_addr 'rm ~/ain_blockchain_data.tar.gz'"
printf "CLEANUP_CMD=$CLEANUP_CMD\n\n"
Expand Down
4 changes: 2 additions & 2 deletions deploy_blockchain_genesis_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[
PROJECT_ID="testnet-$1-ground"
fi
else
printf "Invalid project/season argument: $1\n"
printf "Invalid <Season> argument: $1\n"
exit
fi
printf "SEASON=$SEASON\n"
Expand Down Expand Up @@ -162,7 +162,7 @@ fi

if [[ ! $KILL_OPTION = '--kill-only' ]]; then
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt
if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then
# Get keystore password
printf "Enter keystore password: "
Expand Down
2 changes: 1 addition & 1 deletion deploy_blockchain_genesis_onprem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ printf "\n[[[[[ deploy_blockchain_genesis_onprem.sh ]]]]]\n\n"
if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
else
printf "Invalid project/season argument: $1\n"
printf "Invalid <Season> argument: $1\n"
exit
fi
printf "SEASON=$SEASON\n"
Expand Down
Loading

0 comments on commit 6e6ffdb

Please sign in to comment.