Updated ethereum node deployment workflow

pull/515/head
kompotkot 2021-12-22 19:29:35 +00:00
rodzic d9a8fd0b7d
commit 016aac05e4
6 zmienionych plików z 36 dodań i 227 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Deployment script - intended to run on Moonstream Ethereum node control server
# Deployment script - intended to run on Moonstream Ethereum node server
# Colors
C_RESET='\033[0m'
@ -22,12 +22,8 @@ PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
SCRIPT_DIR="$(realpath $(dirname $0))"
BLOCKCHAIN="ethereum"
# Parameters scripts
CHECKENV_PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.bash"
CHECKENV_NODES_CONNECTIONS_SCRIPT="${SCRIPT_DIR}/nodes-connections.bash"
# Nodes server service file
NODES_SERVER_SERVICE_FILE="moonstreamnodes.service"
# Node status server service file
NODE_STATUS_SERVER_SERVICE_FILE="node-status.service"
# Ethereum geth service file
ETHEREUM_GETH_SERVICE_FILE="geth.service"
@ -36,38 +32,38 @@ set -eu
echo
echo
echo -e "${PREFIX_INFO} Building executable server of moonstreamnodes with Go"
echo -e "${PREFIX_INFO} Building executable server of node status server"
EXEC_DIR=$(pwd)
cd "${APP_NODES_DIR}/server"
HOME=/root /usr/local/go/bin/go build -o "${APP_NODES_DIR}/server/moonstreamnodes" "${APP_NODES_DIR}/server/main.go"
HOME=/root /usr/local/go/bin/go build -o "${APP_NODES_DIR}/server/nodestatus" "${APP_NODES_DIR}/server/main.go"
cd "${EXEC_DIR}"
echo
echo
echo -e "${PREFIX_INFO} Install checkenv"
HOME=/root /usr/local/go/bin/go install github.com/bugout-dev/checkenv@latest
echo
echo
echo -e "${PREFIX_INFO} Retrieving deployment parameters"
mkdir -p "${SECRETS_DIR}"
> "${PARAMETERS_ENV_PATH}"
bash "${CHECKENV_PARAMETERS_SCRIPT}" -vn -p "moonstream" -o "${PARAMETERS_ENV_PATH}"
HOME=/root AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" $HOME/go/bin/checkenv show aws_ssm+Product:moonstream,Node:true >> "${PARAMETERS_ENV_PATH}"
echo
echo
echo -e "${PREFIX_INFO} Updating nodes connection parameters"
bash "${CHECKENV_NODES_CONNECTIONS_SCRIPT}" -v -f "${PARAMETERS_ENV_PATH}"
echo -e "${PREFIX_INFO} Add instance local IP to parameters"
AWS_LOCAL_IPV4="$(ec2metadata --local-ipv4)"
echo "AWS_LOCAL_IPV4=$AWS_LOCAL_IPV4" >> "${PARAMETERS_ENV_PATH}"
echo
echo
LOCAL_IP="$(ec2metadata --local-ipv4)"
echo -e "${PREFIX_INFO} Replacing current node IP environment variable with local IP ${C_GREEN}${LOCAL_IP}${C_RESET}"
sed -i "s|MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=.*|MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=\"$LOCAL_IP\"|" "${PARAMETERS_ENV_PATH}"
echo
echo
echo -e "${PREFIX_INFO} Replacing existing moonstreamnodes service definition with ${NODES_SERVER_SERVICE_FILE}"
chmod 644 "${SCRIPT_DIR}/${NODES_SERVER_SERVICE_FILE}"
cp "${SCRIPT_DIR}/${NODES_SERVER_SERVICE_FILE}" "/etc/systemd/system/${NODES_SERVER_SERVICE_FILE}"
echo -e "${PREFIX_INFO} Replacing existing node status server definition with ${NODE_STATUS_SERVER_SERVICE_FILE}"
chmod 644 "${SCRIPT_DIR}/${NODE_STATUS_SERVER_SERVICE_FILE}"
cp "${SCRIPT_DIR}/${NODE_STATUS_SERVER_SERVICE_FILE}" "/etc/systemd/system/${NODE_STATUS_SERVER_SERVICE_FILE}"
systemctl daemon-reload
systemctl restart "${NODES_SERVER_SERVICE_FILE}"
systemctl status "${NODES_SERVER_SERVICE_FILE}"
systemctl restart "${NODE_STATUS_SERVER_SERVICE_FILE}"
systemctl status "${NODE_STATUS_SERVER_SERVICE_FILE}"
echo
echo

Wyświetl plik

@ -10,11 +10,11 @@ ExecStart=/usr/bin/geth --syncmode snap --cache 4096 \
--datadir /mnt/disks/nodes/ethereum \
--txpool.globalslots 153600 --txpool.globalqueue 3072 \
--http --http.api eth,web3,txpool \
--http.addr "${MOONSTREAM_NODE_ETHEREUM_IPC_ADDR}" \
--http.port "${MOONSTREAM_NODE_ETHEREUM_IPC_PORT}"
--http.addr "${AWS_LOCAL_IPV4}" \
--http.port 8545
ExecStop=/bin/kill -s SIGINT -$MAINPID
TimeoutStopSec=300
SyslogIdentifier=ethereum-node
SyslogIdentifier=geth
[Install]
WantedBy=multi-user.target

Wyświetl plik

@ -1,14 +0,0 @@
[Unit]
Description=Moonstream node server
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/moonstream/nodes/server
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
ExecStart=/home/ubuntu/moonstream/nodes/server/moonstreamnodes -blockchain ethereum -host "${MOONSTREAM_NODE_ETHEREUM_IPC_ADDR}" -port "${MOONSTREAM_NODES_SERVER_PORT}"
SyslogIdentifier=moonstreamnodes
[Install]
WantedBy=multi-user.target

Wyświetl plik

@ -0,0 +1,14 @@
[Unit]
Description=Moonstream node status server
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/moonstream/nodes/server
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
ExecStart=/home/ubuntu/moonstream/nodes/server/nodestatus -blockchain ethereum -host "${AWS_LOCAL_IPV4}" -port 8734
SyslogIdentifier=node-status
[Install]
WantedBy=multi-user.target

Wyświetl plik

@ -1,89 +0,0 @@
#!/usr/bin/env bash
#
# Update nodes connection address environment variables
# from AWS Route53 internal hosted zone
VERSION='0.0.1'
# Colors
C_RESET='\033[0m'
C_RED='\033[1;31m'
C_GREEN='\033[1;32m'
C_YELLOW='\033[1;33m'
# Logs
PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]"
PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]"
PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]"
# Print help message
function usage {
echo "Usage: $0 [-h] -p PRODUCT -f FILEPATH"
echo
echo "CLI to update nodes connection address environment
variables from AWS Route53 internal hosted zone"
echo
echo "Optional arguments:"
echo " -h Show this help message and exit"
echo " -f File path where environment variables update at"
}
file_flag=""
verbose_flag="false"
while getopts 'f:v' flag; do
case "${flag}" in
f) file_flag="${OPTARG}" ;;
h) usage
exit 1 ;;
v) verbose_flag="true" ;;
*) usage
exit 1 ;;
esac
done
# Log messages
function verbose {
if [ "${verbose_flag}" == "true" ]; then
echo -e "$1"
fi
}
# File flag should be specified
if [ -z "${file_flag}" ]; then
verbose "${PREFIX_CRIT} Please specify file path"
usage
exit 1
fi
if [ ! -f "${file_flag}" ]; then
verbose "${PREFIX_CRIT} Provided file does not exist"
usage
exit 1
fi
verbose "${PREFIX_INFO} Script version: v${VERSION}"
verbose "${PREFIX_INFO} Source environment variables"
. ${file_flag}
verbose "${PREFIX_INFO} Retrieving Ethereum node address"
RETRIEVED_NODE_ETHEREUM_IPC_ADDR=$(aws route53 list-resource-record-sets --hosted-zone-id "${MOONSTREAM_INTERNAL_HOSTED_ZONE_ID}" --query "ResourceRecordSets[?Name == '${MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI}.'].ResourceRecords[].Value" | jq -r .[0])
if [ "$RETRIEVED_NODE_ETHEREUM_IPC_ADDR" == "null" ]; then
verbose "${PREFIX_CRIT} Ethereum node internal DNS record address is null"
exit 1
fi
verbose "${PREFIX_INFO} Retrieving Polygon node address"
RETRIEVED_NODE_POLYGON_IPC_ADDR=$(aws route53 list-resource-record-sets --hosted-zone-id "${MOONSTREAM_INTERNAL_HOSTED_ZONE_ID}" --query "ResourceRecordSets[?Name == '${MOONSTREAM_POLYGON_WEB3_PROVIDER_URI}.'].ResourceRecords[].Value" | jq -r .[0])
if [ "$RETRIEVED_NODE_POLYGON_IPC_ADDR" == "null" ]; then
verbose "${PREFIX_CRIT} Polygon node internal DNS record address is null"
exit 1
fi
# TODO(kompotkot): Modify regexp to work with export prefix
verbose "${PREFIX_INFO} Updating MOONSTREAM_NODE_ETHEREUM_IPC_ADDR with ${RETRIEVED_NODE_ETHEREUM_IPC_ADDR}"
sed -i "s|^MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=.*|MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=\"$RETRIEVED_NODE_ETHEREUM_IPC_ADDR\"|" ${file_flag}
verbose "${PREFIX_INFO} Updating MOONSTREAM_NODE_POLYGON_IPC_ADDR with ${RETRIEVED_NODE_POLYGON_IPC_ADDR}"
sed -i "s|^MOONSTREAM_NODE_POLYGON_IPC_ADDR=.*|MOONSTREAM_NODE_POLYGON_IPC_ADDR=\"$RETRIEVED_NODE_POLYGON_IPC_ADDR\"|" ${file_flag}

Wyświetl plik

@ -1,98 +0,0 @@
#!/usr/bin/env bash
#
# Collect secrets from AWS SSM Parameter Store and
# opt out as environment variable exports.
VERSION='0.0.2'
# Colors
C_RESET='\033[0m'
C_RED='\033[1;31m'
C_GREEN='\033[1;32m'
C_YELLOW='\033[1;33m'
# Logs
PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]"
PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]"
PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]"
# Print help message
function usage {
echo "Usage: $0 [-h] -p PRODUCT -o OUTPUT"
echo
echo "CLI to collect secrets from AWS SSM Parameter Store
and output as environment variable exports"
echo
echo "Optional arguments:"
echo " -h Show this help message and exit"
echo " -n Provide true if server is Blockchain node"
echo " -o Output file name environment variables export to"
echo " -p Product tag (moonstream, spire, brood, drones)"
}
# TODO(kompotkot): Flag for export prefix
node_flag=""
output_flag=""
product_flag=""
verbose_flag="false"
while getopts 'no:p:v' flag; do
case "${flag}" in
n) node_flag="true" ;;
o) output_flag="${OPTARG}" ;;
p) product_flag="${OPTARG}" ;;
h) usage
exit 1 ;;
v) verbose_flag="true" ;;
*) usage
exit 1 ;;
esac
done
# Log messages
function verbose {
if [ "${verbose_flag}" == "true" ]; then
echo -e "$1"
fi
}
# Product flag should be specified
# TODO(kompotkot): Extend script to work with few product at once
if [ -z "${product_flag}" ]; then
verbose "${PREFIX_CRIT} Please specify product tag"
usage
exit 1
fi
verbose "${PREFIX_INFO} Script version: v${VERSION}"
PARAMETER_FILTERS="Key=tag:Product,Values=${product_flag}"
if [ "${node_flag}" == "true" ]; then
verbose "${PREFIX_INFO} Node flag provided, extracting environment variables only for nodes"
PARAMETER_FILTERS="$PARAMETER_FILTERS Key=tag:Node,Values=true"
fi
verbose "${PREFIX_INFO} Retrieving deployment parameters with tag ${C_GREEN}Product:${product_flag}${C_RESET}"
ENV_PARAMETERS=$(aws ssm describe-parameters \
--parameter-filters ${PARAMETER_FILTERS} \
| jq -r .Parameters[].Name)
if [ -z "${ENV_PARAMETERS}" ]; then
verbose "${PREFIX_CRIT} There no parameters for provided product tag"
exit 1
fi
verbose "${PREFIX_INFO} Retrieving parameters values"
ENV_PARAMETERS_VALUES=$(aws ssm get-parameters \
--names ${ENV_PARAMETERS} \
--query "Parameters[*].{Name:Name,Value:Value}")
ENV_PARAMETERS_VALUES_LENGTH=$(echo ${ENV_PARAMETERS_VALUES} | jq length)
verbose "${PREFIX_INFO} Extracted ${ENV_PARAMETERS_VALUES_LENGTH} parameters"
for i in $(seq 0 $((${ENV_PARAMETERS_VALUES_LENGTH} - 1))); do
param_key=$(echo ${ENV_PARAMETERS_VALUES} | jq -r .[$i].Name)
param_value=$(echo ${ENV_PARAMETERS_VALUES} | jq .[$i].Value)
if [ -z "${output_flag}" ]; then
echo "${param_key}=${param_value}"
else
echo "${param_key}=${param_value}" >> "${output_flag}"
fi
done