Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wedpr-builder #193

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build and Publish Binary
on:
push:
branches-ignore:
- "**"
release:
types: [published, created]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
RUST_BACKTRACE: 1
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION: node16
ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16


jobs:
upload-wedpr-builder:
name: upload-wedpr-builder
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 5
- name: prepare wedpr-builder tgz
run: |
tar -cvzf wedpr-builder.tar.gz wedpr-builder
- name: Upload wedpr-builder
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: wedpr-builder.tar.gz
asset_name: wedpr-builder.tar.gz
tag: ${{ github.ref }}
overwrite: true

upload-web:
name: upload-web
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13]
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '14.17.0'
- name: build web
run: |
cd wedpr-web && npm install && npm run build:pro
mv wedpr-web wedpr-web.bak && mv wedpr-web/dist wedpr-web
tar -cvzf wedpr-web.tar.gz wedpr-web
- name: Upload wedpr-web
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: wedpr-web.tar.gz
asset_name: wedpr-web.tar.gz
tag: ${{ github.ref }}
overwrite: true
2 changes: 1 addition & 1 deletion docker-files/site/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ COPY --from=builder /WeDPR/wedpr-site/dist/ /data/home/wedpr/wedpr-site
# copy the web package
COPY --from=web_builder /WeDPR/wedpr-web/dist /data/home/wedpr/wedpr-site/web

ENTRYPOINT ["/bin/bash", "/data/home/wedpr/wedpr-site/start.sh", "true", "&&", "/usr/sbin/nginx"]
ENTRYPOINT ["/usr/sbin/nginx","&&", "/bin/bash", "/data/home/wedpr/wedpr-site/start.sh", "true"]
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"
32 changes: 23 additions & 9 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,19 +389,25 @@ 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
self.server_backend_list.append(f"{deploy_ip}:{server_start_port}")
server_start_port = self.server_start_port + 3 * node_index
self.server_backend_list.append(
f"server {deploy_ip}:{server_start_port}")
# nodeid
node_id = f"{self.service_type}-{self.env_config.zone}-node{node_index}"
props.update({constant.ConfigProperities.WEDPR_NODE_ID: node_id})
Expand All @@ -417,16 +425,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 +456,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 +861,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 +898,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
8 changes: 5 additions & 3 deletions wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ LOG_INFO() {

cd ${SHELL_FOLDER}

LOG_INFO "Ready to create docker: ${WEDPR_DOCKER_NAME}, Please enter 'Y' to confirm"
LOG_INFO "Ready to create docker: ${WEDPR_DOCKER_NAME}, Please enter 'Y' to confirm: "
read -r confirm
if [ ${confirm} != "Y" ]
if [[ "${confirm}" == "Y" || "${confirm}" == "y" ]]; then
LOG_INFO "Begin to create docker: ${WEDPR_DOCKER_NAME}"
LOG_INFO "* Begin to create docker: ${WEDPR_DOCKER_NAME}"
LOG_INFO "* Pull image ${WEDPR_IMAGE_DESC}"
docker pull ${WEDPR_IMAGE_DESC}
LOG_INFO "* Pull image ${WEDPR_IMAGE_DESC} success, begin to create docker"
docker run -d --restart always --net host -v ${SHELL_FOLDER}/${WEDPR_CONFIG_DIR}:${DOCKER_CONF_PATH} -v ${SHELL_FOLDER}/${WEDPR_LOG_DIR}:${DOCKER_LOG_PATH} ${EXTENDED_MOUNT_CONF} --name ${WEDPR_DOCKER_NAME} ${WEDPR_IMAGE_DESC} ${WEDPR_DOCKER_EXPORSE_PORT_LIST}
LOG_INFO "Create docker: ${WEDPR_DOCKER_NAME} success"
else
Expand Down
6 changes: 2 additions & 4 deletions 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 Expand Up @@ -67,6 +67,4 @@ server {
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

daemon off;
}
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
21 changes: 18 additions & 3 deletions wedpr-pir/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ STATUS_STARTING="Starting"
STATUS_RUNNING="Running"
STATUS_STOPPED="Stopped"
start_success_log="start.*success"
ENABLE_DOCKER_MODE="false"

start_log="start.out"
if [ "${ENABLE_DOCKER_MODE}" = "true" ]; then
start_log="logs/start.out"
fi


JAVA_CMD=$JAVA_HOME/bin/java
if [ ! -f "${JAVA_HOME}" ];then
Expand Down Expand Up @@ -46,13 +53,17 @@ JAVA_OPTS+=" -DserviceConfigPath=${CONFIG_PATH}"

run_app()
{
nohup $JAVA_CMD $JAVA_OPTS -cp $CLASSPATH $APP_MAIN > start.out 2>&1 &
if [ "${ENABLE_DOCKER_MODE}" = "true" ]; then
exec ${JAVA_CMD} $JAVA_OPTS -cp $CLASSPATH $APP_MAIN > ${start_log} 2>&1
else
nohup $JAVA_CMD $JAVA_OPTS -cp $CLASSPATH $APP_MAIN > ${start_log} 2>&1 &
fi
}

app_status()
{
if [ ! -z "$(app_pid)" ]; then
if [ ! -z "$(grep -i "${start_success_log}" start.out)" ]; then
if [ ! -z "$(grep -i "${start_success_log}" ${start_log})" ]; then
echo ${STATUS_RUNNING}
else
echo ${STATUS_STARTING}
Expand Down Expand Up @@ -84,7 +95,7 @@ before_start()
}

start(){
rm -f start.out
rm -f ${start_log}
run_app
LOG_INFO "${APP_MAIN} booting up .."
try_times=45
Expand Down Expand Up @@ -141,6 +152,10 @@ after_start()
esac
}

if [ $# -eq 1 ]; then
ENABLE_DOCKER_MODE="${1}"
fi
echo "ENABLE_DOCKER_MODE: ${ENABLE_DOCKER_MODE}"
before_start
start
after_start
Loading
Loading