Skip to content

Commit

Permalink
fix builder
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Dec 11, 2024
1 parent 7a3bd01 commit 3a1d0b9
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
4 changes: 3 additions & 1 deletion wedpr-builder/wedpr_builder/common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class ConfigInfo:
wedpr_node_service_dir = "wedpr-pro-node-service"
wedpr_mpc_service_dir = "wedpr-mpc-service"
docker_file_list = ["create_docker.sh",
"start_docker.sh", "stop_docker.sh"]
"start_docker.sh",
"stop_docker.sh", "destroy_docker.sh"]
# the nginx config
nginx_tpl_path = get_abs_path("nginx/")
nginx_config_file_list = ["nginx.conf"]
Expand Down Expand Up @@ -169,3 +170,4 @@ class ConfigProperities:
EXTENDED_MOUNT_CONF = "EXTENDED_MOUNT_CONF"
# the nginx configuration
NGINX_BACKEND_SERVER_LIST = "NGINX_BACKEND_SERVER_LIST"
NGINX_PORT = "NGINX_PORT"
29 changes: 21 additions & 8 deletions wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def __init__(self, config, section_name: str):
self.config, section_name, "sequencer_contract_address", None, True)

def __repr__(self):

return f"**BlockchainConfig: blockchain_group: {self.blockchain_group}, " \
f"blockchain_peers: [{','.join(self.blockchain_peers)}], " \
f"blockchain_cert_path: {self.blockchain_cert_path}**\n"
Expand All @@ -170,9 +171,10 @@ def to_properties(self) -> {}:
constant.ConfigProperities.WEDPR_SEQUENCER_CONTRACT_ADDRESS:
self.sequencer_contract_address})
# the blockchain peers
blockchain_peers_info = ','.join(map(str, self.blockchain_peers))
quoted_peers = [f'"{peer}"' for peer in self.blockchain_peers]
blockchain_peers_info = ','.join(map(str, quoted_peers))
properties.update({constant.ConfigProperities.BLOCKCHAIN_PEERS:
f"[{blockchain_peers_info}]"})
f'[{blockchain_peers_info}]'})
return properties


Expand Down Expand Up @@ -387,18 +389,23 @@ def __repr__(self):
f"server_start_port: {self.server_start_port}," \
f"service_type: {self.service_type} \n**"

def to_nginx_properties(self):
def get_nginx_listen_port(self, node_index):
return self.server_start_port + 3 * node_index + 2

def to_nginx_properties(self, nginx_listen_port):
props = {}
nginx_backend_setting = ""
for backend in self.server_backend_list:
nginx_backend_setting = f"{nginx_backend_setting}{backend};\\n\\t"
props.update({constant.ConfigProperities.NGINX_BACKEND_SERVER_LIST:
nginx_backend_setting})
props.update(
{constant.ConfigProperities.NGINX_PORT: nginx_listen_port})
return props

def to_properties(self, deploy_ip, node_index: int) -> {}:
props = {}
server_start_port = self.server_start_port + 2 * node_index
server_start_port = self.server_start_port + 3 * node_index
self.server_backend_list.append(f"{deploy_ip}:{server_start_port}")
# nodeid
node_id = f"{self.service_type}-{self.env_config.zone}-node{node_index}"
Expand All @@ -417,16 +424,21 @@ def to_properties(self, deploy_ip, node_index: int) -> {}:
props.update(
{constant.ConfigProperities.WEDPR_SERVER_LISTEN_PORT: server_start_port})
# transport listen_port
transport_port = server_start_port + 1
props.update(
{constant.ConfigProperities.WEDPR_TRANSPORT_LISTEN_PORT: server_start_port + 1})
{constant.ConfigProperities.WEDPR_TRANSPORT_LISTEN_PORT: transport_port})
# set the image desc for docker mode
image_desc = self.env_config.get_image_desc_by_service_name(
self.service_type)
if image_desc is not None:
props.update(
{constant.ConfigProperities.WEDPR_IMAGE_DESC: image_desc})
# set the exposed port
exposed_port_list = f"-p {server_start_port}:{server_start_port} -p {server_start_port + 1}:{server_start_port + 1}"
exposed_port_list = f"-p {server_start_port}:{server_start_port} -p {transport_port}:{transport_port}"
# expose the nginx port
if self.service_type == constant.ServiceInfo.wedpr_site_service:
nginx_port = server_start_port + 2
exposed_port_list = f"{exposed_port_list} -p {nginx_port}:{nginx_port}"
# default expose 20 ports for jupyter use
# reserver 100 ports for jupyter use
jupyter_start_port = server_start_port + 100
Expand All @@ -443,7 +455,7 @@ def to_properties(self, deploy_ip, node_index: int) -> {}:
props.update(
{constant.ConfigProperities.WEDPR_DOCKER_EXPORSE_PORT_LIST: exposed_port_list})
# set the docker name
docker_name = f"{self.service_type}-{self.env_config.zone}-node{node_index}"
docker_name = f"{self.agency}-{self.service_type}-{self.env_config.zone}-node{node_index}"
props.update(
{constant.ConfigProperities.WEDPR_DOCKER_NAME: docker_name})
return props
Expand Down Expand Up @@ -848,6 +860,7 @@ def get_wedpr_model_properties(self, deploy_ip: str, node_index: int) -> {}:

@staticmethod
def generate_cpp_component_docker_properties(
agency_name: str,
prefix_path, zone_name: str, service_type: str, env_config,
exposed_port_list: str, node_index: int):
props = {}
Expand Down Expand Up @@ -884,7 +897,7 @@ def generate_cpp_component_docker_properties(
props.update(
{constant.ConfigProperities.WEDPR_DOCKER_EXPORSE_PORT_LIST: exposed_port_list})
# set the docker name
docker_name = f"{service_type}-{zone_name}-node{node_index}"
docker_name = f"{agency_name}-{service_type}-{zone_name}-node{node_index}"
props.update(
{constant.ConfigProperities.WEDPR_DOCKER_NAME: docker_name})
return props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __generate_docker_config__(
f"{constant.ConfigInfo.docker_tpl_path} to {node_path} "
f"failed, reason: {output}")
props = AgencyConfig.generate_cpp_component_docker_properties(
gateway_config.agency_name,
constant.ConfigInfo.wedpr_gateway_service_dir,
self.config.env_config.zone,
gateway_config.service_type, self.config.env_config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __generate_docker_config__(
f"{constant.ConfigInfo.docker_tpl_path} to {node_path} "
f"failed, reason: {output}")
props = AgencyConfig.generate_cpp_component_docker_properties(
node_config.agency_name,
constant.ConfigInfo.wedpr_node_service_dir,
self.config.env_config.zone,
node_config.service_type, self.config.env_config,
Expand Down
21 changes: 14 additions & 7 deletions wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __generate_service_config__(
f"{self.config.env_config.deploy_dir}, "
f"service_config: {service_config}")
node_path_list = []
nginx_listen_port = []
for ip_str in service_config.deploy_ip_list:
ip_array = ip_str.split(":")
ip = ip_array[0]
Expand All @@ -72,15 +73,20 @@ def __generate_service_config__(
agency_name=service_config.agency,
deploy_ip=ip, node_index=i)
node_path_list.append(node_path)
nginx_listen_port.append(
service_config.get_nginx_listen_port(i))
# generate the ip shell scripts
output_path = self.__get_deploy_path__(
agency_config.agency_name, ip, None, service_config.service_type)
self.__generate_docker_ip_shell_scripts__(output_path)
# generate the init scripts
self.generate_init_scripts(os.path.join(
output_path, "init"), agency_list, agency_config)
i = 0
for node_path in node_path_list:
self.generate_nginx_config(node_path, service_config)
self.generate_nginx_config(
node_path, service_config, nginx_listen_port[i])
i += 1
utilities.print_badge(f"* generate {service_config.service_type} config success, "
f"agency: {agency_config.agency_name}, deploy_dir: "
f"{self.config.env_config.deploy_dir}, "
Expand Down Expand Up @@ -274,15 +280,16 @@ def __generate_shell_scripts__(self, dist_path, dst_path):
def __copy_binary__(self, dist_path, dst_path):
self.__copy_java_binary__(dist_path, dst_path)

def generate_nginx_config(self, node_path: str, server_config: ServiceConfig):
utilities.log_info(f"* generate nginx for {node_path}")
def generate_nginx_config(self, node_path: str, server_config: ServiceConfig, nginx_listen_port: int):
utilities.log_info(
f"* generate nginx for {node_path}, nginx_listen_port: {nginx_listen_port}")
# copy the nginx config
command = f"cp {constant.ConfigInfo.nginx_tpl_path}/* {node_path}/conf"
(ret, output) = utilities.execute_command_and_getoutput(command)
if ret is False:
raise Exception(f"Generate nginx config failed when execute command: {command}, "
f"error: {output}")
props = server_config.to_nginx_properties()
props = server_config.to_nginx_properties(nginx_listen_port)
for config_file in constant.ConfigInfo.nginx_config_file_list:
config_path = os.path.join(node_path, "conf", config_file)
utilities.substitute_configurations(props, config_path)
Expand Down Expand Up @@ -348,7 +355,7 @@ def get_properties(
def get_service_config(self, agency_config: AgencyConfig) -> ServiceConfig:
return agency_config.model_service_config

def generate_nginx_config(self, node_path: str, server_config: ServiceConfig):
def generate_nginx_config(self, node_path: str, server_config: ServiceConfig, listen_port: int):
return


Expand Down Expand Up @@ -376,7 +383,7 @@ def get_properties(
def get_service_config(self, agency_config: AgencyConfig) -> ServiceConfig:
return agency_config.pir_config

def generate_nginx_config(self, node_path: str, server_config: ServiceConfig):
def generate_nginx_config(self, node_path: str, server_config: ServiceConfig, listen_port: int):
return


Expand Down Expand Up @@ -405,5 +412,5 @@ def get_properties(
def get_service_config(self, agency_config: AgencyConfig) -> ServiceConfig:
return agency_config.jupyter_worker_config

def generate_nginx_config(self, node_path: str, server_config: ServiceConfig):
def generate_nginx_config(self, node_path: str, server_config: ServiceConfig, listen_port: int):
return
2 changes: 1 addition & 1 deletion wedpr-builder/wedpr_builder/tpl/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ upstream backend {
${NGINX_BACKEND_SERVER_LIST}
}
server {
listen 8010;
listen ${NGINX_PORT};
client_max_body_size 30M;
server_name localhost;

Expand Down
4 changes: 2 additions & 2 deletions wedpr-builder/wedpr_builder/tpl/site/conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ useSMCrypto = "false" # RPC SM crypto type

[network]
messageTimeout = "10000"
defaultGroup="group0" # Console default group to connect
peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect
defaultGroup="${BLOCKCHAIN_GROUP_ID}" # Console default group to connect
peers=${BLOCKCHAIN_PEERS} # The peer list to connect

[account]
keyStoreDir = "account" # The directory to load/store the account file, default is "account"
Expand Down

0 comments on commit 3a1d0b9

Please sign in to comment.