mirror of
https://github.com/anyproto/any-sync-dockercompose.git
synced 2025-06-08 05:47:03 +09:00
Fixed the generation of QUIC protocol listening addresses
This commit is contained in:
parent
98d528ffaf
commit
ed0520b39d
2 changed files with 53 additions and 17 deletions
|
@ -6,7 +6,7 @@ source .env
|
|||
|
||||
# Set file paths
|
||||
DEST_PATH="./etc"
|
||||
NETWORK_FILE="${DEST_PATH}/network.yml"
|
||||
NETWORK_FILE="./storage/docker-generateconfig/network.yml"
|
||||
|
||||
echo "INFO: Create directories for all node types"
|
||||
for NODE_TYPE in node-1 node-2 node-3 filenode coordinator consensusnode admin; do
|
||||
|
@ -17,14 +17,13 @@ echo "INFO: Create directory for aws credentials"
|
|||
mkdir -p "${DEST_PATH}/.aws"
|
||||
|
||||
echo "INFO: Configure external listen host"
|
||||
./docker-generateconfig/setListenIp.py "./storage/docker-generateconfig/nodes.yml" ${EXTERNAL_LISTEN_HOST} ${EXTERNAL_LISTEN_HOSTS}
|
||||
./docker-generateconfig/setListenIp.py "./storage/docker-generateconfig/nodes.yml" "./storage/docker-generateconfig/nodesProcessed.yml"
|
||||
|
||||
echo "INFO: Create config for clients"
|
||||
cp "./storage/docker-generateconfig/nodes.yml" "${DEST_PATH}/client.yml"
|
||||
cp "./storage/docker-generateconfig/nodesProcessed.yml" "${DEST_PATH}/client.yml"
|
||||
|
||||
echo "INFO: Generate network file"
|
||||
#sed 's|^| |; 1s|^|network:\n|' "generateconfig/nodes.yml" > "${NETWORK_FILE}"
|
||||
yq eval '. as $item | {"network": $item}' --indent 2 ./storage/docker-generateconfig/nodes.yml > "${NETWORK_FILE}"
|
||||
yq eval '. as $item | {"network": $item}' --indent 2 ./storage/docker-generateconfig/nodesProcessed.yml > "${NETWORK_FILE}"
|
||||
|
||||
echo "INFO: Generate config files for 3 nodes"
|
||||
for i in {0..2}; do
|
||||
|
@ -47,7 +46,7 @@ cat "${NETWORK_FILE}" docker-generateconfig/etc/common.yml storage/docker-genera
|
|||
> ${DEST_PATH}/any-sync-consensusnode/config.yml
|
||||
|
||||
echo "INFO: Copy network file to coordinator directory"
|
||||
cp "storage/docker-generateconfig/nodes.yml" "${DEST_PATH}/any-sync-coordinator/network.yml"
|
||||
cp "storage/docker-generateconfig/nodesProcessed.yml" "${DEST_PATH}/any-sync-coordinator/network.yml"
|
||||
|
||||
echo "INFO: Copy any-sync-admin config"
|
||||
cp "docker-generateconfig/etc/admin.yml" "${DEST_PATH}/any-sync-admin/config.yml"
|
||||
|
|
|
@ -1,23 +1,60 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import yaml
|
||||
import json
|
||||
|
||||
arguments = sys.argv[1:]
|
||||
yamlFile = arguments[0]
|
||||
listenHosts = arguments[1:]
|
||||
# load .env vars
|
||||
envVars = dict()
|
||||
if os.path.exists('.env') and os.path.getsize('.env') > 0:
|
||||
with open('.env') as file:
|
||||
for line in file:
|
||||
if line.startswith('#') or not line.strip():
|
||||
continue
|
||||
key, value = line.strip().split('=', 1)
|
||||
value = value.replace('"', '')
|
||||
if key in envVars:
|
||||
print(f"WARNING: dublicate key={key} in env file='.env'")
|
||||
envVars[key] = value
|
||||
else:
|
||||
print(f"ERROR: file='.env' not found or size=0")
|
||||
exit(1)
|
||||
|
||||
with open(yamlFile, 'r') as file:
|
||||
#print(f"DEBUG: envVars={json.dumps(envVars,indent=4)}")
|
||||
|
||||
inputYamlFile = sys.argv[1]
|
||||
outputYamlFile = sys.argv[2]
|
||||
listenHosts = envVars['EXTERNAL_LISTEN_HOSTS'].split()
|
||||
if 'EXTERNAL_LISTEN_HOST' in envVars:
|
||||
listenHosts.append(envVars['EXTERNAL_LISTEN_HOST'])
|
||||
|
||||
print(f"DEBUG: listenHosts={listenHosts}")
|
||||
|
||||
# read input yaml file
|
||||
with open(inputYamlFile, 'r') as file:
|
||||
config = yaml.load(file,Loader=yaml.Loader)
|
||||
|
||||
# processing addresses for nodes
|
||||
for index, nodes in enumerate(config['nodes']):
|
||||
addresses = nodes['addresses']
|
||||
port = addresses[0].split(':')[1]
|
||||
for listenHost in listenHosts:
|
||||
listenAddress = listenHost +':'+ port
|
||||
if listenAddress not in addresses:
|
||||
addresses.append(listenAddress)
|
||||
listenHost = nodes['addresses'][0].split(':')[0]
|
||||
listenPort = nodes['addresses'][0].split(':')[1]
|
||||
nodeListenHosts = [listenHost] + listenHosts
|
||||
for nodeListenHost in nodeListenHosts:
|
||||
listenAddress = nodeListenHost +':'+ str(listenPort)
|
||||
if listenAddress not in nodes['addresses']:
|
||||
nodes['addresses'].append(listenAddress)
|
||||
# add "quic" listen address
|
||||
for name,value in envVars.items():
|
||||
if re.match(r"^(ANY_SYNC_.*_PORT)$", name) and value == listenPort:
|
||||
quicPortKey = name.replace('_PORT', '_QUIC_PORT')
|
||||
quicPortValue = envVars[quicPortKey]
|
||||
quicListenAddress = 'quic://'+ nodeListenHost +':'+ str(quicPortValue)
|
||||
if ( quicPortValue ) and ( quicListenAddress not in nodes['addresses']):
|
||||
nodes['addresses'].append(quicListenAddress)
|
||||
|
||||
with open(yamlFile, 'w') as file:
|
||||
# write output yaml file
|
||||
with open(outputYamlFile, 'w') as file:
|
||||
yaml.dump(config, file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue