This commit is contained in:
root
2026-05-18 11:04:52 +00:00
parent efa5533032
commit 088a5a6429
6 changed files with 136 additions and 29 deletions

View File

@@ -262,6 +262,9 @@ def _try_local_console_build() -> tuple[bool, str]:
return True, "up-to-date"
print("[launch] 正在构建 Web 控制台…")
for path in (CONSOLE / "node_modules", CONSOLE / ".next"):
if path.exists():
shutil.rmtree(path, ignore_errors=True)
lock = CONSOLE / "package-lock.json"
if lock.is_file():
rc = _run_console_cmd([npm, "ci"], cwd=CONSOLE, env=env)
@@ -290,9 +293,18 @@ def _docker_console_build() -> bool:
print(f"[launch] 本机 Node 不足,改用 Docker 构建: {DOCKER_NODE_IMAGE}")
script = (
"set -e; "
"rm -rf /tmp/web-console; "
"mkdir -p /tmp/web-console; "
"cd /workspace/web-console; "
"if [ ! -d node_modules ]; then npm ci || npm install; fi; "
"npm run build"
"tar --exclude=node_modules --exclude=.next --exclude=out -cf - . | tar -C /tmp/web-console -xf -; "
"cd /tmp/web-console; "
"rm -rf node_modules .next out; "
"export HOME=/tmp npm_config_cache=/tmp/npm-cache; "
"if [ -f package-lock.json ]; then npm ci || npm install; else npm install; fi; "
"test -x node_modules/.bin/next; "
"npm run build; "
"rm -rf /workspace/web-console/out; "
"cp -a out /workspace/web-console/out"
)
cmd = [
docker,
@@ -300,6 +312,10 @@ def _docker_console_build() -> bool:
"--rm",
"-u",
f"{os.getuid()}:{os.getgid()}",
"-e",
"HOME=/tmp",
"-e",
"npm_config_cache=/tmp/npm-cache",
"-v",
f"{ROOT}:/workspace",
"-w",
@@ -390,7 +406,10 @@ def _start_docker_console_dev(*, host: str, port: str, next_port: str) -> subpro
script = (
"set -e; "
"cd /workspace/web-console; "
"if [ ! -d node_modules ]; then npm ci || npm install; fi; "
"if [ ! -x node_modules/.bin/next ]; then rm -rf node_modules .next; fi; "
"if [ ! -d node_modules ]; then "
"if [ -f package-lock.json ]; then npm ci || npm install; else npm install; fi; "
"fi; "
"npm run dev -- --hostname 0.0.0.0 --port 3000"
)
cmd = [
@@ -404,6 +423,10 @@ def _start_docker_console_dev(*, host: str, port: str, next_port: str) -> subpro
"-e",
f"API_PROXY_TARGET={proxy_target}",
"-e",
"HOME=/tmp",
"-e",
"npm_config_cache=/tmp/npm-cache",
"-e",
"HOST=0.0.0.0",
"-e",
"PORT=3000",