Skip to content

Commit

Permalink
Merge pull request #286 from hollaex/testnet
Browse files Browse the repository at this point in the history
HollaEx CLI v2.8.1 Release
  • Loading branch information
kycfeel authored Sep 15, 2023
2 parents 09b9148 + a530e0b commit 0caa551
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 61 deletions.
157 changes: 102 additions & 55 deletions hollaex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Options:
--enable_maintenance_mode, Maintenance mode. Giving HTTP 503 for non-whitelisted IPs.
--whitelist-ip, List of whitelist IPs for the maintenance mode. Comma separated, no spaces.
--disable_maintenance_mode, Disabling maintenance mode.
--upgrade-psql-db-version, Upgrade PostgreSQL DB to a specific version.

dev: Running an exchange in a dev mode.
--setup, Setup an exchange in a dev mode.
Expand Down Expand Up @@ -1992,21 +1993,25 @@ elif [[ "$1" == "setup" ]]; then

sleep 5

IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_EXCHANGE_RUN_MODE}"
if [[ ! "$IS_HOLLAEX_SETUP" ]]; then

IFS=',' read -ra CONTAINER_PREFIX <<< "-${ENVIRONMENT_EXCHANGE_RUN_MODE}"

# Confirm that the local API server is up.
while ! [[ $(docker inspect -f "{{.Name}} {{.State.Status}}" ${DOCKER_COMPOSE_NAME_PREFIX}${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX}${DOCKER_COMPOSE_CONTAINER_NUMBER_CONNECTOR}1) == *"running"* ]] ;
do echo "Waiting for the containers to get fully initialized..."
sleep 5;
done;
# Confirm that the local API server is up.
while ! [[ $(docker inspect -f "{{.Name}} {{.State.Status}}" ${DOCKER_COMPOSE_NAME_PREFIX}${ENVIRONMENT_EXCHANGE_NAME}-server${CONTAINER_PREFIX}${DOCKER_COMPOSE_CONTAINER_NUMBER_CONNECTOR}1) == *"running"* ]] ;
do echo "Waiting for the containers to get fully initialized..."
sleep 5;
done;

fi

if [[ "$HOLLAEX_NETWORK_SETUP" ]]; then

local_hollaex_network_database_init start;

else

if [[ ! "$RESTORE_FROM_BACKUP" ]]; then
if [[ ! "$RESTORE_FROM_BACKUP" ]] || [[ ! "$UPGRADE_PSQL_DB_VERSION" ]]; then

local_database_init start;

Expand Down Expand Up @@ -3085,7 +3090,7 @@ elif [[ "$1" == "start" ]]; then
shift; continue
;;
--is_hollaex_setup)
IS_HOLLAEX_SETUP=true
export IS_HOLLAEX_SETUP=true
shift; continue
;;
--skip)
Expand Down Expand Up @@ -3244,7 +3249,7 @@ elif [[ "$1" == "start" ]]; then
echo "Scaling up containers on the cluster..."
kubectl scale deployment/$ENVIRONMENT_EXCHANGE_NAME-redis --replicas=1 --namespace $ENVIRONMENT_EXCHANGE_NAME

kubectl scale deployment/$ENVIRONMENT_EXCHANGE_NAME-db --replicas=1 --namespace $ENVIRONMENT_EXCHANGE_NAME
kubectl scale deployment/$HOLLAEX_SECRET_DB_HOST --replicas=1 --namespace $ENVIRONMENT_EXCHANGE_NAME

if [[ "$HOLLAEX_NETWORK_START" ]]; then

Expand Down Expand Up @@ -4587,7 +4592,7 @@ elif [[ "$1" == "stop" ]]; then

kubectl scale deployment/$ENVIRONMENT_EXCHANGE_NAME-redis --replicas=0 --namespace $ENVIRONMENT_EXCHANGE_NAME

kubectl scale deployment/$ENVIRONMENT_EXCHANGE_NAME-db --replicas=0 --namespace $ENVIRONMENT_EXCHANGE_NAME
kubectl scale deployment/$HOLLAEX_SECRET_DB_HOST --replicas=0 --namespace $ENVIRONMENT_EXCHANGE_NAME

if [[ "$HOLLAEX_NETWORK_STOP" ]]; then

Expand Down Expand Up @@ -7108,7 +7113,7 @@ elif [[ "$1" == "toolbox" ]]; then
--upgrade-psql-db-version)
shift
case $1 in (-*|"") err_msg_l; print_usage; exit 1; esac
UPGRADE_PSQL_DB_VERSION=$1
export UPGRADE_PSQL_DB_VERSION=$1
TOOLBOX_ENABLE=true
shift; continue
;;
Expand Down Expand Up @@ -7276,7 +7281,7 @@ elif [[ "$1" == "toolbox" ]]; then
echo "Upgrading PostgreSQL DB"
generate_nodeselector_values $ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_NODESELECTOR postgresql

helm upgrade --install $ENVIRONMENT_EXCHANGE_NAME-db \
helm upgrade --install $HOLLAEX_SECRET_DB_HOST \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
--set pvc.create=true \
--set pvc.name="$ENVIRONMENT_EXCHANGE_NAME-postgres-volume" \
Expand Down Expand Up @@ -7388,7 +7393,7 @@ elif [[ "$1" == "toolbox" ]]; then
echo "HollaEx CLI will open proxy tunnel between your machine and remote proxy with kubectl proxy."

echo "Opening local proxy on 5432 port of your machine..."
kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$ENVIRONMENT_EXCHANGE_NAME-db" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &
kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$HOLLAEX_SECRET_DB_HOST" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &

echo "Waiting for the proxy tunnel get fully ready..."
sleep 10;
Expand Down Expand Up @@ -7517,7 +7522,7 @@ elif [[ "$1" == "toolbox" ]]; then
echo "HollaEx CLI will open proxy tunnel between your machine and remote proxy with kubectl proxy."

echo "Opening local proxy on 5432 port of your machine..."
kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$ENVIRONMENT_EXCHANGE_NAME-db" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &
kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$HOLLAEX_SECRET_DB_HOST" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &

echo "Waiting for the proxy tunnel get fully ready..."
sleep 10;
Expand Down Expand Up @@ -7600,7 +7605,7 @@ elif [[ "$1" == "toolbox" ]]; then
generate_db_s3_backup_cronjob_config;

echo "Installing cronjob for database backup on Kubernetes."
if command helm upgrade --install $ENVIRONMENT_EXCHANGE_NAME-db-backup-s3 \
if command helm upgrade --install $HOLLAEX_SECRET_DB_HOST-backup-s3 \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
-f $TEMPLATE_GENERATE_PATH/kubernetes/config/db-s3-backup-cronjob.yaml \
$SCRIPTPATH/kubernetes/helm-chart/bitholla-hollaex-postgres-s3-backup-cronjob; then
Expand Down Expand Up @@ -8039,12 +8044,12 @@ elif [[ "$1" == "toolbox" ]]; then

check_kubernetes_dependencies;

if command kubectl get ns $ENVIRONMENT_EXCHANGE_NAME > /dev/null 2>&1 && command kubectl get pods -n $ENVIRONMENT_EXCHANGE_NAME -l app=$ENVIRONMENT_EXCHANGE_NAME-db > /dev/null 2>&1; then
if command kubectl get ns $ENVIRONMENT_EXCHANGE_NAME > /dev/null 2>&1 && command kubectl get pods -n $ENVIRONMENT_EXCHANGE_NAME -l app=$HOLLAEX_SECRET_DB_HOST > /dev/null 2>&1; then

echo "Successfully detected the PostgreSQL DB created by HollaEx CLI."
echo "Opening kube-proxy tunnel for database connection..."

kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$ENVIRONMENT_EXCHANGE_NAME-db" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &
kubectl port-forward --namespace $ENVIRONMENT_EXCHANGE_NAME $(kubectl get pod --namespace $ENVIRONMENT_EXCHANGE_NAME -l "app=$HOLLAEX_SECRET_DB_HOST" -o name | sed 's/pod\///' | head -n 1) 5432:5432 &
sleep 5;

echo "Opening local proxy on 5432 port of your machine..."
Expand Down Expand Up @@ -8073,7 +8078,7 @@ elif [[ "$1" == "toolbox" ]]; then

check_docker_compose_dependencies;

if command docker ps | grep $ENVIRONMENT_EXCHANGE_NAME-db > /dev/null 2>&1; then
if command docker ps | grep $HOLLAEX_SECRET_DB_HOST > /dev/null 2>&1; then

echo "Successfully detected the PostgreSQL DB created by HollaEx CLI."

Expand Down Expand Up @@ -8474,6 +8479,42 @@ elif [[ "$1" == "toolbox" ]]; then

fi

if [[ "$USE_KUBERNETES" ]]; then

echo "Getting a database dump..."
if ! command hollaex toolbox --backup --kube --skip; then

echo "Failed to get a database dump. Aborting the job."
exit 1;

fi

if ! command hollaex server --stop --kube --skip; then

echo "Something went wrong while restarting the exchange!"
exit 1;

fi

else

echo "Getting a database dump..."
if ! command hollaex toolbox --backup --skip; then

echo "Failed to get a database dump. Aborting the job."
exit 1;

fi

if ! command hollaex server --stop --skip; then

echo "Something went wrong while restarting the exchange!"
exit 1;

fi

fi

echo "Updating the DB to v$UPGRADE_PSQL_DB_VERSION..."
for i in ${CONFIG_FILE_PATH[@]}; do
if command grep -q "ENVIRONMENT_EXCHANGE_NAME" $i > /dev/null ; then
Expand All @@ -8491,63 +8532,62 @@ elif [[ "$1" == "toolbox" ]]; then

export SECRET_FILE_PATH=$i

sed -i.bak "s/HOLLAEX_SECRET_DB_HOST=.*/HOLLAEX_SECRET_DB_HOST=$(echo $UPGRADE_PSQL_DB_VERSION | tr -dc '[^[:alnum:]-]\n\r' | tr '[:upper:]' '[:lower:]' | tr -d ' ')-${ENVIRONMENT_EXCHANGE_NAME}-db/" $SECRET_FILE_PATH
sed -i.bak "s/HOLLAEX_SECRET_DB_HOST=.*/HOLLAEX_SECRET_DB_HOST=${ENVIRONMENT_EXCHANGE_NAME}-db-$(echo $UPGRADE_PSQL_DB_VERSION | tr -dc '[^[:alnum:]-]\n\r' | tr '[:upper:]' '[:lower:]' | tr -d ' ')/" $SECRET_FILE_PATH
rm $SECRET_FILE_PATH.bak

fi

done

if [[ "$USE_KUBERNETES" ]]; then
for i in ${CONFIG_FILE_PATH[@]}; do
source $i
done;

echo "Getting a database dump..."
if ! command hollaex toolbox --backup --kube --skip; then
if [[ "$USE_KUBERNETES" ]]; then

echo "Failed to get a database dump. Aborting the job."
exit 1;
for i in ${CONFIG_FILE_PATH[@]}; do
source $i
done;

fi
helm upgrade --install $HOLLAEX_SECRET_DB_HOST \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
--wait \
--set pvc.create=true \
--set pvc.name="$HOLLAEX_SECRET_DB_HOST-postgres-volume" \
--set pvc.size="$ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_VOLUMESIZE" \
--set secretName="$ENVIRONMENT_EXCHANGE_NAME-secret" \
--set resources.limits.cpu="${ENVIRONMENT_POSTGRESQL_CPU_LIMITS:-100m}" \
--set resources.limits.memory="${ENVIRONMENT_POSTGRESQL_MEMORY_LIMITS:-200Mi}" \
--set resources.requests.cpu="${ENVIRONMENT_POSTGRESQL_CPU_REQUESTS:-10m}" \
--set resources.requests.memory="${ENVIRONMENT_POSTGRESQL_MEMORY_REQUESTS:-100Mi}" \
-f $SCRIPTPATH/kubernetes/helm-chart/bitholla-hollaex-postgres/values.yaml \
-f $TEMPLATE_GENERATE_PATH/kubernetes/config/nodeSelector-postgresql.yaml \
$SCRIPTPATH/kubernetes/helm-chart/bitholla-hollaex-postgres $(kubernetes_set_backend_image_target $ENVIRONMENT_DOCKER_IMAGE_POSTGRESQL_REGISTRY $(if [[ "$KUBERNETES_PSQL_DB_EXISTS" ]]; then echo $EXISTING_DB_DOCKER_IMAGE_TAG; else echo $ENVIRONMENT_DOCKER_IMAGE_POSTGRESQL_VERSION; fi)) $(set_nodeport_access $ENVIRONMENT_KUBERNETES_ALLOW_EXTERNAL_POSTGRESQL_DB_ACCESS $ENVIRONMENT_KUBERNETES_EXTERNAL_POSTGRESQL_DB_ACCESS_PORT)

if [[ "$ENVIRONMENT_KUBERNETES_RUN_POSTGRESQL_DB" == true ]]; then
echo "Waiting until the DB become ready"
sleep 30

generate_nodeselector_values $ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_NODESELECTOR postgresql
BACKUP_FILE_PATH="backups/$(ls backups/ | tail -1)"

helm upgrade --install $ENVIRONMENT_EXCHANGE_NAME-db \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
--wait \
--set pvc.create=true \
--set pvc.name="$ENVIRONMENT_EXCHANGE_NAME-postgres-volume" \
--set pvc.size="$ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_VOLUMESIZE" \
--set secretName="$ENVIRONMENT_EXCHANGE_NAME-secret" \
--set resources.limits.cpu="${ENVIRONMENT_POSTGRESQL_CPU_LIMITS:-100m}" \
--set resources.limits.memory="${ENVIRONMENT_POSTGRESQL_MEMORY_LIMITS:-200Mi}" \
--set resources.requests.cpu="${ENVIRONMENT_POSTGRESQL_CPU_REQUESTS:-10m}" \
--set resources.requests.memory="${ENVIRONMENT_POSTGRESQL_MEMORY_REQUESTS:-100Mi}" \
-f $SCRIPTPATH/kubernetes/helm-chart/bitholla-hollaex-postgres/values.yaml \
-f $TEMPLATE_GENERATE_PATH/kubernetes/config/nodeSelector-postgresql.yaml \
$SCRIPTPATH/kubernetes/helm-chart/bitholla-hollaex-postgres $(kubernetes_set_backend_image_target $ENVIRONMENT_DOCKER_IMAGE_POSTGRESQL_REGISTRY $ENVIRONMENT_DOCKER_IMAGE_POSTGRESQL_VERSION) $(set_nodeport_access $ENVIRONMENT_KUBERNETES_ALLOW_EXTERNAL_POSTGRESQL_DB_ACCESS $ENVIRONMENT_KUBERNETES_EXTERNAL_POSTGRESQL_DB_ACCESS_PORT)
if ! command hollaex toolbox --kube --skip --restore $BACKUP_FILE_PATH; then

echo "Waiting until the database to be fully initialized"
sleep 60
echo "Failed to restore the DB. Please check the error logs."
exit 1;

fi

else
fi

echo "Getting a database dump..."
if ! command hollaex toolbox --backup --skip; then
if ! command hollaex server --start --skip --kube; then

echo "Failed to get a database dump. Aborting the job."
exit 1;
echo "Something went wrong while starting the exchange!"
exit 1;

fi

if ! command hollaex server --stop --skip; then

echo "Something went wrong while restarting the exchange!"
exit 1;
else

fi
for i in ${CONFIG_FILE_PATH[@]}; do
source $i
done;

if ! command hollaex server --start --skip --is_hollaex_setup; then

Expand All @@ -8568,6 +8608,13 @@ elif [[ "$1" == "toolbox" ]]; then

fi

if ! command hollaex server --start --skip; then

echo "Something went wrong while starting the exchange!"
exit 1;

fi

fi


Expand Down
10 changes: 5 additions & 5 deletions tools_generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ function generate_local_docker_compose() {

if [[ -f "$TEMPLATE_GENERATE_PATH/local/${ENVIRONMENT_EXCHANGE_NAME}-docker-compose.yaml" ]] && [[ ! "$UPGRADE_PSQL_DB_VERSION" ]] && [[ ! "$HOLLAEX_IS_SETUP" ]]; then

DOCKER_CONTAINER_NAME=$(docker ps -a | grep $HOLLAEX_SECRET_DB_HOST | cut -f1 -d " ")
DOCKER_CONTAINER_NAME=$(docker ps -a | grep $ENVIRONMENT_EXCHANGE_NAME | grep "\-db" | cut -f1 -d " " | head -n 1)
EXISTING_DB_DOCKER_IMAGE=$(docker inspect --format='{{.Config.Image}}' $DOCKER_CONTAINER_NAME)
EXISTING_DB_DOCKER_IMAGE_TAG=$(echo $EXISTING_DB_DOCKER_IMAGE | cut -f2 -d":")

Expand Down Expand Up @@ -5003,11 +5003,11 @@ function run_and_upgrade_hollaex_on_kubernetes() {

generate_nodeselector_values $ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_NODESELECTOR postgresql

if command helm ls -n $ENVIRONMENT_EXCHANGE_NAME | grep $ENVIRONMENT_EXCHANGE_NAME-db; then
if command helm ls -n $ENVIRONMENT_EXCHANGE_NAME | grep $HOLLAEX_SECRET_DB_HOST; then

export KUBERNETES_PSQL_DB_EXISTS=true

EXISTING_DB_DOCKER_IMAGE=$(kubectl get -n $ENVIRONMENT_EXCHANGE_NAME deployment/$ENVIRONMENT_EXCHANGE_NAME-db -o jsonpath="{.spec.template.spec.containers[0].image}")
EXISTING_DB_DOCKER_IMAGE=$(kubectl get -n $ENVIRONMENT_EXCHANGE_NAME deployment/$HOLLAEX_SECRET_DB_HOST -o jsonpath="{.spec.template.spec.containers[0].image}")
EXISTING_DB_DOCKER_IMAGE_TAG=$(echo $EXISTING_DB_DOCKER_IMAGE | cut -f2 -d":")

if [[ -z "$EXISTING_DB_DOCKER_IMAGE_TAG" ]]; then
Expand All @@ -5020,7 +5020,7 @@ function run_and_upgrade_hollaex_on_kubernetes() {

fi

helm upgrade --install $ENVIRONMENT_EXCHANGE_NAME-db \
helm upgrade --install $HOLLAEX_SECRET_DB_HOST \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
--wait \
--set pvc.create=true \
Expand Down Expand Up @@ -5216,7 +5216,7 @@ function run_and_upgrade_hollaex_network_on_kubernetes() {

generate_nodeselector_values $ENVIRONMENT_KUBERNETES_POSTGRESQL_DB_NODESELECTOR postgresql

helm upgrade --install $ENVIRONMENT_EXCHANGE_NAME-db \
helm upgrade --install $HOLLAEX_SECRET_DB_HOST \
--namespace $ENVIRONMENT_EXCHANGE_NAME \
--wait \
--set pvc.create=true \
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.0
2.8.1

0 comments on commit 0caa551

Please sign in to comment.