From 1bdff2b22e904b1f667abd1e8ba76b49302dcf47 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 4 Jun 2024 12:16:43 +0530 Subject: [PATCH] Setup config on startup and fix node initialization --- .../compose/docker-compose-bsc-node.yml | 7 ++++--- .../config/docker-entrypoint.sh | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/stack-orchestrator/compose/docker-compose-bsc-node.yml b/stack-orchestrator/compose/docker-compose-bsc-node.yml index be99ccf..a2a2938 100644 --- a/stack-orchestrator/compose/docker-compose-bsc-node.yml +++ b/stack-orchestrator/compose/docker-compose-bsc-node.yml @@ -2,12 +2,13 @@ services: bsc: image: ghcr.io/bnb-chain/bsc:1.4.8 restart: unless-stopped - environment: + # environment: volumes: - ../config/docker-entrypoint.sh:/bsc/docker-entrypoint.sh - data:/data - - config:/bsc/config + - bsc:/bsc ports: + - 30303:30303 - 30311:30311 - 8545:8545 - 8546:8546 @@ -20,4 +21,4 @@ services: volumes: data: - config: + bsc: diff --git a/stack-orchestrator/config/docker-entrypoint.sh b/stack-orchestrator/config/docker-entrypoint.sh index d27950f..2e7afb4 100755 --- a/stack-orchestrator/config/docker-entrypoint.sh +++ b/stack-orchestrator/config/docker-entrypoint.sh @@ -1,19 +1,28 @@ #!/bin/bash set -e -# TODO: Check for testnet flag -# TODO: Download and unzip the config files - BSC_CONFIG=${BSC_HOME}/config/config.toml BSC_GENESIS=${BSC_HOME}/config/genesis.json -# Init genesis state if geth not exist -DATA_DIR=$(cat ${BSC_CONFIG} | grep -A1 '\[Node\]' | grep -oP '\"\K.*?(?=\")') +# TODO: Check for testnet flag +if [ -f "$BSC_CONFIG" ]; then + echo "Config file found at $BSC_CONFIG" +else + echo "Config file not found at $BSC_CONFIG, downloading..." + + # Download and unzip the config files + wget -O config.zip $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4) + unzip config.zip -d config +fi + +# Init genesis state if geth sub dir does not exist GETH_DIR=${DATA_DIR}/geth if [ ! -d "$GETH_DIR" ]; then + echo Initializing geth... geth --datadir ${DATA_DIR} init ${BSC_GENESIS} + echo Initialization done fi # TODO: Check for archive mode flag -exec "geth" "--config" ${BSC_CONFIG} "$@" +exec "geth" "--config" ${BSC_CONFIG} "--datadir" ${DATA_DIR} "$@"