Skip to content

Commit

Permalink
Fix deploy script (#611)
Browse files Browse the repository at this point in the history
* Update vault-config script
* Add conditional log out output and list cmd
* Fix API nodes deployment (roles)
  • Loading branch information
dincho authored Feb 29, 2024
1 parent 0f6cdbc commit 07a4e14
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 17 deletions.
16 changes: 11 additions & 5 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,38 @@ fi
read -p "Deploy testnet API gateway - Stockholm? (y/N):" testnetgate1
if [[ $testnetgate1 == "y" ]]; then
make vault-config-update-api_uat
DEPLOY_ENV=api_uat DEPLOY_REGION=eu_north_1 make deploy
DEPLOY_ENV=api_uat DEPLOY_REGION=eu_north_1 DEPLOY_KIND="peer" make deploy

make vault-config-update-api_uat_channel
DEPLOY_ENV=api_uat DEPLOY_REGION=eu_north_1 DEPLOY_KIND="channel" CONFIG_KEY=api_uat_channel make deploy
fi

read -p "Deploy testnet API gateway - Singapore? (y/N):" testnetgate2
if [[ $testnetgate2 == "y" ]]; then
make vault-config-update-api_uat
DEPLOY_ENV=api_uat DEPLOY_REGION=ap_southeast_1 make deploy
DEPLOY_ENV=api_uat DEPLOY_REGION=ap_southeast_1 DEPLOY_KIND="peer" make deploy
fi

# Mainnet gateway nodes
read -p "Deploy mainnet API gateway - Stockholm? (y/N):" mainnetgate1
if [[ $mainnetgate1 == "y" ]]; then
make vault-config-update-api_main
DEPLOY_ENV=api_main DEPLOY_REGION=eu_north_1 make deploy
DEPLOY_ENV=api_main DEPLOY_REGION=eu_north_1 DEPLOY_KIND="peer" make deploy

make vault-config-update-api_main_channel
DEPLOY_ENV=api_main DEPLOY_REGION=eu_north_1 DEPLOY_KIND="channel" CONFIG_KEY=api_main_channel make deploy
fi

read -p "Deploy mainnet API gateway - Singapore? (y/N):" mainnetgate2
if [[ $mainnetgate2 == "y" ]]; then
make vault-config-update-api_main
DEPLOY_ENV=api_main DEPLOY_REGION=ap_southeast_1 make deploy
DEPLOY_ENV=api_main DEPLOY_REGION=ap_southeast_1 DEPLOY_KIND="peer" make deploy
fi

read -p "Deploy mainnet API gateway - Oregon? (y/N):" mainnetgate3
if [[ $mainnetgate3 == "y" ]]; then
make vault-config-update-api_main
DEPLOY_ENV=api_main DEPLOY_REGION=us-west-2 make deploy
DEPLOY_ENV=api_main DEPLOY_REGION=us-west-2 DEPLOY_KIND="peer" make deploy
fi

# restore the working dir
Expand Down
128 changes: 116 additions & 12 deletions scripts/vault-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CONFIG_ROOT=${CONFIG_ROOT:-secret2/aenode/config}
CONFIG_FIELD=${CONFIG_FIELD:-ansible_vars}
DEFAULT_FIELD_FILE_SUFFIX=${DEFAULT_FIELD_FILE_SUFFIX:-".yml"}
DRY_RUN=${DRY_RUN:-""}
KV2=${KV2:-""}
KV2=${KV2:-"1"}
VERBOSE=${VERBOSE:-""}

if [ $DRY_RUN ]; then
echo "### RUNNING IN DRY RUN MODE ###"
Expand All @@ -17,15 +18,24 @@ fi

usage() {
USAGE="Usage:
${0} dump <config_key>
${0} list
${0} dump <config_keys>
${0} dmp-yml -f <file> -p <path> <config_keys>
${0} dump-all
${0} update <config_key>
${0} update <config_keys>
${0} update-yml -f <file> -p <path> -v <value> <config_keys>
${0} update-all
"

echo -e "$USAGE" >&2; exit 1
}

log() {
if [ $VERBOSE ]; then
echo "${1:-}"
fi
}

# "return value"
CONFIG_FILE_PATH=""
set_config_file_path() {
Expand All @@ -42,18 +52,30 @@ set_config_file_path() {
CONFIG_FILE_PATH="${CONFIG_OUTPUT_DIR}/${config_key}/${config_field}${field_file_suffix}"
}

list() {
if [ $KV2 ]; then
vault kv list ${CONFIG_ROOT:?} | tail -n +3
else
vault list ${CONFIG_ROOT:?} | tail -n +3
fi
}

dump_field() {
local config_key=${1:?}
local config_field=${2:?}

set_config_file_path $config_key $config_field
echo "Dumping field: $CONFIG_FILE_PATH"
log "Dumping field: $CONFIG_FILE_PATH"

if [ $DRY_RUN ]; then
vault read -field=${config_field} ${CONFIG_ROOT:?}/${config_key} > /dev/null
else
mkdir -p ${CONFIG_OUTPUT_DIR}/${config_key}
vault read -field=${config_field} ${CONFIG_ROOT:?}/${config_key} > ${CONFIG_FILE_PATH}
if [ $KV2 ]; then
vault kv get -field=${config_field} ${CONFIG_ROOT:?}/${config_key} > ${CONFIG_FILE_PATH}
else
vault read -field=${config_field} ${CONFIG_ROOT:?}/${config_key} > ${CONFIG_FILE_PATH}
fi
fi
}

Expand All @@ -62,7 +84,7 @@ update_field() {
local config_field=${2:?}

set_config_file_path $config_key $config_field
echo "Updating field: $CONFIG_FILE_PATH"
log "Updating field: $CONFIG_FILE_PATH"

if [ ! $DRY_RUN ]; then
if [ $KV2 ]; then
Expand All @@ -78,9 +100,14 @@ dump_config() {
local config_key=${1:?}
local config_path=${CONFIG_ROOT:?}/${config_key}

echo "Dumping config: $config_path"
log "Dumping config: $config_path"

if [ $KV2 ]; then
local res=$(vault kv get -format=json ${config_path} | jq -r '.data.data | keys[]')
else
local res=$(vault read -format=json ${config_path} | jq -r '.data | keys[]')
fi

local res=$(vault read -format=json ${config_path} | jq -r '.data | keys[]')
mapfile -t fields <<< "$res"

for field in "${fields[@]}"
Expand All @@ -94,7 +121,7 @@ update_config() {
local config_key=${1:?}
local config_path=${CONFIG_ROOT:?}/${config_key}

echo "Updating config: $config_path"
log "Updating config: $config_path"

if [ $KV2 ]; then
if [ ! $DRY_RUN ]; then
Expand Down Expand Up @@ -122,18 +149,25 @@ dump() {
done
}

update() {
dump_yml_value() {
local config_path=${1:?}

yq r "${config_path}/${YAML_FILE:?}" "${YAML_PATH:?}"
}

dump_yml() {
local config_keys
read -r -a config_keys <<< "${1:?}"

for config_key in "${config_keys[@]}"
do
update_config "${config_key}"
log "### ${CONFIG_OUTPUT_DIR}/${config_key} ###"
dump_yml_value "${CONFIG_OUTPUT_DIR}/${config_key}"
done
}

dump_all() {
local res=$(vault list ${CONFIG_ROOT:?} | tail -n +3)
local res=$(list)
local config_keys
mapfile -t config_keys <<< "${res}"

Expand All @@ -143,6 +177,34 @@ dump_all() {
done
}

update() {
local config_keys
read -r -a config_keys <<< "${1:?}"

for config_key in "${config_keys[@]}"
do
update_config "${config_key}"
done
}

update_yml_value() {
local config_path=${1:?}

yq r "${config_path}/${YAML_FILE:?}" "${YAML_PATH:?}" "${YAML_VALUE:?}"
yq w -i "${config_path}/${YAML_FILE:?}" "${YAML_PATH:?}" "${YAML_VALUE:?}"
}

update_yml() {
local config_keys
read -r -a config_keys <<< "${1:?}"

for config_key in "${config_keys[@]}"
do
update_yml_value "${CONFIG_OUTPUT_DIR}/${config_key}"
# update_config "${config_key}"
done
}

update_all() {
local res=$(ls "${CONFIG_OUTPUT_DIR}")
mapfile -t config_keys <<< "$res"
Expand All @@ -157,15 +219,57 @@ update_all() {
### MAIN ###
if [[ -n "$1" ]]; then
case "$1" in
list)
list
;;
dump)
dump "${*:2}"
;;
dump-yml)
shift
while getopts "f:p:" option; do
case $option in
f)
YAML_FILE=$OPTARG
;;
p)
YAML_PATH=$OPTARG
;;
\?) # not option
usage
;;
esac
done
shift $(($OPTIND - 1))
dump_yml "$*"
;;
dump-all)
dump_all
;;
update)
update "${*:2}"
;;
update-yml)
shift
while getopts "f:p:v:" option; do
case $option in
f)
YAML_FILE=$OPTARG
;;
p)
YAML_PATH=$OPTARG
;;
v)
YAML_VALUE=$OPTARG
;;
\?) # not option
usage
;;
esac
done
shift $(($OPTIND - 1))
update_yml "$*"
;;
update-all)
update_all
;;
Expand Down

0 comments on commit 07a4e14

Please sign in to comment.