Skip to content

Commit

Permalink
support docker
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Dec 6, 2024
1 parent a956d69 commit e7a7d28
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions wedpr-builder/wedpr_builder/common/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ConfigInfo:
wedpr_worker_docker_dir = "wedpr-worker"
wedpr_pir_docker_dir = "wedpr-pir"
wedpr_site_docker_dir = "wedpr-site"
docker_file_list = ["creat_docker.sh", "start_docker.sh", "stop_docker.sh"]

@staticmethod
def get_docker_path(file_path: str):
Expand Down
8 changes: 8 additions & 0 deletions wedpr-builder/wedpr_builder/config/wedpr_deploy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ def to_properties(self, deploy_ip, node_index: int) -> {}:
{constant.ConfigProperities.WEDPR_IMAGE_DESC: image_desc})
# set the exposed port
exposed_port_list = f"-p {start_port}:{start_port} -p {start_port + 1}:{start_port + 1}"
# default expose 20 ports for jupyter use
# reserver 100 ports for jupyter use
jupyter_start_port = start_port + 100
default_jupyter_max_num = 20
if self.service_type == constant.ServiceInfo.wedpr_jupyter_worker_service:
start_port = jupyter_start_port + default_jupyter_max_num * node_index
end_port = start_port + default_jupyter_max_num
exposed_port_list = f"{exposed_port_list} -p {start_port}-{end_port}:{start_port}-{end_port}"
props.update(
{constant.ConfigProperities.WEDPR_DOCKER_EXPORSE_PORT_LIST: exposed_port_list})
# set the docker name
Expand Down
20 changes: 20 additions & 0 deletions wedpr-builder/wedpr_builder/generator/wedpr_service_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from wedpr_builder.config.wedpr_deploy_config import ServiceConfig
from wedpr_builder.common import utilities
from wedpr_builder.common import constant
from wedpr_builder.generator.docker_generator import DockerGenerator


class WedprServiceGenerator:
Expand Down Expand Up @@ -94,12 +95,31 @@ def __generate_single_site_config(
# substitute the configuration
config_properties = self.get_properties(
deploy_ip, agency_config, node_index)
# the docker mode case
self.__generate_docker_scripts__(
node_path, config_properties, service_config)
for config_file in service_config.config_file_list:
config_path = os.path.join(node_path, "conf", config_file)
if service_config.service_type == constant.ServiceInfo.wedpr_model_service:
config_path = os.path.join(node_path, config_file)
utilities.substitute_configurations(config_properties, config_path)

def __generate_docker_scripts__(
self, node_path: str,
config_props: {},
service_config: ServiceConfig):
# Note: jupyter only support docker mode
if self.config.env_config.docker_mode is False \
and service_config.service_type != \
constant.ServiceInfo.wedpr_jupyter_worker_service:
return
self.__generate_docker_scripts_impl__(node_path, config_props)

def __generate_docker_scripts_impl__(self, node_path, config_props: dict):
docker_generater = DockerGenerator(node_path,
constant.ConfigInfo.docker_tpl_path)
docker_generater.generate_config(config_props)

@abstractmethod
def __generate_shell_scripts__(self, dist_path, dst_path):
pass
Expand Down
6 changes: 6 additions & 0 deletions wedpr-builder/wedpr_builder/tpl/docker/create_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)

cd ${SHELL_FOLDER}

docker run -d -v ${SHELL_FOLDER}/${WEDPR_CONFIG_DIR}:${DOCKER_CONF_PATH} -v ${SHELL_FOLDER}/${WEDPR_LOG_DIR}:${DOCKER_LOG_PATH} --name ${WEDPR_DOCKER_NAME} ${WEDPR_IMAGE_DESC} ${WEDPR_DOCKER_EXPORSE_PORT_LIST}
6 changes: 6 additions & 0 deletions wedpr-builder/wedpr_builder/tpl/docker/start_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)

cd ${SHELL_FOLDER}

docker start ${WEDPR_DOCKER_NAME}
6 changes: 6 additions & 0 deletions wedpr-builder/wedpr_builder/tpl/docker/stop_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)

cd ${SHELL_FOLDER}

docker stop ${WEDPR_DOCKER_NAME}

0 comments on commit e7a7d28

Please sign in to comment.