make exported environment variables unique from Bitcoin Node app

This commit is contained in:
nmfretz 2024-03-25 20:21:13 -07:00
parent 4f645fdefe
commit 0c4bbc58fc
2 changed files with 87 additions and 84 deletions

View File

@ -3,7 +3,7 @@ version: "3.7"
services:
app_proxy:
environment:
APP_HOST: $APP_BITCOIN_IP
APP_HOST: $APP_BITCOIN_KNOTS_IP
APP_PORT: 3005
server:
@ -15,43 +15,44 @@ services:
- ${APP_BITCOIN_DATA_DIR}:/bitcoin/.bitcoin # volume to persist umbrel-bitcoin.conf and bitcoin.conf
environment:
PORT: "3005"
BITCOIN_HOST: "${APP_BITCOIN_NODE_IP}"
RPC_PORT: "${APP_BITCOIN_INTERNAL_RPC_PORT}"
BITCOIN_RPC_PORT: "${APP_BITCOIN_INTERNAL_RPC_PORT}"
RPC_USER: "${APP_BITCOIN_RPC_USER}"
BITCOIN_RPC_USER: "${APP_BITCOIN_RPC_USER}"
RPC_PASSWORD: "${APP_BITCOIN_RPC_PASS}"
BITCOIN_RPC_PASSWORD: "${APP_BITCOIN_RPC_PASS}"
BITCOIN_RPC_HIDDEN_SERVICE: "${APP_BITCOIN_RPC_HIDDEN_SERVICE}"
BITCOIN_P2P_HIDDEN_SERVICE: "${APP_BITCOIN_P2P_HIDDEN_SERVICE}"
BITCOIN_P2P_PORT: "${APP_BITCOIN_P2P_PORT}"
BITCOIN_HOST: "${APP_BITCOIN_KNOTS_NODE_IP}"
RPC_PORT: "${APP_BITCOIN_KNOTS_INTERNAL_RPC_PORT}"
BITCOIN_RPC_PORT: "${APP_BITCOIN_KNOTS_INTERNAL_RPC_PORT}"
RPC_USER: "${APP_BITCOIN_KNOTS_RPC_USER}"
BITCOIN_RPC_USER: "${APP_BITCOIN_KNOTS_RPC_USER}"
RPC_PASSWORD: "${APP_BITCOIN_KNOTS_RPC_PASS}"
BITCOIN_RPC_PASSWORD: "${APP_BITCOIN_KNOTS_RPC_PASS}"
BITCOIN_RPC_HIDDEN_SERVICE: "${APP_BITCOIN_KNOTS_RPC_HIDDEN_SERVICE}"
BITCOIN_P2P_HIDDEN_SERVICE: "${APP_BITCOIN_KNOTS_P2P_HIDDEN_SERVICE}"
BITCOIN_P2P_PORT: "${APP_BITCOIN_KNOTS_P2P_PORT}"
DEVICE_DOMAIN_NAME: "${DEVICE_DOMAIN_NAME}"
BITCOIN_DEFAULT_NETWORK: "${BITCOIN_DEFAULT_NETWORK:-mainnet}"
BITCOIN_DEFAULT_NETWORK: "${BITCOIN_KNOTS_DEFAULT_NETWORK:-mainnet}"
# not needed
BITCOIN_INITIALIZE_WITH_CLEARNET_OVER_TOR: "${BITCOIN_INITIALIZE_WITH_CLEARNET_OVER_TOR:-unset}"
BITCOIND_IP: "${APP_BITCOIN_NODE_IP}"
TOR_PROXY_IP: "${APP_BITCOIN_TOR_PROXY_IP}"
BITCOIND_IP: "${APP_BITCOIN_KNOTS_NODE_IP}"
TOR_PROXY_IP: "${APP_BITCOIN_KNOTS_TOR_PROXY_IP}"
TOR_PROXY_PORT: "9050"
TOR_PROXY_CONTROL_PORT: "9051"
TOR_PROXY_CONTROL_PASSWORD: "moneyprintergobrrr"
I2P_DAEMON_IP: "${APP_BITCOIN_I2P_DAEMON_IP}"
I2P_DAEMON_IP: "${APP_BITCOIN_KNOTS_I2P_DAEMON_IP}"
I2P_DAEMON_PORT: "7656"
networks:
default:
ipv4_address: $APP_BITCOIN_IP
ipv4_address: $APP_BITCOIN_KNOTS_IP
bitcoind:
image: retropexx/bitcoind:v25.1@sha256:4091eb570744d24f4234a0efc6d8b6aaf7de1c86d1a6e3077525d59bbd98336e
command: "${APP_BITCOIN_COMMAND}"
command: "${APP_BITCOIN_KNOTS_COMMAND}"
restart: unless-stopped
stop_grace_period: 15m30s
volumes:
- "${APP_BITCOIN_DATA_DIR}:/data/.bitcoin"
ports:
- "${APP_BITCOIN_P2P_PORT}:${APP_BITCOIN_INTERNAL_P2P_PORT}"
- "${APP_BITCOIN_RPC_PORT}:${APP_BITCOIN_INTERNAL_RPC_PORT}"
- "${APP_BITCOIN_KNOTS_P2P_PORT}:${APP_BITCOIN_KNOTS_INTERNAL_P2P_PORT}"
- "${APP_BITCOIN_KNOTS_RPC_PORT}:${APP_BITCOIN_KNOTS_INTERNAL_RPC_PORT}"
networks:
default:
ipv4_address: $APP_BITCOIN_NODE_IP
ipv4_address: $APP_BITCOIN_KNOTS_NODE_IP
tor:
image: getumbrel/tor:0.4.7.8@sha256:2ace83f22501f58857fa9b403009f595137fa2e7986c4fda79d82a8119072b6a
@ -64,7 +65,7 @@ services:
HOME: "/tmp"
networks:
default:
ipv4_address: "${APP_BITCOIN_TOR_PROXY_IP}"
ipv4_address: "${APP_BITCOIN_KNOTS_TOR_PROXY_IP}"
i2pd_daemon:
image: purplei2p/i2pd:release-2.44.0@sha256:d154a599793c393cf9c91f8549ba7ece0bb40e5728e1813aa6dd4c210aa606f6
@ -75,4 +76,4 @@ services:
- ${APP_DATA_DIR}/data/i2pd:/home/i2pd/data
networks:
default:
ipv4_address: "${APP_BITCOIN_I2P_DAEMON_IP}"
ipv4_address: "${APP_BITCOIN_KNOTS_I2P_DAEMON_IP}"

View File

@ -1,19 +1,19 @@
export APP_BITCOIN_IP="10.21.22.5"
export APP_BITCOIN_NODE_IP="10.21.21.7"
export APP_BITCOIN_TOR_PROXY_IP="10.21.22.12"
export APP_BITCOIN_I2P_DAEMON_IP="10.21.22.13"
export APP_BITCOIN_KNOTS_IP="10.21.22.5"
export APP_BITCOIN_KNOTS_NODE_IP="10.21.21.7"
export APP_BITCOIN_KNOTS_TOR_PROXY_IP="10.21.22.12"
export APP_BITCOIN_KNOTS_I2P_DAEMON_IP="10.21.22.13"
export APP_BITCOIN_DATA_DIR="${EXPORTS_APP_DIR}/data/bitcoin"
export APP_BITCOIN_RPC_PORT="9332"
export APP_BITCOIN_P2P_PORT="9333"
export APP_BITCOIN_TOR_PORT="9334"
export APP_BITCOIN_ZMQ_RAWBLOCK_PORT="48332"
export APP_BITCOIN_ZMQ_RAWTX_PORT="48333"
export APP_BITCOIN_ZMQ_HASHBLOCK_PORT="48334"
export APP_BITCOIN_ZMQ_SEQUENCE_PORT="48335"
export APP_BITCOIN_INTERNAL_RPC_PORT="8332"
export APP_BITCOIN_INTERNAL_P2P_PORT="8333"
export APP_BITCOIN_INTERNAL_tor_PORT="8334"
export APP_BITCOIN_KNOTS_DATA_DIR="${EXPORTS_APP_DIR}/data/bitcoin"
export APP_BITCOIN_KNOTS_RPC_PORT="9332"
export APP_BITCOIN_KNOTS_P2P_PORT="9333"
export APP_BITCOIN_KNOTS_TOR_PORT="9334"
export APP_BITCOIN_KNOTS_ZMQ_RAWBLOCK_PORT="48332"
export APP_BITCOIN_KNOTS_ZMQ_RAWTX_PORT="48333"
export APP_BITCOIN_KNOTS_ZMQ_HASHBLOCK_PORT="48334"
export APP_BITCOIN_KNOTS_ZMQ_SEQUENCE_PORT="48335"
export APP_BITCOIN_KNOTS_INTERNAL_RPC_PORT="8332"
export APP_BITCOIN_KNOTS_INTERNAL_P2P_PORT="8333"
export APP_BITCOIN_KNOTS_INTERNAL_tor_PORT="8334"
BITCOIN_CHAIN="main"
BITCOIN_ENV_FILE="${EXPORTS_APP_DIR}/.env"
@ -48,10 +48,10 @@ if [[ ! -f "${BITCOIN_ENV_FILE}" ]]; then
BITCOIN_RPC_AUTH=$(echo "$BITCOIN_RPC_DETAILS" | head -2 | tail -1 | sed -e "s/^rpcauth=//")
fi
echo "export APP_BITCOIN_NETWORK='${BITCOIN_NETWORK}'" > "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_RPC_USER='${BITCOIN_RPC_USER}'" >> "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_RPC_PASS='${BITCOIN_RPC_PASS}'" >> "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_RPC_AUTH='${BITCOIN_RPC_AUTH}'" >> "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_KNOTS_NETWORK='${BITCOIN_NETWORK}'" > "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_KNOTS_RPC_USER='${BITCOIN_RPC_USER}'" >> "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_KNOTS_RPC_PASS='${BITCOIN_RPC_PASS}'" >> "${BITCOIN_ENV_FILE}"
echo "export APP_BITCOIN_KNOTS_RPC_AUTH='${BITCOIN_RPC_AUTH}'" >> "${BITCOIN_ENV_FILE}"
fi
. "${BITCOIN_ENV_FILE}"
@ -59,34 +59,34 @@ fi
# Make sure we don't persist the original value in .env if we have a more recent
# value from the app config
{
if [[ ! -z ${BITCOIN_NETWORK+x} ]] && [[ "${BITCOIN_NETWORK}" ]] && [[ "${APP_BITCOIN_NETWORK}" ]]
if [[ ! -z ${BITCOIN_NETWORK+x} ]] && [[ "${BITCOIN_NETWORK}" ]] && [[ "${APP_BITCOIN_KNOTS_NETWORK}" ]]
then
APP_BITCOIN_NETWORK="${BITCOIN_NETWORK}"
APP_BITCOIN_KNOTS_NETWORK="${BITCOIN_NETWORK}"
fi
} > /dev/null || true
if [[ "${APP_BITCOIN_NETWORK}" == "mainnet" ]]; then
if [[ "${APP_BITCOIN_KNOTS_NETWORK}" == "mainnet" ]]; then
BITCOIN_CHAIN="main"
elif [[ "${APP_BITCOIN_NETWORK}" == "testnet" ]]; then
elif [[ "${APP_BITCOIN_KNOTS_NETWORK}" == "testnet" ]]; then
BITCOIN_CHAIN="test"
# export APP_BITCOIN_RPC_PORT="18332"
# export APP_BITCOIN_P2P_PORT="18333"
# export APP_BITCOIN_TOR_PORT="18334"
elif [[ "${APP_BITCOIN_NETWORK}" == "signet" ]]; then
elif [[ "${APP_BITCOIN_KNOTS_NETWORK}" == "signet" ]]; then
BITCOIN_CHAIN="signet"
# export APP_BITCOIN_RPC_PORT="38332"
# export APP_BITCOIN_P2P_PORT="38333"
# export APP_BITCOIN_TOR_PORT="38334"
elif [[ "${APP_BITCOIN_NETWORK}" == "regtest" ]]; then
elif [[ "${APP_BITCOIN_KNOTS_NETWORK}" == "regtest" ]]; then
BITCOIN_CHAIN="regtest"
# export APP_BITCOIN_RPC_PORT="18443"
# export APP_BITCOIN_P2P_PORT="18444"
# export APP_BITCOIN_TOR_PORT="18445"
else
echo "Warning (${EXPORTS_APP_ID}): Bitcoin Network '${APP_BITCOIN_NETWORK}' is not supported"
echo "Warning (${EXPORTS_APP_ID}): Bitcoin Network '${APP_BITCOIN_KNOTS_NETWORK}' is not supported"
fi
export BITCOIN_DEFAULT_NETWORK="${BITCOIN_CHAIN}"
export BITCOIN_KNOTS_DEFAULT_NETWORK="${BITCOIN_CHAIN}"
BIN_ARGS=()
# Commenting out options that are replaced by generated config file. We should migrate all these over in a future update.
@ -99,58 +99,60 @@ BIN_ARGS=()
# BIN_ARGS+=( "-rpcport=${APP_BITCOIN_RPC_PORT}" )
BIN_ARGS+=( "-port=8333" )
BIN_ARGS+=( "-rpcport=8332" )
BIN_ARGS+=( "-rpcbind=${APP_BITCOIN_NODE_IP}" )
BIN_ARGS+=( "-rpcbind=${APP_BITCOIN_KNOTS_NODE_IP}" )
BIN_ARGS+=( "-rpcbind=127.0.0.1" )
BIN_ARGS+=( "-rpcallowip=${NETWORK_IP}/16" )
BIN_ARGS+=( "-rpcallowip=127.0.0.1" )
BIN_ARGS+=( "-rpcauth=\"${APP_BITCOIN_RPC_AUTH}\"" )
BIN_ARGS+=( "-zmqpubrawblock=tcp://0.0.0.0:${APP_BITCOIN_ZMQ_RAWBLOCK_PORT}" )
BIN_ARGS+=( "-zmqpubrawtx=tcp://0.0.0.0:${APP_BITCOIN_ZMQ_RAWTX_PORT}" )
BIN_ARGS+=( "-zmqpubhashblock=tcp://0.0.0.0:${APP_BITCOIN_ZMQ_HASHBLOCK_PORT}" )
BIN_ARGS+=( "-zmqpubsequence=tcp://0.0.0.0:${APP_BITCOIN_ZMQ_SEQUENCE_PORT}" )
BIN_ARGS+=( "-rpcauth=\"${APP_BITCOIN_KNOTS_RPC_AUTH}\"" )
BIN_ARGS+=( "-zmqpubrawblock=tcp://0.0.0.0:${APP_BITCOIN_KNOTS_ZMQ_RAWBLOCK_PORT}" )
BIN_ARGS+=( "-zmqpubrawtx=tcp://0.0.0.0:${APP_BITCOIN_KNOTS_ZMQ_RAWTX_PORT}" )
BIN_ARGS+=( "-zmqpubhashblock=tcp://0.0.0.0:${APP_BITCOIN_KNOTS_ZMQ_HASHBLOCK_PORT}" )
BIN_ARGS+=( "-zmqpubsequence=tcp://0.0.0.0:${APP_BITCOIN_KNOTS_ZMQ_SEQUENCE_PORT}" )
# BIN_ARGS+=( "-txindex=1" )
# BIN_ARGS+=( "-blockfilterindex=1" )
# BIN_ARGS+=( "-peerbloomfilters=1" )
# BIN_ARGS+=( "-peerblockfilters=1" )
# BIN_ARGS+=( "-rpcworkqueue=128" )
export APP_BITCOIN_COMMAND=$(IFS=" "; echo "${BIN_ARGS[@]}")
export APP_BITCOIN_KNOTS_COMMAND=$(IFS=" "; echo "${BIN_ARGS[@]}")
# echo "${APP_BITCOIN_COMMAND}"
# echo "${APP_BITCOIN_KNOTS_COMMAND}"
rpc_hidden_service_file="${EXPORTS_TOR_DATA_DIR}/app-${EXPORTS_APP_ID}-rpc/hostname"
p2p_hidden_service_file="${EXPORTS_TOR_DATA_DIR}/app-${EXPORTS_APP_ID}-p2p/hostname"
export APP_BITCOIN_RPC_HIDDEN_SERVICE="$(cat "${rpc_hidden_service_file}" 2>/dev/null || echo "notyetset.onion")"
export APP_BITCOIN_P2P_HIDDEN_SERVICE="$(cat "${p2p_hidden_service_file}" 2>/dev/null || echo "notyetset.onion")"
export APP_BITCOIN_KNOTS_RPC_HIDDEN_SERVICE="$(cat "${rpc_hidden_service_file}" 2>/dev/null || echo "notyetset.onion")"
export APP_BITCOIN_KNOTS_P2P_HIDDEN_SERVICE="$(cat "${p2p_hidden_service_file}" 2>/dev/null || echo "notyetset.onion")"
# electrs compatible network param
export APP_BITCOIN_NETWORK_ELECTRS=$APP_BITCOIN_NETWORK
if [[ "${APP_BITCOIN_NETWORK_ELECTRS}" = "mainnet" ]]; then
APP_BITCOIN_NETWORK_ELECTRS="bitcoin"
export APP_BITCOIN_KNOTS_NETWORK_ELECTRS=$APP_BITCOIN_KNOTS_NETWORK
if [[ "${APP_BITCOIN_KNOTS_NETWORK_ELECTRS}" = "mainnet" ]]; then
APP_BITCOIN_KNOTS_NETWORK_ELECTRS="bitcoin"
fi
{
# Migrate settings for app updates differently to fresh installs
BITCOIN_DATA_DIR="${EXPORTS_APP_DIR}/data/bitcoin"
IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH="${EXPORTS_APP_DIR}/data/app/IS_POST_ADVANCED_SETTINGS_INSTALL"
# We do not need this legacy bitcoin app logic because the Bitcoin Knots app was forked after advanced settings were introduced
# If no blocks directory exists, we write out a file to indicate that this is a fresh install.
# This gets around the issue of the pre-start hook starting up the bitcoind container early for Tor HS creation
# and creating the blocks directory.
if [[ ! -d "${BITCOIN_DATA_DIR}/blocks" ]] && [[ ! -d "${BITCOIN_DATA_DIR}/testnet3/blocks" ]] && [[ ! -d "${BITCOIN_DATA_DIR}/regtest/blocks" ]]
then
touch "${IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH}"
fi
# {
# # Migrate settings for app updates differently to fresh installs
# BITCOIN_DATA_DIR="${EXPORTS_APP_DIR}/data/bitcoin"
# IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH="${EXPORTS_APP_DIR}/data/app/IS_POST_ADVANCED_SETTINGS_INSTALL"
APP_CONFIG_EXISTS="false"
if [[ -f "${EXPORTS_APP_DIR}/data/app/bitcoin-config.json" ]]
then
APP_CONFIG_EXISTS="true"
fi
# # If no blocks directory exists, we write out a file to indicate that this is a fresh install.
# # This gets around the issue of the pre-start hook starting up the bitcoind container early for Tor HS creation
# # and creating the blocks directory.
# if [[ ! -d "${BITCOIN_DATA_DIR}/blocks" ]] && [[ ! -d "${BITCOIN_DATA_DIR}/testnet3/blocks" ]] && [[ ! -d "${BITCOIN_DATA_DIR}/regtest/blocks" ]]
# then
# touch "${IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH}"
# fi
if [[ ! -f "${IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH}" ]] && [[ "${APP_CONFIG_EXISTS}" = "false" ]]
then
# This app is not a fresh install, it's being updated, so preserve existing clearnet over Tor setting
export BITCOIN_INITIALIZE_WITH_CLEARNET_OVER_TOR="true"
fi
} || true
# APP_CONFIG_EXISTS="false"
# if [[ -f "${EXPORTS_APP_DIR}/data/app/bitcoin-config.json" ]]
# then
# APP_CONFIG_EXISTS="true"
# fi
# if [[ ! -f "${IS_POST_ADVANCED_SETTINGS_INSTALL_FILE_PATH}" ]] && [[ "${APP_CONFIG_EXISTS}" = "false" ]]
# then
# # This app is not a fresh install, it's being updated, so preserve existing clearnet over Tor setting
# export BITCOIN_INITIALIZE_WITH_CLEARNET_OVER_TOR="true"
# fi
# } || true