From f48f5913034dc821ae754c92eff06cc07f4e476f Mon Sep 17 00:00:00 2001 From: Bartek Wrona <wrona@syncad.com> Date: Fri, 17 Jul 2020 18:30:49 +0200 Subject: [PATCH] CI commands moved into dedicated scripts to simplify yaml file. --- .gitlab-ci.yaml | 16 +--------------- scripts/ci_start_server.sh | 20 ++++++++++++++++++++ scripts/ci_sync.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 scripts/ci_start_server.sh create mode 100755 scripts/ci_sync.sh diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index 28821e72b..98d0d1cea 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -58,21 +58,7 @@ hivemind_sync: HIVEMIND_MAX_BLOCK: 50000 script: - - "DB_NAME=${HIVEMIND_DB_NAME/-/_}" - - "DB_URL=$HIVEMIND_POSTGRESQL_CONNECTION_STRING/$HIVEMIND_DB_NAME" - - "echo Corrected db name $DB_NAME" - - "echo Corrected db url $DB_URL" - - ls -l dist/* - - rm -rf ./local-site - - mkdir -p `python3 -m site --user-site` - - python3 setup.py install --user --force - - ./local-site/bin/hive -h - - "echo Attempting to recreate database $DB_NAME" - - psql -U $POSTGRES_USER -h localhost -d postgres -c "DROP DATABASE IF EXISTS $DB_NAME;" - - psql -U $POSTGRES_USER -h localhost -d postgres -c "CREATE DATABASE $DB_NAME;" - - "echo Attempting to starting hive sync using hived node: $HIVEMIND_SOURCE_HIVED_URL . Max sync block is: $HIVEMIND_MAX_BLOCK" - - echo Attempting to access database $DB_URL - - ./local-site/bin/hive sync --test-max-block=$HIVEMIND_MAX_BLOCK --exit-after-sync --test-profile=False --steemd-url "$HIVEMIND_SOURCE_HIVED_URL" --database-url $DB_URL 2>&1 | tee -i hivemind-sync.log + - scripts/ci_sync.sh "$HIVEMIND_DB_NAME" "$HIVEMIND_POSTGRESQL_CONNECTION_STRING" "$HIVEMIND_SOURCE_HIVED_URL" $HIVEMIND_MAX_BLOCK - echo Attempting to start hive server listening on $HIVEMIND_HTTP_PORT port... - if [ -f hive_server.pid ]; then kill -SIGINT `cat hive_server.pid`; fi; - rm -f hive_server.pid diff --git a/scripts/ci_start_server.sh b/scripts/ci_start_server.sh new file mode 100644 index 000000000..227283f63 --- /dev/null +++ b/scripts/ci_start_server.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +HIVEMIND_DB_NAME=$1 +HIVEMIND_POSTGRESQL_CONNECTION_STRING=$2 +HIVEMIND_SOURCE_HIVED_URL=$3 +HIVEMIND_HTTP_PORT=$4 + +PYTHONUSERBASE=./local-site + +DB_NAME=${HIVEMIND_DB_NAME/-/_} +DB_URL=$HIVEMIND_POSTGRESQL_CONNECTION_STRING/$DB_NAME + +echo Attempting to start hive server listening on $HIVEMIND_HTTP_PORT port... +if [ -f hive_server.pid ]; then kill -SIGINT `cat hive_server.pid`; fi; +rm -f hive_server.pid +screen -L -Logfile hive_server.log -dmS hive_server_$CI_JOB_ID ./local-site/bin/hive server --pid-file hive_server.pid --http-server-port $HIVEMIND_HTTP_PORT --steemd-url "$HIVEMIND_SOURCE_HIVED_URL" --database-url $DB_URL +for i in `seq 1 10`; do if [ -f hive_server.pid ]; then break; else sleep 1; fi; done +cat hive_server.pid diff --git a/scripts/ci_sync.sh b/scripts/ci_sync.sh new file mode 100755 index 000000000..06d6e9025 --- /dev/null +++ b/scripts/ci_sync.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +HIVEMIND_DB_NAME=$1 +HIVEMIND_POSTGRESQL_CONNECTION_STRING=$2 +HIVEMIND_SOURCE_HIVED_URL=$3 +HIVEMIND_MAX_BLOCK=$4 + +PYTHONUSERBASE=./local-site + +DB_NAME=${HIVEMIND_DB_NAME/-/_} +DB_URL=$HIVEMIND_POSTGRESQL_CONNECTION_STRING/$DB_NAME +echo Corrected db name $DB_NAME +echo Corrected db url $DB_URL +ls -l dist/* +rm -rf ./local-site +mkdir -p `python3 -m site --user-site` +python3 setup.py install --user --force +./local-site/bin/hive -h +echo Attempting to recreate database $DB_NAME +psql -U $POSTGRES_USER -h localhost -d postgres -c "DROP DATABASE IF EXISTS $DB_NAME;" +psql -U $POSTGRES_USER -h localhost -d postgres -c "CREATE DATABASE $DB_NAME;" +echo Attempting to starting hive sync using hived node: $HIVEMIND_SOURCE_HIVED_URL . Max sync block is: $HIVEMIND_MAX_BLOCK +echo Attempting to access database $DB_URL +./local-site/bin/hive sync --test-max-block=$HIVEMIND_MAX_BLOCK --exit-after-sync --test-profile=False --steemd-url "$HIVEMIND_SOURCE_HIVED_URL" --database-url $DB_URL 2>&1 | tee -i hivemind-sync.log -- GitLab