From f36f1eb0ff88d19bb11be0ce6d280730db761b29 Mon Sep 17 00:00:00 2001 From: Konrad Botor <kbotor@syncad.com> Date: Wed, 14 Jun 2023 15:57:37 +0200 Subject: [PATCH] Updated Docker entrypoint script to split database setup from sync command - ref. #198 --- .gitlab-ci.yaml | 4 +++- README.md | 10 +++++++--- docker/docker_entrypoint.sh | 21 +++++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index 7f0e3ea41..5f60fa52f 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -269,6 +269,9 @@ sync_e2e_benchmark: ci/wait-for-postgres.sh ${HAF_ADMIN_POSTGRES_URL} && \ cd ${WORKING_DIR} && \ cat ${WORKING_DIR}/.hivemind-venv/lib/python3.8/site-packages/hive/_version.py > version.log && \ + /home/hivemind/docker_entrypoint.sh setup \ + --database-admin-url="${HAF_ADMIN_POSTGRES_URL}" \ + --add-mocks=${ADD_MOCKS} && \ ${WORKING_DIR}/docker_entrypoint.sh sync \ --log-mask-sensitive-data \ --pid-file hive_sync.pid \ @@ -276,7 +279,6 @@ sync_e2e_benchmark: --test-profile=False \ --prometheus-port 11011 \ --database-url="${HAF_POSTGRES_URL}" \ - --database-admin-url="${HAF_ADMIN_POSTGRES_URL}" \ --community-start-block 4998000 && \ ${WORKING_DIR}/app/ci/collect-db-stats.sh && \ python -m http.server ${RUNNER_HIVEMIND_SERVER_HTTP_PORT} diff --git a/README.md b/README.md index 3c47c1f9b..0d4140984 100644 --- a/README.md +++ b/README.md @@ -185,14 +185,18 @@ Entering application main loop... #### Running Hivemind instance container -The built Hivemind instance requires a preconfigured HAF database to store its data. The required database configuration will be performed automatically by the container before the `hive sync` command is run: +The built Hivemind instance requires a preconfigured HAF database to store its data. You can perform them with `setup` command before starting the sync. The commands below assume that the running HAF container has IP: 172.17.0.2 ```bash -../hivemind/scripts/run_instance.sh registry.gitlab.syncad.com/hive/hivemind/instance:local sync \ - --database-url="postgresql://haf_app_admin@172.17.0.2:5432/haf_block_log" \ +# Set-up Database +../hivemind/scripts/run_instance.sh registry.gitlab.syncad.com/hive/hivemind/instance:local setup \ --database-admin-url="postgresql://haf_admin@172.17.0.2/haf_block_log" # haf_admin access URL + +# Run the sync +../hivemind/scripts/run_instance.sh registry.gitlab.syncad.com/hive/hivemind/instance:local sync \ + --database-url="postgresql://haf_app_admin@172.17.0.2:5432/haf_block_log" ``` ## Updating from an existing hivemind database diff --git a/docker/docker_entrypoint.sh b/docker/docker_entrypoint.sh index df0023a64..d06eef49d 100755 --- a/docker/docker_entrypoint.sh +++ b/docker/docker_entrypoint.sh @@ -27,8 +27,14 @@ while [ $# -gt 0 ]; do --database-admin-url=*) POSTGRES_ADMIN_URL="${1#*=}" ;; + --add-mocks=*) + ADD_MOCKS="${1#*=}" + ;; + --add-mocks) + ADD_MOCKS=true + ;; *) - HIVEMIND_ARGS+=("$1") + HIVEMIND_ARGS+=("$1") esac shift done @@ -48,24 +54,23 @@ run_hive() { fi } -sync() { - log "sync" "Setting up the database before sync..." +setup() { + log "setup" "Setting up the database..." cd /home/hivemind/app - ./setup_postgres.sh --postgres-url="${POSTGRES_URL}" + ./setup_postgres.sh --postgres-url="${POSTGRES_ADMIN_URL}" ./setup_db.sh --postgres-url="${POSTGRES_ADMIN_URL}" if [[ "$ADD_MOCKS" == "true" ]]; then - log "sync" "Adding mocks to database..." + log "setup" "Adding mocks to database..." # shellcheck source=/dev/null source /home/hivemind/.hivemind-venv/bin/activate ci/add-mocks-to-db.sh --postgres-url="${POSTGRES_ADMIN_URL}" deactivate fi - run_hive } case "$COMMAND" in - sync) - sync + setup) + setup ;; *) run_hive -- GitLab