diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..032d19d5 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/docker-files/site/Dockerfile b/docker-files/site/Dockerfile index c2945756..df3dae7f 100644 --- a/docker-files/site/Dockerfile +++ b/docker-files/site/Dockerfile @@ -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"] diff --git a/wedpr-builder/wedpr_builder/common/constant.py b/wedpr-builder/wedpr_builder/common/constant.py index a6cb2528..d1b04314 100644 --- a/wedpr-builder/wedpr_builder/common/constant.py +++ b/wedpr-builder/wedpr_builder/common/constant.py @@ -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"] @@ -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" diff --git a/wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py b/wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py index 5a3c4e7b..ecd51e96 100644 --- a/wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py +++ b/wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py @@ -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" @@ -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 @@ -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}) @@ -417,8 +425,9 @@ 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) @@ -426,7 +435,11 @@ def to_properties(self, deploy_ip, node_index: int) -> {}: 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 @@ -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 @@ -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 = {} @@ -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 diff --git a/wedpr-builder/wedpr_builder/generator/wedpr_gateway_config_generator.py b/wedpr-builder/wedpr_builder/generator/wedpr_gateway_config_generator.py index 6122307c..8dfb5ab4 100644 --- a/wedpr-builder/wedpr_builder/generator/wedpr_gateway_config_generator.py +++ b/wedpr-builder/wedpr_builder/generator/wedpr_gateway_config_generator.py @@ -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, diff --git a/wedpr-builder/wedpr_builder/generator/wedpr_node_config_generator.py b/wedpr-builder/wedpr_builder/generator/wedpr_node_config_generator.py index e9fcb4a3..5f32be72 100644 --- a/wedpr-builder/wedpr_builder/generator/wedpr_node_config_generator.py +++ b/wedpr-builder/wedpr_builder/generator/wedpr_node_config_generator.py @@ -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, diff --git a/wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py b/wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py index b3c4f826..cfae2967 100644 --- a/wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py +++ b/wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py @@ -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] @@ -72,6 +73,8 @@ 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) @@ -79,8 +82,11 @@ def __generate_service_config__( # 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}, " @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh b/wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh index 89a7cb76..c69b489c 100644 --- a/wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh +++ b/wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh @@ -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 diff --git a/wedpr-builder/wedpr_builder/tpl/nginx/nginx.conf b/wedpr-builder/wedpr_builder/tpl/nginx/nginx.conf index a5a12447..c5bb5cf1 100644 --- a/wedpr-builder/wedpr_builder/tpl/nginx/nginx.conf +++ b/wedpr-builder/wedpr_builder/tpl/nginx/nginx.conf @@ -14,7 +14,7 @@ upstream backend { ${NGINX_BACKEND_SERVER_LIST} } server { - listen 8010; + listen ${NGINX_PORT}; client_max_body_size 30M; server_name localhost; @@ -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; \ No newline at end of file +} \ No newline at end of file diff --git a/wedpr-builder/wedpr_builder/tpl/site/conf/config.toml b/wedpr-builder/wedpr_builder/tpl/site/conf/config.toml index bf24b45e..273bbf64 100644 --- a/wedpr-builder/wedpr_builder/tpl/site/conf/config.toml +++ b/wedpr-builder/wedpr_builder/tpl/site/conf/config.toml @@ -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" diff --git a/wedpr-pir/bin/start.sh b/wedpr-pir/bin/start.sh index 25ea39a7..6f801b7f 100644 --- a/wedpr-pir/bin/start.sh +++ b/wedpr-pir/bin/start.sh @@ -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 @@ -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} @@ -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 @@ -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 diff --git a/wedpr-site/bin/start.sh b/wedpr-site/bin/start.sh index 8911e4d0..1e83d89b 100644 --- a/wedpr-site/bin/start.sh +++ b/wedpr-site/bin/start.sh @@ -11,6 +11,12 @@ 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 @@ -44,13 +50,17 @@ JAVA_OPTS+=" -DserviceName=${SERVER_NAME}" 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} @@ -82,7 +92,7 @@ before_start() } start(){ - rm -f start.out + rm -f ${start_log} run_app LOG_INFO "${APP_MAIN} booting up .." try_times=45 @@ -139,6 +149,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 diff --git a/wedpr-worker/bin/start.sh b/wedpr-worker/bin/start.sh index a14ea3b2..c26830b6 100644 --- a/wedpr-worker/bin/start.sh +++ b/wedpr-worker/bin/start.sh @@ -15,10 +15,11 @@ STATUS_STOPPED="Stopped" start_success_log="start.*success" ENABLE_DOCKER_MODE="false" -#if [ "${JAVA_HOME}" = "" ];then -# JAVA_HOME=/nemo/jdk8u382-b05 -# echo "JAVA_HOME has not been configured, set to default: ${JAVA_HOME}" -#fi +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 @@ -50,17 +51,17 @@ JAVA_OPTS+=" -DserviceName=${SERVER_NAME}" JAVA_OPTS+=" -DserviceConfigPath=${CONFIG_PATH}" run_app() { - if [ "$ENABLE_DOCKER_MODE" = "true" ]; then - exec ${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.out 2>&1 & + 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} @@ -92,7 +93,7 @@ before_start() } start(){ - rm -f start.out + rm -f ${start_log} run_app LOG_INFO "${APP_MAIN} booting up .." try_times=45