Skip to content

Commit

Permalink
feat: allow to configure external data dir in run-node entrypoint (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
daeMOn63 authored Mar 30, 2022
1 parent 6d1a433 commit adf5d3e
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions entrypoints/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,38 @@ then
echo "Sleeping for 24 hours"
sleep 86400
else
VALIDATOR_STATE_FILE="/root/.fetchd/data/priv_validator_state.json"
VALIDATOR_STATE_DIR="/root/.fetchd/data"
NODE_HOME="/root/.fetchd"
VALIDATOR_STATE_FILE="${NODE_HOME}/data/priv_validator_state.json"
VALIDATOR_STATE_DIR="${NODE_HOME}/data"
WASM_STATE_DIR="${NODE_HOME}/wasm"

# when EXTERNAL_DATA_DIR is provided, it will replace default state directories
# by symlinks, effectively moving their effective location to EXTERNAL_DATA_DIR.
if [ -d "${EXTERNAL_DATA_DIR}" ]; then
mkdir -p ${EXTERNAL_DATA_DIR}/{data,wasm}
test -L ${VALIDATOR_STATE_DIR} || ln -s "${EXTERNAL_DATA_DIR}/data/" "${VALIDATOR_STATE_DIR}"
test -L ${WASM_STATE_DIR} || ln -s "${EXTERNAL_DATA_DIR}/wasm/" "${WASM_STATE_DIR}"
fi

# Copy readonly values from configmap dir to /root/.fetchd/config
if [ ! -d "/root/.fetchd/config" ]; then
mkdir -p "/root/.fetchd/config"
# Copy readonly values from configmap dir to ${NODE_HOME}/config
if [ ! -d "${NODE_HOME}/config" ]; then
mkdir -p "${NODE_HOME}/config"
fi
cp /root/wasm-temp-config/* /root/.fetchd/config/
cp /root/secret-temp-config/* /root/.fetchd/config/
chmod 644 /root/.fetchd/config/*

cp /root/wasm-temp-config/* ${NODE_HOME}/config/ || true
cp /root/secret-temp-config/* ${NODE_HOME}/config/ || true

# Set the correct moniker in the config.toml
sed -i "s/tempmoniker/$MONIKER/g" ~/.fetchd/config/config.toml
sed -i "s/tempexternal/$P2PADDRESS/g" ~/.fetchd/config/config.toml
sed -i "s/tempmoniker/$MONIKER/g" ${NODE_HOME}/config/config.toml
sed -i "s/tempexternal/$P2PADDRESS/g" ${NODE_HOME}/config/config.toml

# Genesis usually comes from /root/wasm-temp-config/genesis.json, which is populated from a configmap
# Some genesis might not fit there (when over 1MB), so as an alternative, OVERWRITE_GENESIS_URL environment
# can be specified to pull the genesis from the URL it contains.
if [ -n "${OVERWRITE_GENESIS_URL}" ];
then
echo "Overwritting genesis.json from ${OVERWRITE_GENESIS_URL}"
curl -o ~/.fetchd/config/genesis.json "${OVERWRITE_GENESIS_URL}"
curl -o ${NODE_HOME}/config/genesis.json "${OVERWRITE_GENESIS_URL}"
if [ $? -ne 0 ]; then
echo "failed to download genesis.json"
exit 1
Expand All @@ -40,7 +50,7 @@ else
##
if [ ! -f "$VALIDATOR_STATE_FILE" ];
then
mkdir -p "$VALIDATOR_STATE_DIR"
mkdir -p "$VALIDATOR_STATE_DIR" || true
echo "$VALIDATOR_STATE_FILE not found"
echo "---"
echo "Creating priv_validator_state.json"
Expand All @@ -49,7 +59,6 @@ else
echo ' "round": 0,' >> "$VALIDATOR_STATE_FILE"
echo ' "step": 0' >> "$VALIDATOR_STATE_FILE"
echo '}' >> "$VALIDATOR_STATE_FILE"
chmod 666 "$VALIDATOR_STATE_FILE"
fi

fetchd start
Expand Down

0 comments on commit adf5d3e

Please sign in to comment.