Skip to content

feat: 引入模板驱动的实例管理闭环(容器创建、配置重建、实时状态与网页控制台)#3

Closed
MF-B wants to merge 28 commits intomainfrom
feat/game-server
Closed

feat: 引入模板驱动的实例管理闭环(容器创建、配置重建、实时状态与网页控制台)#3
MF-B wants to merge 28 commits intomainfrom
feat/game-server

Conversation

@MF-B
Copy link
Copy Markdown
Owner

@MF-B MF-B commented Apr 4, 2026

变更概览

本 PR 将 MineDock 从“基础容器增删启停”扩展为“模板驱动创建 + 实时状态同步 + 在线控制台 + 配置重建”的完整链路,同时补齐文档体系与任务流水线。

主要改动

  • 后端新增游戏目录与 YAML 模板能力,支持按游戏 ID 加载模板并做结构校验(镜像、参数、端口、卷挂载等)。
  • 后端实例创建流程升级:创建时可注入模板参数、覆盖宿主机端口映射、自动应用卷挂载命名规则,并在本地持久化实例元数据。
  • 后端新增实例配置读写接口:支持读取当前生效配置,并在容器停止状态下通过“重建容器”应用新参数与端口映射。
  • 后端新增事件中心与 WebSocket 推送,基于 Docker 事件向前端广播实例快照,实现状态实时同步。
  • 后端新增网页控制台 WebSocket 桥接,打通容器 stdin/stdout/stderr 的双向通信。
  • 存储层从内存实现演进为 SQLite 持久化,实例记录包含 game_id,重启后可恢复元数据。
  • 前端新增镜像市场页、实例创建页、实例详情页(控制台/配置双 Tab),并接入模板参数表单、端口编辑与重建结果回写。
  • 前端新增实例同步机制:优先使用 WebSocket 实时更新,断线自动降级轮询并指数退避重连。
  • 前端新增 xterm 控制台集成,支持在线输入、输出渲染与自适应布局。
  • 文档结构重组为 api、standards、design-docs、exec-plans 目录,并补齐 API 合约与设计文档。
  • 工程与 CI 更新:Taskfile 统一开发/构建/测试/文档检查任务,CI 与 Release 流程同步到 Go 1.25.x,新增文档 lint/fmt/todo 生成链路。

API 变化

  • 新增 GET /api/games
  • 新增 GET /api/games/:id/template
  • 新增 GET /api/ws/events
  • 新增 GET /api/ws/console/:id
  • 新增 GET /api/instances/:id/config
  • 新增 PUT /api/instances/:id/config
  • 扩展 POST /api/instances 请求体,支持 params 与 ports

行为说明与注意事项

  • 实例配置更新通过重建容器生效,成功后会返回新的 container_id。
  • 配置更新仅允许在容器停止状态下执行,运行中会返回冲突错误。
  • WebSocket 连接采用同源策略;连接失败时前端自动回退轮询。
  • 删除实例默认不删除关联卷,数据默认保留。

影响范围

  • 后端 API、服务层、存储层、路由和主启动流程
  • 前端路由、状态管理、页面与实时通信
  • 文档目录结构、任务脚本、CI 与发布流程

MF-B added 28 commits March 29, 2026 23:18
Copilot AI review requested due to automatic review settings April 4, 2026 15:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands MineDock into a template-driven instance lifecycle loop, adding game/template discovery, real-time instance status sync, an in-browser console, and config rebuild flows, along with docs/CI/tasking updates to support the new architecture.

Changes:

  • Introduces backend game catalog + YAML templates and updates instance creation/config update APIs accordingly.
  • Adds WebSocket-based real-time instance snapshot push and a WebSocket console bridge (stdin/stdout/stderr).
  • Evolves storage and engineering workflows: SQLite persistence improvements, new Taskfile quality gates, and reorganized documentation/exec plans.

Reviewed changes

Copilot reviewed 76 out of 78 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Taskfile.yml Adds fmt/lint/docs tasks and reorganizes global quality gates.
scripts/todo-gen/main.go New TODO index generator for consolidating TODO: comments into docs.
Readme.md Updates project TODO list and trims/adjusts run guidance.
frontend/vite.config.js Adjusts dev server host/HMR and proxy WebSocket settings.
frontend/src/views/InstanceDetail.vue New instance detail page with console/config tabs and console lifecycle management.
frontend/src/views/ImageRegistry.vue New game template marketplace page with category filtering and navigation to create flow.
frontend/src/views/ContainerList.vue Hooks in realtime sync, routes to registry/detail pages, and improves output i18n rendering.
frontend/src/stores/games.ts New Pinia store for game list + template caching and fetching.
frontend/src/stores/containers.ts Enhances store with i18n-safe error mapping, WS connection state, snapshot apply, and updated create signature.
frontend/src/router/index.ts Adds routes for registry, create instance, and instance detail pages.
frontend/src/locales/zh-CN.json Adds i18n strings for console/config/registry/errors and realtime status.
frontend/src/locales/en-US.json Adds i18n strings for console/config/registry/errors and realtime status.
frontend/src/composables/useInstanceSync.ts New composable for WS realtime sync with polling fallback and exponential backoff reconnect.
frontend/src/composables/useConsole.ts New xterm-based console composable over WebSocket bridge.
frontend/src/components/TopBar.vue Adds realtime sync indicator and refines language menu behavior.
frontend/src/components/Sidebar.vue Adds navigation entry for the registry and tweaks mobile/desktop hamburger spacing.
frontend/src/api/index.ts Adds typed APIs for games/templates/config, WS URL builder, and structured request error type.
frontend/package.json Adds xterm dependencies for the web console.
frontend/package-lock.json Locks newly added xterm dependencies.
docs/standards/ops.md New ops standards doc reflecting Taskfile/CI/release conventions.
docs/standards/frontend.md New frontend standards doc describing architecture, routing, styling, and error handling conventions.
docs/standards/directory.md New directory layout reference.
docs/standards/backend.md New backend standards doc describing layering, error handling, DB constraints, and quality gates.
docs/ops_engineering_standards.md Removes older ops standards doc in favor of reorganized standards.
docs/exec-plans/TODO.md Adds generated TODO index output.
docs/exec-plans/README.md Adds exec-plans directory guidance and TODO index generation instructions.
docs/exec-plans/completed/20260401-realtime-status-sync.md Adds completed plan doc for WS realtime status sync design/implementation.
docs/exec-plans/completed/20260331-static-image-registry.md Adds completed plan doc for static registry design/implementation history.
docs/exec-plans/completed/20260331-image-marketplace-page.md Adds completed plan doc for marketplace UI flow.
docs/exec-plans/active/20260402-container-ports-volumes.md Adds active plan doc for port/volume wiring on create.
docs/exec-plans/.markdownlint.json Adds markdownlint overrides for exec-plans docs.
docs/domain_instance_lifecycle.md Removes older lifecycle doc in favor of reorganized design docs.
docs/design-docs/instance_lifecycle.md Adds updated lifecycle design doc including config rebuild, console, and consistency strategy.
docs/api/contracts.md Adds consolidated API contracts including games/templates/ws/config endpoints.
docs/02_API_Contracts.md Removes older API contracts doc in favor of new contracts location.
docs/01_Frontend_Standards.md Removes older frontend standards doc in favor of new standards structure.
docs/01_Backend_Standards.md Removes older backend standards doc in favor of new standards structure.
docs/00_Root_Context.md Removes older root context doc in favor of reorganized docs.
backend/templates/terraria.yaml Adds Terraria YAML template definition.
backend/templates/minecraft-java.yaml Adds Minecraft Java YAML template definition.
backend/templates/minecraft-bedrock.yaml Adds Minecraft Bedrock YAML template definition.
backend/main.go Wires up game service, event hub, WS handlers, console service, and config handler into the server.
backend/internal/store/sqlite.go Extends schema to store game_id, improves comments, and adds schema migration helper.
backend/internal/store/sqlite_test.go Adds SQLite store tests covering save/get/upsert/unique name/delete/list.
backend/internal/service/game_service.go Adds game catalog loader and YAML template parsing + normalization/validation.
backend/internal/service/game_service_test.go Adds tests for game service loading, template resolution, and validation errors.
backend/internal/service/event_hub.go Adds Docker events listener + WS broadcast hub with debounce, dedupe, and backoff.
backend/internal/service/event_hub_test.go Adds tests for client add/remove and snapshot deduplication behavior.
backend/internal/service/console_service.go Adds console attach service with running-state enforcement.
backend/internal/service/console_service_test.go Adds tests for attach success/failure paths.
backend/internal/model/template.go Adds template model types (image/container/ports/volumes/resources/params).
backend/internal/model/instance.go Extends instance model to include game_id.
backend/internal/model/game.go Adds game model for catalog listing.
backend/internal/model/errors.go Adds shared domain errors used for consistent API error mapping.
backend/internal/api/ws_handler.go Adds WS handler for instance snapshot events.
backend/internal/api/ws_handler_test.go Adds WS handler tests for hub unavailable and client add/remove.
backend/internal/api/router.go Registers new API routes (games/templates/ws/config/console) and adjusts CORS handling.
backend/internal/api/handlers.go Updates instance APIs to accept game/template params/ports and centralizes error-to-status mapping.
backend/internal/api/game_handlers.go Adds handlers for listing games and fetching templates by id.
backend/internal/api/console_handler.go Adds WS console bridge handler piping WS <-> Docker attach streams.
backend/internal/api/config_handler.go Adds config read/update handlers with rebuild flow support.
backend/internal/api/config_handler_test.go Adds tests for config get/update endpoints and error mapping.
backend/go.sum Adds dependency checksums (e.g., coder/websocket).
backend/go.mod Adds coder/websocket and records yaml dependency.
backend/games.json Adds game catalog data consumed by the backend and UI.
backend/.golangci.yml Adds golangci-lint configuration for backend linting.
AGENTS.md Adds documentation navigation index.
.markdownlint.json Adds root markdownlint configuration.
.github/workflows/release.yml Updates workflow to use new formatting task name.
.github/workflows/ci.yml Updates CI to use new global formatting check task.
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

docs:links:check:
desc: Check Markdown links for the knowledge base
cmds:
- npx --yes markdown-link-check -q "AGENTS.md" "Readme.md" "docs"
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs:links:check passes the docs directory to markdown-link-check, but the CLI expects Markdown file paths; passing a directory typically fails with an EISDIR/stat error. Consider changing this to a glob of markdown files (e.g. docs/**/*.md) or enumerating files via find/git ls-files before invoking the checker so the task works in CI.

Suggested change
- npx --yes markdown-link-check -q "AGENTS.md" "Readme.md" "docs"
- find docs -type f -name '*.md' -exec npx --yes markdown-link-check -q "AGENTS.md" "Readme.md" {} +

Copilot uses AI. Check for mistakes.
Comment on lines +162 to +173
socket.onclose = (event: CloseEvent) => {
if (disposed) {
return;
}
connected.value = false;
if (event.reason) {
error.value = event.reason;
return;
}
if (event.code !== 1000) {
error.value = "console.disconnected";
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WebSocket close handler sets error.value = "console.disconnected", but the locales only define console.disconnectedLabel (no console.disconnected). This will render as a missing i18n key in InstanceDetail.vue (it translates any console.* errors). Align the key name (either add console.disconnected translations or reuse the existing console.disconnectedLabel).

Copilot uses AI. Check for mistakes.
Comment on lines 15 to 19
"dependencies": {
"@xterm/addon-attach": "^0.11.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0",
"pinia": "^3.0.4",
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xterm/addon-attach is added as a dependency but does not appear to be imported/used anywhere in frontend/src (the console composable uses only @xterm/xterm and @xterm/addon-fit). If it's not needed, remove it (and the corresponding lockfile entry) to reduce install/bundle surface; otherwise add the integration that requires it.

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +103
<div
v-for="item in store.instances"
:key="item.container_id"
class="card"
@click="openInstanceDetail(item.container_id)"
>
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each instance card is now a clickable <div> that navigates to the detail page. As-is it isn’t keyboard-accessible (no tabindex, no Enter/Space handling, no link semantics), which is an accessibility regression. Prefer using a semantic element (e.g. a <button>/<a> wrapper) or add role="link" + tabindex="0" and key handlers so keyboard users can open details.

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +134
<div class="header-left">
<button class="back-btn" @click="backToList">&lt;</button>
</div>
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The back button uses only the “<” glyph and has no accessible label. Add an aria-label (and preferably type="button") so screen readers announce its purpose and it won’t accidentally act as a submit button if nested in a form in the future.

Copilot uses AI. Check for mistakes.
@MF-B MF-B closed this Apr 4, 2026
@MF-B MF-B deleted the feat/game-server branch April 4, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants