Skip to content

Commit

Permalink
[#2362] Add topology update functionality to Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Jun 8, 2021
1 parent 11a446f commit 40fc79a
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 20 deletions.
28 changes: 25 additions & 3 deletions nix/docker/README.md
Expand Up @@ -39,7 +39,8 @@ cardano-node run \
2. Run -e NETWORK=mainnet and check graceful shutdown SIGTERM with --detach
3. Run without -e NETWORK and check graceful shutdown SIGINT with -it
4. Run without -e NETWORK and check graceful shutdown SIGTERM with --detach
5. Check cardano-cli access
5. Run with -e CARDANO_UPDATE_TOPOLOGY and check cron job
6. Check cardano-cli access

### Run with NETWORK

Expand Down Expand Up @@ -92,10 +93,31 @@ docker run --detach \
docker logs -f relay
```

### Run with -e CARDANO_UPDATE_TOPOLOGY

```
docker rm -f relay
docker run --detach \
--name=relay \
-p 3001:3001 \
-e CARDANO_UPDATE_TOPOLOGY=true \
-e CARDANO_CUSTOM_PEERS="relay01.astorpool.net:3001" \
-v node-data:/opt/cardano/data \
-v node-ipc:/opt/cardano/ipc \
inputoutput/cardano-node:dev run
docker logs -f relay
docker exec relay cat /opt/cardano/logs/topologyUpdateResult
docker exec relay cat /var/cardano/config/mainnet-topology.json
```

### Check cardano-cli

```
docker run --rm -it \
alias cardano-cli="docker run --rm -it \
-v node-ipc:/opt/cardano/ipc \
inputoutput/cardano-node:dev cli query tip --mainnet
inputoutput/cardano-node:dev"
cardano-cli query tip --mainnet
```
141 changes: 124 additions & 17 deletions nix/docker/context/bin/run-node
Expand Up @@ -24,6 +24,10 @@ if [[ -z $CARDANO_SOCKET_PATH ]]; then
CARDANO_SOCKET_PATH="/opt/cardano/ipc/socket"
fi

if [[ -z $CARDANO_LOG_DIR ]]; then
CARDANO_LOG_DIR="/opt/cardano/logs"
fi

if [[ -z $CARDANO_BIND_ADDR ]]; then
CARDANO_BIND_ADDR="0.0.0.0"
fi
Expand All @@ -32,10 +36,30 @@ if [[ -z $CARDANO_PORT ]]; then
CARDANO_PORT=3001
fi

if [ -v $CARDANO_BLOCK_PRODUCER ]; then
if [[ -z $CARDANO_BLOCK_PRODUCER ]]; then
CARDANO_BLOCK_PRODUCER=false
fi

if [[ -z $CARDANO_UPDATE_TOPOLOGY ]]; then
CARDANO_UPDATE_TOPOLOGY=false
fi

if [[ -z $EKG_HOST ]]; then
EKG_HOST="127.0.0.1"
fi

if [[ -z $EKG_PORT ]]; then
EKG_PORT=12788
fi

if [[ -z $EKG_TIMEOUT ]]; then
EKG_TIMEOUT=3
fi

if [[ -z $MAX_PEERS ]]; then
MAX_PEERS=15
fi

#####################################################################
#
# Print run environment
Expand All @@ -46,21 +70,23 @@ printRunEnv () {
echo "CARDANO_BLOCK_PRODUCER=$CARDANO_BLOCK_PRODUCER"
echo "CARDANO_CONFIG=$CARDANO_CONFIG"
echo "CARDANO_DATABASE_PATH=$CARDANO_DATABASE_PATH"
echo "CARDANO_LOG_DIR=$CARDANO_LOG_DIR"
echo "CARDANO_PORT=$CARDANO_PORT"
echo "CARDANO_SOCKET_PATH=$CARDANO_SOCKET_PATH"
echo "CARDANO_TOPOLOGY=$CARDANO_TOPOLOGY"
echo "CARDANO_UPDATE_TOPOLOGY=$CARDANO_UPDATE_TOPOLOGY"

if [ "$CARDANO_BLOCK_PRODUCER" = true ]; then
if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then

if [ -v $CARDANO_SHELLEY_KES_KEY ]; then
if [[ -z ${CARDANO_SHELLEY_KES_KEY} ]]; then
CARDANO_SHELLEY_KES_KEY="$CARDANO_CONFIG_BASE/keys/kes.skey"
fi

if [ -v $CARDANO_SHELLEY_VRF_KEY ]; then
if [[ -z ${CARDANO_SHELLEY_VRF_KEY} ]]; then
CARDANO_SHELLEY_VRF_KEY="$CARDANO_CONFIG_BASE/keys/vrf.skey"
fi

if [ -v $CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE ]; then
if [[ -z ${CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE} ]]; then
CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE="$CARDANO_CONFIG_BASE/keys/node.cert"
fi

Expand All @@ -70,6 +96,89 @@ printRunEnv () {
fi
}

#####################################################################
#
# Write root env file
#
writeRootEnv () {

cat << EOF > /usr/local/bin/env
#!/usr/bin/env bash
# Docker run ENV vars
CARDANO_CONFIG="$CARDANO_CONFIG"
CARDANO_TOPOLOGY="$CARDANO_TOPOLOGY"
CARDANO_BIND_ADDR="$CARDANO_BIND_ADDR"
CARDANO_PORT=$CARDANO_PORT
CARDANO_DATABASE_PATH="$CARDANO_DATABASE_PATH"
CARDANO_SOCKET_PATH="$CARDANO_SOCKET_PATH"
CARDANO_LOG_DIR="$CARDANO_LOG_DIR"
CARDANO_PUBLIC_IP="$CARDANO_PUBLIC_IP"
CARDANO_CUSTOM_PEERS="$CARDANO_CUSTOM_PEERS"
CARDANO_UPDATE_TOPOLOGY=$CARDANO_UPDATE_TOPOLOGY
CARDANO_BLOCK_PRODUCER=$CARDANO_BLOCK_PRODUCER
# Mapping for topologyUpdater
CNODE_HOSTNAME="$CARDANO_PUBLIC_IP"
CNODE_PORT=$CARDANO_PORT
CUSTOM_PEERS="$CARDANO_CUSTOM_PEERS"
GENESIS_JSON="$CARDANO_CONFIG_BASE/mainnet-shelley-genesis.json"
TOPOLOGY="$CARDANO_TOPOLOGY"
LOG_DIR="$CARDANO_LOG_DIR"
EKG_HOST="$EKG_HOST"
EKG_PORT=$EKG_PORT
EKG_TIMEOUT=$EKG_TIMEOUT
MAX_PEERS=$MAX_PEERS
EOF
}

#####################################################################
#
# Run the relay node in the background
#
runRelayNode () {

if [[ $CARDANO_UPDATE_TOPOLOGY == true ]]; then
topologyUpdate -l &
fi

effopts=(--config $CARDANO_CONFIG \
--topology $CARDANO_TOPOLOGY \
--database-path $CARDANO_DATABASE_PATH \
--socket-path $CARDANO_SOCKET_PATH \
--host-addr $CARDANO_BIND_ADDR \
--port $CARDANO_PORT)

effopts+=(${options[@]})

echo "cardano-node run ${effopts[@]}"
exec /usr/local/bin/cardano-node run ${effopts[@]}
}

#####################################################################
#
# Run the block producer in the background
#
runBlockProducerNode () {

effopts=(--config $CARDANO_CONFIG \
--topology $CARDANO_TOPOLOGY \
--database-path $CARDANO_DATABASE_PATH \
--socket-path $CARDANO_SOCKET_PATH \
--host-addr $CARDANO_BIND_ADDR \
--port $CARDANO_PORT \
--shelley-kes-key $CARDANO_SHELLEY_KES_KEY \
--shelley-vrf-key $CARDANO_SHELLEY_VRF_KEY \
--shelley-operational-certificate $CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE)

effopts+=(${options[@]})

echo "cardano-node run ${effopts[@]}"
exec /usr/local/bin/cardano-node run ${effopts[@]}
}

# Shift the first option by one index
shift

Expand All @@ -93,6 +202,9 @@ do
--socket-path) CARDANO_SOCKET_PATH=${val}; found=true;;
--host-addr) CARDANO_BIND_ADDR=${val}; found=true;;
--port) CARDANO_PORT=${val}; found=true;;
--shelley-kes-key) CARDANO_SHELLEY_KES_KEY=${val}; found=true;;
--shelley-vrf-key) CARDANO_SHELLEY_VRF_KEY=${val}; found=true;;
--shelley-operational-certificate) CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=${val}; found=true;;
esac

if [[ $found == true ]]; then
Expand All @@ -102,18 +214,13 @@ do
done

printRunEnv

effopts=(--config $CARDANO_CONFIG \
--topology $CARDANO_TOPOLOGY \
--database-path $CARDANO_DATABASE_PATH \
--socket-path $CARDANO_SOCKET_PATH \
--host-addr $CARDANO_BIND_ADDR \
--port $CARDANO_PORT)

effopts+=(${options[@]})
writeRootEnv

# The IPC socket dir is not created on demand
mkdir -p `dirname $CARDANO_SOCKET_PATH`
mkdir -p `dirname ${CARDANO_SOCKET_PATH}`

echo "/usr/local/bin/cardano-node run ${effopts[@]}"
exec /usr/local/bin/cardano-node run ${effopts[@]}
if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
runBlockProducerNode
else
runRelayNode
fi

0 comments on commit 40fc79a

Please sign in to comment.