diff --git a/appmanage/api/service/manage.py b/appmanage/api/service/manage.py index 9f78c0de..515e61df 100644 --- a/appmanage/api/service/manage.py +++ b/appmanage/api/service/manage.py @@ -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() diff --git a/appmanage/api/utils/docker.py b/appmanage/api/utils/docker.py index 2d8c336a..6c284126 100644 --- a/appmanage/api/utils/docker.py +++ b/appmanage/api/utils/docker.py @@ -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) diff --git a/appmanage/api/v1/routers/apps.py b/appmanage/api/v1/routers/apps.py index 7d60d026..eedbe66e 100644 --- a/appmanage/api/v1/routers/apps.py +++ b/appmanage/api/v1/routers/apps.py @@ -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")