更新系统页面和更新功能

- 更新 admin-frontend 系统页面和更新 API
- 更新 routes 和 services 中的更新逻辑
- 重新构建前端静态资源
This commit is contained in:
2025-12-15 15:58:12 +08:00
parent de6d269fb4
commit a8b9f225bd
22 changed files with 165 additions and 62 deletions

View File

@@ -66,6 +66,15 @@ def sanitize_job_id(value: object) -> str:
return text
def _as_bool(value: object) -> bool:
if isinstance(value, bool):
return value
if isinstance(value, int):
return value != 0
text = str(value or "").strip().lower()
return text in ("1", "true", "yes", "y", "on")
def _run(cmd: list[str], *, cwd: Path, log_fp, env: Optional[dict] = None, check: bool = True) -> subprocess.CompletedProcess:
log_fp.write(f"[{ts_str()}] $ {' '.join(cmd)}\n")
log_fp.flush()
@@ -305,7 +314,16 @@ def consume_request(paths: Paths) -> Tuple[dict, Optional[str]]:
return data, None
def handle_update_job(*, paths: Paths, branch: str, health_url: str, job_id: str, requested_by: str) -> None:
def handle_update_job(
*,
paths: Paths,
branch: str,
health_url: str,
job_id: str,
requested_by: str,
build_no_cache: bool = False,
build_pull: bool = False,
) -> None:
ensure_dirs(paths)
log_path = paths.jobs_dir / f"{job_id}.log"
with open(log_path, "a", encoding="utf-8") as log_fp:
@@ -323,6 +341,8 @@ def handle_update_job(*, paths: Paths, branch: str, health_url: str, job_id: str
"duration_seconds": None,
"requested_by": requested_by,
"branch": branch,
"build_no_cache": bool(build_no_cache),
"build_pull": bool(build_pull),
"from_commit": None,
"to_commit": None,
"backup_db": None,
@@ -360,7 +380,30 @@ def handle_update_job(*, paths: Paths, branch: str, health_url: str, job_id: str
result["stage"] = "docker_build"
result["message"] = "构建容器镜像"
write_result(paths, result)
_run([*compose, "build"], cwd=paths.repo_dir, log_fp=log_fp)
build_no_cache = bool(result.get("build_no_cache") is True)
build_pull = bool(result.get("build_pull") is True)
build_cmd = [*compose, "build"]
if build_pull:
build_cmd.append("--pull")
if build_no_cache:
build_cmd.append("--no-cache")
try:
_run(build_cmd, cwd=paths.repo_dir, log_fp=log_fp)
except subprocess.CalledProcessError as e:
if (not build_no_cache) and (e.returncode != 0):
log_fp.write(f"[{ts_str()}] build failed, retry with --no-cache\n")
log_fp.flush()
build_no_cache = True
result["build_no_cache"] = True
write_result(paths, result)
retry_cmd = [*compose, "build"]
if build_pull:
retry_cmd.append("--pull")
retry_cmd.append("--no-cache")
_run(retry_cmd, cwd=paths.repo_dir, log_fp=log_fp)
else:
raise
result["stage"] = "docker_up"
result["message"] = "重建并启动服务"
@@ -501,12 +544,16 @@ def main(argv: list[str]) -> int:
elif action == "check":
handle_check_job(paths=paths, branch=branch, job_id=job_id, requested_by=requested_by)
else:
build_no_cache = _as_bool(req.get("build_no_cache") or req.get("no_cache") or False)
build_pull = _as_bool(req.get("build_pull") or req.get("pull") or False)
handle_update_job(
paths=paths,
branch=branch,
health_url=health_url,
job_id=job_id,
requested_by=requested_by,
build_no_cache=build_no_cache,
build_pull=build_pull,
)
last_check_ts = time.time()