Skip to content

Commit

Permalink
0.9.9.17
Browse files Browse the repository at this point in the history
#####
1. 修复路径问题

#####
  • Loading branch information
Xingsandesu committed Jan 21, 2024
1 parent 8475628 commit b51733d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions async_app/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
CODE_YES = 200 # 操作成功的响应码
CODE_NO = 400 # 操作失败的响应码


# 获取 Docker 数据路径
def get_docker_data_path():
docker_info = client.info()
return docker_info.get('DockerRootDir')


# 使用 Docker 数据路径
docker_data_path = get_docker_data_path()


def create_api_response(handler: tornado.web.RequestHandler, code: int, errmsg: any = '', data: any = None):
"""
返回一个josnify后的对象
Expand All @@ -40,9 +43,6 @@ def create_api_response(handler: tornado.web.RequestHandler, code: int, errmsg:

handler.set_header("Content-Type", "application/json; charset=utf-8")
handler.write(json_data)





class CreateContainerHandler(tornado.web.RequestHandler):
Expand Down Expand Up @@ -74,14 +74,14 @@ async def post(self, id):
logging.info(f"Ports: {ports}")
logging.info(f"Restart Policy: {restart_policy}")
logging.info(f"Environment Variables: {env}") # 打印环境变量

volumes = app_run_data.get('volumes', {})
for volume, details in volumes.items():
if volume not in [v.name for v in client.volumes.list()]:
logging.info(f"将创建存储卷:{volume}")
client.volumes.create(volume)
bind_path = details['bind']
host_path = f"/var/lib/docker/volumes/{volume}/_data{bind_path}"
host_path = f"{docker_data_path}/volumes/{volume}/_data{bind_path}"
logging.info(f"将初始化存储卷:{volume}")
if os.path.splitext(bind_path)[1] == '' or bind_path.endswith('/'):
os.makedirs(host_path, exist_ok=True)
Expand All @@ -95,7 +95,7 @@ async def post(self, id):

for volume, cmds in run_cmd.items():
bind_path = volumes[volume]['bind']
host_path = f"/var/lib/docker/volumes/{volume}/_data{bind_path}"
host_path = f"{docker_data_path}/volumes/{volume}/_data{bind_path}"
if not os.path.isdir(host_path):
host_path = os.path.dirname(host_path)
for cmd in cmds:
Expand Down Expand Up @@ -137,7 +137,8 @@ async def post(self, id):
name=name,
ports={k: (None, v) for k, v in ports.items()},
volumes={f"{docker_data_path}/volumes/{v}/_data{details['bind']}": {'bind': details['bind'],
'mode': details['mode']} for v, details
'mode': details['mode']} for
v, details
in volumes.items()} if volumes else {},
restart_policy=restart_policy,
environment=env # 添加环境变量
Expand Down
2 changes: 1 addition & 1 deletion core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"""

TAICHI_OS_WELCOME_MESSAGE = ("\n"
"版本 : 0.9.9.16-DEV\n"
"版本 : 0.9.9.17-DEV\n"
"GITHUB : https://github.com/Xingsandesu\n")
# # @/command 配置文件
# commands = {
Expand Down

0 comments on commit b51733d

Please sign in to comment.