Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial versions of on-premise deploy scripts #1286

Merged
merged 18 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer
```
- Set up Ubuntu machine (if it's on a new VM)
```
bash setup_blockchain_ubuntu.sh
bash setup_blockchain_ubuntu_gcp.sh
```
- Start tracker server job
```
Expand Down Expand Up @@ -136,7 +136,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer
```
- Set up Ubuntu machine (if it's on a new VM)
```
bash setup_blockchain_ubuntu.sh
bash setup_blockchain_ubuntu_gcp.sh
```
- Start Node server job (set shard index to 0 if you're running a root chain node)
```
Expand Down
16 changes: 8 additions & 8 deletions config_client_api_ip_whitelist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ else
fi
fi

# Read node ip addresses
IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt

# Get keystore password
printf "Enter password: "
read -s PASSWORD
printf "Enter keystore password: "
read -s KEYSTORE_PW
printf "\n\n"
if [[ $SEASON = "mainnet" ]]; then
CHAIN_ID="1"
Expand All @@ -96,19 +96,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n"

function config_node() {
local node_index="$1"
local node_ip_addr=${IP_ADDR_LIST[${node_index}]}
local node_url=${NODE_URL_LIST[${node_index}]}

printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n"
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_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH"
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'"
fi

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

for j in `seq $(( 0 )) $(( 9 ))`; do
Expand Down
16 changes: 8 additions & 8 deletions config_node_param.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ else
fi
fi

# Read node ip addresses
IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt

# Get keystore password
printf "Enter password: "
read -s PASSWORD
printf "Enter keystore password: "
read -s KEYSTORE_PW
printf "\n\n"
if [[ $SEASON = "mainnet" ]]; then
CHAIN_ID="1"
Expand Down Expand Up @@ -107,19 +107,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n"

function config_node() {
local node_index="$1"
local node_ip_addr=${IP_ADDR_LIST[${node_index}]}
local node_url=${NODE_URL_LIST[${node_index}]}

printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n"
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_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM"
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'"
fi

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

for j in `seq $(( 0 )) $(( 9 ))`; do
Expand Down
46 changes: 26 additions & 20 deletions deploy_blockchain_genesis_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ while [ $ARG_INDEX -le $# ]; do
parse_options "${!ARG_INDEX}"
((ARG_INDEX++))
done

if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf "You cannot use --setup without --no-keep-code\n"
exit
fi

printf "SETUP_OPTION=$SETUP_OPTION\n"
printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n"
printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"
Expand Down Expand Up @@ -163,12 +169,12 @@ else
fi

if [[ ! $KILL_OPTION = '--kill-only' ]]; then
# Read node ip addresses
IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt
# Read node urls
IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt
if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then
# Get keystore password
printf "Enter password: "
read -s PASSWORD
printf "Enter keystore password: "
read -s KEYSTORE_PW
printf "\n\n"

if [[ "$SEASON" = "mainnet" ]]; then
Expand All @@ -185,41 +191,41 @@ fi

function inject_account() {
local node_index="$1"
local node_ip_addr=${IP_ADDR_LIST[${node_index}]}
local node_url=${NODE_URL_LIST[${node_index}]}
if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then
printf "\n* >> Injecting an account for node $node_index ********************\n\n"
printf "node_ip_addr='$node_ip_addr'\n"
printf "node_url='$node_url'\n"

KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json"
{
echo $KEYSTORE_FILE_PATH
sleep 1
echo $PASSWORD
} | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION
echo $KEYSTORE_PW
} | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION
elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then
local MNEMONIC=${MNEMONIC_LIST[${node_index}]}
printf "\n* >> Injecting an account for node $node_index ********************\n\n"
printf "node_ip_addr='$node_ip_addr'\n"
printf "node_url='$node_url'\n"
{
echo $MNEMONIC
sleep 1
echo 0
} | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION
} | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION
else
printf "\n* >> Injecting an account for node $node_index ********************\n\n"
printf "node_ip_addr='$node_ip_addr'\n"
printf "node_url='$node_url'\n"
local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json"
if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then
GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json"
fi
PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key')
echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION
echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION
fi
}

# deploy files
FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh"
FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh"
FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh"

TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan"
NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan"
Expand Down Expand Up @@ -279,7 +285,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then
# Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1
if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then
printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE
gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE
fi

begin_index=$PARENT_NODE_INDEX_BEGIN
Expand All @@ -292,7 +298,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then
NODE_ZONE=NODE_${node_index}_ZONE

printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE}
gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE}
done
fi
fi
Expand Down Expand Up @@ -486,13 +492,13 @@ if [[ $NUM_SHARDS -gt 0 ]]; then
# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME)
if [[ $SETUP_OPTION = "--setup" ]]; then
printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE
gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE
printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE
gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE
printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE
gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE
printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n"
gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE
gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE
fi

# install node modules on GCP instances
Expand Down
Loading
Loading