From 773869194d2d5847a127ddbe48e217a9e6993538 Mon Sep 17 00:00:00 2001 From: shiqizng <80276844+shiqizng@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:01:17 -0400 Subject: [PATCH] docker: option to override topology file and peer address. (#5209) --- docker/README.md | 22 ++++----- docker/files/run/followermode_template.json | 51 +++++++++++++++++++++ docker/files/run/run.sh | 21 +++++++-- 3 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 docker/files/run/followermode_template.json diff --git a/docker/README.md b/docker/README.md index 5db6b20a1d..0ea18b0c55 100644 --- a/docker/README.md +++ b/docker/README.md @@ -22,15 +22,16 @@ The following environment variables can be supplied. Except when noted, it is po | Variable | Description | | -------- | ----------- | -| NETWORK | Leave blank for a private network, otherwise specify one of mainnet, betanet, testnet, or devnet. Only used during a data directory initialization. | -| FAST_CATCHUP | If set to 1 on a public network, attempt to start fast-catchup during initial config. | -| TELEMETRY_NAME| If set on a public network, telemetry is reported with this name. | -| DEV_MODE | If set to 1 on a private network, enable dev mode. Only used during data directory initialization. | -| NUM_ROUNDS | If set on a private network, override default of 30000 participation keys. | -| TOKEN | If set, overrides the REST API token. | -| ADMIN_TOKEN | If set, overrides the REST API admin token. | -| KMD_TOKEN | If set along with `START_KMD`, override the KMD REST API token. | -| START_KMD | When set to 1, start kmd service with no timeout. THIS SHOULD NOT BE USED IN PRODUCTION. | +| NETWORK | Leave blank for a private network, otherwise specify one of mainnet, betanet, testnet, or devnet. Only used during a data directory initialization. | +| FAST_CATCHUP | If set to 1 on a public network, attempt to start fast-catchup during initial config. | +| TELEMETRY_NAME | If set on a public network, telemetry is reported with this name. | +| DEV_MODE | If set to 1 on a private network, enable dev mode. Only used during data directory initialization. | +| NUM_ROUNDS | If set on a private network, override default of 30000 participation keys. | +| TOKEN | If set, overrides the REST API token. | +| ADMIN_TOKEN | If set, overrides the REST API admin token. | +| KMD_TOKEN | If set along with `START_KMD`, override the KMD REST API token. | +| START_KMD | When set to 1, start kmd service with no timeout. THIS SHOULD NOT BE USED IN PRODUCTION. | +| PEER_ADDRESS | If set, override phonebook with peer ip:port (or semicolon separated list: ip:port;ip:port;ip:port...) | ### Special Files @@ -42,8 +43,7 @@ Configuration can be modified by specifying certain files. These can be changed | /etc/algorand/algod.token | Override default randomized REST API token. | | /etc/algorand/algod.admin.token | Override default randomized REST API admin token. | | /etc/algorand/logging.config | Use a custom [logging.config](https://developer.algorand.org/docs/run-a-node/reference/telemetry-config/#configuration) file for configuring telemetry. | - -TODO: `/etc/algorand/template.json` for overriding the private network topology. + | /etc/algorand/template.json | Override default private network topology. One of the nodes in the template must be named "data".| ## Example Configuration diff --git a/docker/files/run/followermode_template.json b/docker/files/run/followermode_template.json new file mode 100644 index 0000000000..ed074587e7 --- /dev/null +++ b/docker/files/run/followermode_template.json @@ -0,0 +1,51 @@ +{ + "Genesis": { + "ConsensusProtocol": "future", + "NetworkName": "followermodenet", + "FirstPartKeyRound": 0, + "LastPartKeyRound": NUM_ROUNDS, + "Wallets": [ + { + "Name": "Wallet1", + "Stake": 40, + "Online": true + }, + { + "Name": "Wallet2", + "Stake": 40, + "Online": true + }, + { + "Name": "Wallet3", + "Stake": 20, + "Online": true + } + ], + "DevMode": true + }, + "Nodes": [ + { + "Name": "data", + "IsRelay": true, + "Wallets": [ + { + "Name": "Wallet1", + "ParticipationOnly": false + }, + { + "Name": "Wallet2", + "ParticipationOnly": false + }, + { + "Name": "Wallet3", + "ParticipationOnly": false + } + ] + }, + { + "Name": "follower", + "IsRelay": false, + "ConfigJSONOverride": "{\"EnableFollowMode\":true,\"EndpointAddress\":\"0.0.0.0:8081\"}" + } + ] +} diff --git a/docker/files/run/run.sh b/docker/files/run/run.sh index bd4e79fe04..f9caa98818 100755 --- a/docker/files/run/run.sh +++ b/docker/files/run/run.sh @@ -35,8 +35,13 @@ function start_public_network() { catchup & fi - # redirect output to stdout - algod -o + if [ "$PEER_ADDRESS" != "" ]; then + printf "$PEER_ADDRESS" + algod -o -p $PEER_ADDRESS + else + # redirect output to stdout + algod -o + fi } function configure_data_dir() { @@ -59,7 +64,9 @@ function configure_data_dir() { # check for token overrides if [ "$TOKEN" != "" ]; then - echo "$TOKEN" >algod.token + for dir in ${ALGORAND_DATA}/../*/; do + echo "$TOKEN" > "$dir/algod.token" + done fi if [ "$ADMIN_TOKEN" != "" ]; then echo "$ADMIN_TOKEN" >algod.admin.token @@ -142,8 +149,12 @@ function start_private_network() { function start_new_private_network() { local TEMPLATE="template.json" - if [ "$DEV_MODE" = "1" ]; then - TEMPLATE="devmode_template.json" + if [ -f "/etc/algorand/template.json" ]; then + cp /etc/algorand/template.json "/node/run/$TEMPLATE" + else + if [ "$DEV_MODE" = "1" ]; then + TEMPLATE="devmode_template.json" + fi fi sed -i "s/NUM_ROUNDS/${NUM_ROUNDS:-30000}/" "/node/run/$TEMPLATE" goal network create --noclean -n dockernet -r "${ALGORAND_DATA}/.." -t "/node/run/$TEMPLATE"