From f8c2c42359a745cff5370681b13d834b26c4fe6d Mon Sep 17 00:00:00 2001 From: jonathansumner Date: Wed, 17 May 2023 13:58:48 +0100 Subject: [PATCH] chore: add env checks --- scripts/genesis-entrypoint.sh | 21 +++++++++++++++++---- src/genesis/genesis.py | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/genesis-entrypoint.sh b/scripts/genesis-entrypoint.sh index 30c67c514..6a5e0e26c 100644 --- a/scripts/genesis-entrypoint.sh +++ b/scripts/genesis-entrypoint.sh @@ -1,6 +1,13 @@ #!/bin/bash set -e +echo "checking genesis processing requirements..." + +if [ -z "$DB_DATABASE" ] || [ -z "$DB_HOST" ] || [ -z "$DB_PASS" ] || [ -z "$DB_SCHEMA" ] || [ -z "$DB_USER" ] || [ -z "$DB_PORT" ]; then + echo "One or more database envs missing from: DB_HOST, DB_DATABASE, DB_PASS, DB_SCHEMA, DB_USER, DB_PORT" + exit 1 +fi + export PGPASSWORD=$DB_PASS genesisProcessed=$(psql -At -v ON_ERROR_STOP=1 \ -h $DB_HOST \ @@ -9,7 +16,7 @@ genesisProcessed=$(psql -At -v ON_ERROR_STOP=1 \ -d $DB_DATABASE \ -c "SELECT to_regclass('genesis_processing.genesisProcessed');") -if [ -n "$genesisProcessed" ]; then +if [ -n "$genesisProcessed" ] && [[ -z "$FORCE_PROCESS" || "$FORCE_PROCESS" == "false" ]]; then echo "genesis already processed" exit 1 fi @@ -19,6 +26,15 @@ if [ -z "$JSON_URL" ] || [ -z "${NETWORK}" ]; then exit 1 fi +pipenv run python /app/genesis.py \ + "${JSON_URL}" \ + --db-host="${DB_HOST}" \ + --db-name="${DB_DATABASE}" \ + --db-pass="${DB_PASS}" \ + --db-schema="${DB_SCHEMA}" \ + --db-user="${DB_USER}" \ + --db-port="${DB_PORT}" + export PGPASSWORD=$DB_PASS psql -At -v ON_ERROR_STOP=1 \ -h $DB_HOST \ @@ -33,6 +49,3 @@ CREATE TABLE IF NOT EXISTS genesis_processing.genesisProcessed ( INSERT INTO genesis_processing.genesisProcessed(network) VALUES ('${NETWORK}'); EOF - -pipenv run python /app/genesis.py "${JSON_URL}" - diff --git a/src/genesis/genesis.py b/src/genesis/genesis.py index bb17f9740..45f4d9d04 100644 --- a/src/genesis/genesis.py +++ b/src/genesis/genesis.py @@ -25,3 +25,4 @@ def process_genesis(db_conn: Connection, genesis_data: dict): print("contracts...") contracts_manager.process_genesis(genesis_data) print("done.") + print("processing complete.")