mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-24 10:17:15 +08:00
appmanage:add app_version
This commit is contained in:
parent
09d2bb44b8
commit
14ab2cba87
@ -53,11 +53,15 @@ def set_app_info(output_list, num):
|
||||
pass
|
||||
id = 0 # id
|
||||
case = output_list[3 * i + 1].split("(")[0] # case
|
||||
if (case.startswith("r")):
|
||||
if case == "running":
|
||||
case_code = const.RETURN_RUNNING # case_code
|
||||
else:
|
||||
elif case == "exited":
|
||||
case = "stop"
|
||||
case_code = const.RETURN_STOP
|
||||
elif case == "ready":
|
||||
case_code = const.RETURN_READY
|
||||
else:
|
||||
case_code = const.RETURN_ERROR
|
||||
volume = output_list[3 * i + 2] # volume
|
||||
j = 2
|
||||
while not volume.startswith("/"):
|
||||
@ -101,11 +105,14 @@ def install_app_process(app_name):
|
||||
ret = ret.dict()
|
||||
return ret
|
||||
|
||||
def install_app(app_name,app_version):
|
||||
def install_app(app_name, app_version):
|
||||
# check directory
|
||||
if docker.check_app_directory(app_name):
|
||||
# check port
|
||||
docker.check_app_compose(app_name)
|
||||
if app_version != None:
|
||||
path = "/data/apps/"+app_name+"/.env"
|
||||
docker.modify_env(path, "APP_VERSION", app_version)
|
||||
cmd = "cd /data/apps/"+app_name+" && sudo docker compose up -d"
|
||||
t1 = Thread(target=shell_execute.execute_command_output_all, args=(cmd,))
|
||||
t1.start()
|
||||
|
@ -34,11 +34,11 @@ def check_app_compose(app_name):
|
||||
if http_port != "":
|
||||
print("check http port...")
|
||||
http_port = network.get_start_port(http_port)
|
||||
modify_port(path, http_port_env, http_port)
|
||||
modify_env(path, http_port_env, http_port)
|
||||
if db_port != "":
|
||||
print("check db port...")
|
||||
db_port = network.get_start_port(db_port)
|
||||
modify_port(path, db_port_env, db_port)
|
||||
modify_env(path, db_port_env, db_port)
|
||||
print("port check complete")
|
||||
return
|
||||
|
||||
@ -55,12 +55,12 @@ def read_env(path, key):
|
||||
ret = re.sub("\n","",ret)
|
||||
return env, ret
|
||||
|
||||
def modify_port(path, env_name, port):
|
||||
def modify_env(path, env_name, value):
|
||||
file_data = ""
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if env_name in line:
|
||||
line = line.replace(line, env_name + "=" + port+"\n")
|
||||
line = line.replace(line, env_name + "=" + value+"\n")
|
||||
file_data += line
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(file_data)
|
||||
|
@ -18,7 +18,7 @@ def list_my_apps():
|
||||
|
||||
@router.get("/install")
|
||||
def install_app(app_name: Optional[str] = None, app_version: Optional[str] = None):
|
||||
ret = manage.install_app(app_name)
|
||||
ret = manage.install_app(app_name, app_version)
|
||||
return JSONResponse(content=ret)
|
||||
|
||||
@router.get("/process")
|
||||
|
Loading…
Reference in New Issue
Block a user