Skip to content

Commit

Permalink
docker: option to override topology file and peer address. (#5209)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqizng committed Mar 29, 2023
1 parent 9a0f374 commit 7738691
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 16 deletions.
22 changes: 11 additions & 11 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
51 changes: 51 additions & 0 deletions docker/files/run/followermode_template.json
Original file line number Diff line number Diff line change
@@ -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\"}"
}
]
}
21 changes: 16 additions & 5 deletions docker/files/run/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7738691

Please sign in to comment.