Add backend-only deployment option

This commit is contained in:
王鹏
2026-10-09 09:40:30 +08:00
parent 414218c0bd
commit eb5a276f44
5 changed files with 67 additions and 3 deletions

View File

@@ -39,7 +39,8 @@ python main.py
2. 点击“扫描项目”,确认识别到的组件和推荐 JDK 版本。
3. 点击“检测环境”;缺失的工具可以通过“安装环境”处理,也可以手动选择可执行文件。
4. 如果需要导入 SQL,填写 MySQL 用户、密码和数据库名。数据库名默认取第一个 SQL 文件的文件名。MySQL 可在“安装环境”中自动安装;首次使用时填写安装过程中配置的 root 密码。
5. 点击“执行部署”,在运行日志中查看每个步骤和最终访问地址。
5. 如果只需要更新服务端,勾选“只部署后端(保留 SQL 导入)”;程序会跳过所有前端依赖安装、构建和启动步骤。
6. 点击“执行部署”,在运行日志中查看每个步骤和最终访问地址。
当前默认端口如下:

View File

@@ -25,6 +25,7 @@ class DeploymentConfig:
backend_port: str = "8080"
user_frontend_port: str = "8082"
admin_frontend_port: str = "8081"
backend_only: bool = False
output_dir: Path | None = None
tool_paths: Mapping[str, str | Path] | None = None
tool_search_roots: Iterable[Path] | None = None
@@ -86,7 +87,7 @@ def build_deployment_plan(scan: ScanResult, config: DeploymentConfig) -> list[De
description = "构建 SSM WAR 应用" if backend_is_ssm else "打包 Spring Boot 应用"
steps.append(DeploymentStep("构建后端", command, backend_dir, description, kind="backend_build"))
frontends = scan.detected_frontends
frontends = [] if config.backend_only else scan.detected_frontends
for frontend in frontends:
display_name = frontend.metadata.get("display_name", frontend.path.name)
npm_command = _tool_command(config, "npm", _default_npm_command())

View File

@@ -58,6 +58,7 @@ class DeployWorkbench(tk.Tk):
self.mysql_user = tk.StringVar(value="root")
self.mysql_password = tk.StringVar(value=MYSQL_ROOT_PASSWORD)
self.mysql_database = tk.StringVar()
self.backend_only = tk.BooleanVar(value=False)
self.output_dir = tk.StringVar()
self.jdk_version = tk.StringVar(value="8")
self.jdk_reason = tk.StringVar(value="默认推荐 JDK 8,扫描项目后会自动调整。")
@@ -181,6 +182,11 @@ class DeployWorkbench(tk.Tk):
self.mysql_user_widget = self._add_field(right, "MySQL 用户", self.mysql_user)
self.mysql_password_widget = self._add_field(right, "MySQL 密码", self.mysql_password, show="*")
self.database_widget = self._add_field(right, "数据库名", self.mysql_database)
ttk.Checkbutton(
right,
text="只部署后端(保留 SQL 导入)",
variable=self.backend_only,
).pack(anchor=tk.W, pady=(14, 0))
ttk.Label(
right,
text="服务端口使用默认值:8080 / 8082 / 8081",
@@ -517,7 +523,11 @@ class DeployWorkbench(tk.Tk):
plan = self._current_plan()
if not plan:
return
if not messagebox.askyesno("确认执行", "将开始自动执行本地部署:构建前后端、复制前端产物、导入 SQL,并启动后端、用户端和管理端服务。请确认继续。"):
if self.backend_only.get():
confirmation = "将只构建并启动后端,同时导入项目 SQL;不会安装、构建或启动任何前端。请确认继续。"
else:
confirmation = "将开始自动执行本地部署:构建前后端、导入 SQL,并启动后端、用户端和管理端服务。请确认继续。"
if not messagebox.askyesno("确认执行", confirmation):
return
self._set_deployment_running(True)
worker = threading.Thread(target=self._run_deployment_worker, args=(plan,), daemon=True)
@@ -538,6 +548,7 @@ class DeployWorkbench(tk.Tk):
backend_port="8080",
user_frontend_port="8082",
admin_frontend_port="8081",
backend_only=self.backend_only.get(),
output_dir=None,
tool_paths=load_tool_paths(),
)

View File

@@ -421,6 +421,47 @@ class DeployerTests(unittest.TestCase):
self.assertIn("用户端: http://localhost:8082/", combined)
self.assertIn("管理端: http://localhost:8081/", combined)
def test_backend_only_plan_keeps_sql_and_skips_all_frontend_steps(self):
with TemporaryDirectory() as temp:
root = Path(temp)
backend = root / "server"
frontend = root / "web"
database = root / "db"
(backend / "target").mkdir(parents=True)
(backend / "target" / "app.jar").write_text("jar", encoding="utf-8")
frontend.mkdir()
(frontend / "package.json").write_text(
'{"scripts":{"serve":"vue-cli-service serve"}}', encoding="utf-8"
)
database.mkdir()
sql_file = database / "schema.sql"
sql_file.write_text("CREATE TABLE demo(id INT);", encoding="utf-8")
scan = ScanResult(
root=root,
backend=ProjectComponent("Spring Boot", backend, "Maven project"),
frontend=ProjectComponent("Vue", frontend, "Vue project"),
sql_files=[sql_file],
)
plan = build_deployment_plan(
scan,
DeploymentConfig(
backend_only=True,
mysql_database="demo",
output_dir=root / "deploy",
tool_search_roots=[root / "missing"],
),
)
kinds = [step.kind for step in plan]
self.assertEqual(
kinds,
["backend_build_skip", "sql_import", "backend_start", "deployment_summary"],
)
self.assertFalse(any(kind.startswith("frontend_") for kind in kinds))
self.assertEqual(plan[-1].description.count("http://"), 1)
self.assertIn("后端:", plan[-1].description)
def test_plan_uses_executable_steps_without_shell_placeholders(self):
with TemporaryDirectory() as temp:
root = Path(temp)

View File

@@ -26,6 +26,14 @@ class FakeButton:
self.state = options.get("state")
class FakeVariable:
def __init__(self, value=False):
self.value = value
def get(self):
return self.value
class GuiNavigationTests(unittest.TestCase):
def test_database_name_comes_from_first_sql_filename(self):
from pathlib import Path
@@ -66,6 +74,7 @@ class GuiNavigationTests(unittest.TestCase):
app = DeployWorkbench.__new__(DeployWorkbench)
app.deployment_running = False
app.deploy_buttons = [FakeButton()]
app.backend_only = FakeVariable(False)
app._current_plan = lambda: [object()]
app.ui_queue = object()
app._thread_log = lambda value: None
@@ -81,6 +90,7 @@ class GuiNavigationTests(unittest.TestCase):
app = DeployWorkbench.__new__(DeployWorkbench)
app.deployment_running = False
app.deploy_buttons = [FakeButton()]
app.backend_only = FakeVariable(False)
app._current_plan = lambda: [object()]
logs = []
app._append_log = logs.append