From 611c1949ce133fe9e3d046be1b030a0d17664bc1 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 30 Sep 2026 22:28:01 +0800 Subject: [PATCH] fix: keep ticket uploads outside online update status --- .gitignore | 1 + docs/DEPLOYMENT.md | 10 ++++- engine/tests/test_updater.py | 49 ++++++++++++++++++++- engine/virsh_panel/updater.py | 4 ++ web/.gitignore | 1 + web/public/cloud/account.css | 5 ++- web/resources/views/venix/layout_assets.tpl | 2 +- 7 files changed, 68 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f983bdbe..bed4dcdd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ id_ed25519 /web/storage/backups/ /web/storage/logs/ /web/storage/cloud-runtime/ +/web/storage/ticket-attachments/ /web/storage/framework/smarty/compile/* /web/storage/framework/smarty/cache/* /web/storage/framework/views/* diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 6cd9cca0..a3e58e6a 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -205,7 +205,15 @@ systemctl start virt-cloud-engine.service virt-cloud-worker.service virt-cloud-l 以后超级管理员可在“在线更新”页面填写具有该私有仓库只读权限的 Gitea 访问令牌。仓库地址固定为 `https://g.luoli.live/root/virt.git`,分支固定为 `venix`,网页不能修改。令牌写入主库 `engine_records` 时使用引擎 `master.key` 和随机 nonce 进行 AES-GCM 认证加密;读取设置只返回是否已配置,令牌不会回显到页面、Git URL、命令参数或日志。备份数据库时必须同时备份 `runtime/engine/master.key`。若 PHP-FPM unit 不是默认的 `php-fpm.service`,在 `web/config/config.php` 设置 `cloud_update_php_fpm_unit` 后重新执行 `php xcat cloudInit`。 -点击更新前,项目根目录必须是干净的 Git 检出、处于 `venix`、origin 与固定地址完全一致,目录及 `.git` 不能允许组或其他用户写入。更新器只接受快进提交并保存人工回滚引用;通过兼容性检查后,才暂停引擎、worker、策略服务和 PHP-FPM,快进切换代码,执行幂等 `php xcat cloudInit`,最后重启并检查现有服务。更新期间虚拟化写操作会暂停,页面轮询只查询原任务,不会重复提交更新。 +点击更新前,项目根目录必须是干净的 Git 检出、处于 `venix`、origin 与固定地址完全一致,目录及 `.git` 不能允许组或其他用户写入。工单图片属于运行时数据,保存在 `web/storage/ticket-attachments/`,新版本已通过 Git 忽略规则排除;更新器不会删除或覆盖这些附件。若旧版本已经上传过附件,首次升级前先在项目根目录核对工作树只包含该目录,再执行一次性本地排除(不要执行 `git clean`): + +```bash +git status --short --untracked-files=all +printf '\n# Runtime ticket images\n/web/storage/ticket-attachments/\n' >> .git/info/exclude +git status --short --untracked-files=all +``` + +确认第二次状态为空后再打开在线更新。更新器只接受快进提交并保存人工回滚引用;通过兼容性检查后,才暂停引擎、worker、策略服务和 PHP-FPM,快进切换代码,执行幂等 `php xcat cloudInit`,最后重启并检查现有服务。更新期间虚拟化写操作会暂停,页面轮询只查询原任务,不会重复提交更新。 在线更新是纯代码更新:不运行 Composer 或 pip,不创建依赖暂存目录,不复制、改写或重载 systemd unit。若目标提交修改 `engine/requirements.txt`、`web/composer.json`、`web/composer.lock` 或 `deploy/**`,面板会在停服和切换代码前拒绝整个版本。这类版本必须通过 SSH 执行上述手工流程,由部署者审核并安装锁定的 PHP 依赖、Python 依赖和定制的服务单元。 diff --git a/engine/tests/test_updater.py b/engine/tests/test_updater.py index e5b250e4..c9b14532 100644 --- a/engine/tests/test_updater.py +++ b/engine/tests/test_updater.py @@ -57,7 +57,10 @@ def make_repo(tmp_path: Path) -> Path: (source / "README.md").write_text("old\n", encoding="utf-8") (source / "engine").mkdir() (source / "engine" / "requirements.txt").write_text("example-package==1.0\n", encoding="utf-8") - (source / ".gitignore").write_text("engine/.venv/\nruntime/\nweb/vendor/\n", encoding="utf-8") + (source / ".gitignore").write_text( + "engine/.venv/\nruntime/\nweb/vendor/\nweb/storage/ticket-attachments/\n", + encoding="utf-8", + ) git(source, "add", "README.md", "engine/requirements.txt", ".gitignore") git(source, "commit", "-m", "initial") checkout = tmp_path / "panel" @@ -135,6 +138,50 @@ class UpdaterTests(unittest.TestCase): with self.assertRaisesRegex(UpdateError, "未提交"): updater.apply() + def test_project_ignores_ticket_attachment_runtime_data(self): + project_root = Path(__file__).resolve().parents[2] + self.assertIn( + "/web/storage/ticket-attachments/", + (project_root / ".gitignore").read_text(encoding="utf-8"), + ) + self.assertIn( + "storage/ticket-attachments/", + (project_root / "web" / ".gitignore").read_text(encoding="utf-8"), + ) + + def test_ignored_ticket_attachments_do_not_make_checkout_dirty(self): + checkout = make_repo(self.tmp_path) + attachment = checkout / "web" / "storage" / "ticket-attachments" / "ticket-image.png" + attachment.parent.mkdir(parents=True) + attachment.write_bytes(b"private runtime image") + updater = Updater(checkout, MemoryStore()) + updater._remote_head = lambda: git(checkout, "rev-parse", "HEAD") + + self.assertTrue(updater.settings()["checkout_ready"]) + self.assertEqual(updater.check()["status"], "current") + self.assertEqual(git(checkout, "status", "--porcelain=v1", "--untracked-files=all"), "") + + source = self.tmp_path / "source" + target = advance_source(source) + local_fetch(updater, source) + applied = updater.apply() + self.assertEqual(applied["new_commit"], target) + self.assertEqual(attachment.read_bytes(), b"private runtime image") + + def test_target_commit_cannot_vendor_ticket_attachments(self): + checkout = make_repo(self.tmp_path) + source = self.tmp_path / "source" + target = source / "web" / "storage" / "ticket-attachments" / "bundled.png" + target.parent.mkdir(parents=True) + target.write_bytes(b"must remain runtime-only") + git(source, "add", "-f", str(target.relative_to(source))) + git(source, "commit", "-m", "attempt to vendor ticket image") + updater = Updater(checkout, MemoryStore()) + local_fetch(updater, source) + + with self.assertRaisesRegex(UpdateError, "运行数据"): + updater.apply() + def test_fast_forward_job_is_persisted_and_calls_restart(self): checkout = make_repo(self.tmp_path) source = self.tmp_path / "source" diff --git a/engine/virsh_panel/updater.py b/engine/virsh_panel/updater.py index 32e28cd1..1d09b9e4 100644 --- a/engine/virsh_panel/updater.py +++ b/engine/virsh_panel/updater.py @@ -399,6 +399,10 @@ class Updater: "runtime", "web/config/config.php", "web/config/.config.php", + # Ticket images are private runtime data. Keep the path ignored + # and refuse a future target commit that tries to vendor files + # over an existing attachment directory. + "web/storage/ticket-attachments", "web/vendor", "engine/.venv", "engine/master.key", diff --git a/web/.gitignore b/web/.gitignore index 5a1de84c..554d3da1 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -13,4 +13,5 @@ storage/*.online storage/*.offline.delivery.* storage/*.online.delivery.* storage/node_backend_alerts/ +storage/ticket-attachments/ tool/node-gemini-monitor.env diff --git a/web/public/cloud/account.css b/web/public/cloud/account.css index 618cd4c6..b9bea118 100644 --- a/web/public/cloud/account.css +++ b/web/public/cloud/account.css @@ -1731,7 +1731,7 @@ body.vu-body .vu-compact-panel-heading h2 { margin: 0; color: var(--vu-text); fo body.vu-body .vu-compact-panel-heading + :where(.vu-compact-form, .vu-compact-hint, .vu-compact-link-row, .vu-inline-empty) { margin-right: 14px; margin-left: 14px; } body.vu-body .vu-compact-panel-heading + .vu-compact-form { margin-top: 14px; margin-bottom: 14px; } body.vu-body .vu-compact-panel-heading + .vu-compact-hint { margin-top: 12px; } -body.vu-body .vu-referral-hint { display: flex; align-items: flex-start; gap: 7px; width: auto; max-width: calc(100% - 28px); margin: 12px 14px 0; padding: 8px 10px; box-sizing: border-box; background: #f7fbfb; border-radius: 8px; } +body.vu-body .vu-referral-hint { display: flex; align-items: flex-start; gap: 7px; width: auto; max-width: calc(100% - 40px); margin: 12px 20px 0; padding: 8px 10px; box-sizing: border-box; background: #f7fbfb; border-radius: 8px; } body.vu-body .vu-referral-hint i { flex: 0 0 auto; margin-top: 1px; color: var(--vu-brand); font-size: 14px; } body.vu-body .vu-referral-hint span { min-width: 0; } body.vu-body .vu-compact-form { display: grid; align-items: end; gap: 11px; } @@ -1741,6 +1741,9 @@ body.vu-body .vu-compact-field { display: grid; gap: 6px; min-width: 0; color: v body.vu-body .vu-compact-field .vu-input, body.vu-body .vu-factor-line .vu-input { min-height: 40px; padding: 8px 11px; border-radius: 8px; font-size: 12px; } body.vu-body .vu-compact-hint { margin: 0; color: var(--vu-muted); font-size: 10px; line-height: 1.55; } +/* Keep the referral explanation aligned with the drawer content after the + shared compact-hint reset above. */ +body.vu-body .vu-referral-hint { margin: 12px 20px 0; } body.vu-body .vu-inline-status, body.vu-body .vu-inline-empty { display: flex; diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 44958cfc..36e615b9 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026093022' scope='global'} +{assign var=venix_asset_version value='2026093023' scope='global'}