Skip to content

fix(bridge): run with the socket group and report Docker failures - #9

Merged
TN019 merged 11 commits into
mainfrom
fix/docker-access-and-status
Dec 1, 2026
Merged

TN019 merged 11 commits into
mainfrom
fix/docker-access-and-status

Conversation

@TN019

@TN019 TN019 commented Dec 1, 2026

Copy link
Copy Markdown

Why

The bridge ran as node with a group ID that scripts/venue.sh read on the host, which is not necessarily the group the socket has inside the container. When Docker access failed, power and network buttons failed without a clear reason on the page. The scenario buttons could also be pressed with an empty barcode, and the lane did not show whether the cable was plugged in.

What changed

  • Add scripts/bridge-entrypoint.sh as the image ENTRYPOINT. It checks that the socket exists, reads its group with stat -c %g, and starts the server through setpriv --reuid=node --regid=node --groups=<gid>. Remove USER node from the Dockerfile, group_add from compose.devices.yaml, and the host-side DOCKER_GID lookup from scripts/venue.sh. venue.sh also stops overriding DOCKER_CONFIG and DOCKER_HOST, so the host's Docker CLI settings apply.
  • bridge/src/docker.ts: errors read Docker API <status>: <message>, and socketHealth() pings /_ping.
  • bridge/src/server.ts: check the socket at startup, include docker in every snapshot, return 503 from /health while Docker is not accessible, log successful actions as action events, and log failures to the console and the event list as well as sending them to the browser.
  • web/src/main.tsx: show Network cable plugged|unplugged in each lane and the Docker socket message in the header; disable Two gates at once, All gates at once, Scan again and Start burst until the scenario barcode is filled; a ticket button also fills that field.
  • Tests: reports Docker API status and message from an inaccessible socket in bridge/test/docker.test.ts, the cable label in web/test/lane.test.tsx, and the cable label and the disabled scenario button in e2e/entrance.spec.ts.

How to verify

pnpm test
pnpm build
PORT=28080 DEVICE_PORT=7600 node bridge/dist/server.js &
node scripts/fake-gates.mjs &
pnpm test:e2e
curl -i http://127.0.0.1:28080/health

/health answers 200 when the bridge can reach the Docker socket and 503 with the error message when it cannot.


背景

bridge 以 node 用户运行,所用的组 ID 由 scripts/venue.sh 在主机上读取,而这不一定是 socket 在容器内的组。Docker 访问失败时,电源和网络按钮会失败,页面上却看不出原因。另外,场景按钮在条码为空时也能点,通道上也看不出网线是否插着。

改动

  • 新增 scripts/bridge-entrypoint.sh 作为镜像的 ENTRYPOINT:确认 socket 存在,用 stat -c %g 读取它的组,再通过 setpriv --reuid=node --regid=node --groups=<gid> 启动服务。相应地删除 Dockerfile 中的 USER node、compose.devices.yaml 中的 group_add,以及 scripts/venue.sh 在主机上查询 DOCKER_GID 的代码。venue.sh 也不再覆盖 DOCKER_CONFIG 和 DOCKER_HOST,直接沿用主机上的 Docker CLI 设置。
  • bridge/src/docker.ts:错误信息改为 Docker API <status>: <message>,新增 socketHealth(),通过 /_ping 检查连通性。
  • bridge/src/server.ts:启动时检查 socket,每份快照都带上 docker 状态;Docker 不可用时 /health 返回 503;操作成功记为 action 事件;失败时除了发给浏览器,还会写入控制台和事件列表。
  • web/src/main.tsx:每条通道显示 Network cable plugged|unplugged,页头显示 Docker socket 状态信息;场景条码为空时禁用 Two gates at once、All gates at once、Scan again 和 Start burst;点击票据按钮时也会填入该输入框。
  • 测试:bridge/test/docker.test.ts 新增 reports Docker API status and message from an inaccessible socket;web/test/lane.test.tsx 检查网线标签;e2e/entrance.spec.ts 检查网线标签和被禁用的场景按钮。

怎么验证

pnpm test
pnpm build
PORT=28080 DEVICE_PORT=7600 node bridge/dist/server.js &
node scripts/fake-gates.mjs &
pnpm test:e2e
curl -i http://127.0.0.1:28080/health

bridge 能访问 Docker socket 时 /health 返回 200,不能访问时返回 503 并附带错误信息。

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Author

Ingrid Larsen · reviewer

Without USER node the container starts as root. Is root only used by the entrypoint?


去掉 USER node 后容器会以 root 启动。root 只在入口脚本里用到吗?

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Author

Mateo Rossi · author

Yes. The entrypoint only checks the socket and reads its group, then execs the server through setpriv as node with that supplementary group. The Node process never runs as root.


是的。入口脚本只检查 socket、读取它的组,然后通过 setpriv 以带该附加组的 node 用户 exec 服务进程。Node 进程本身从不以 root 运行。

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Author

Noah Williams · reviewer

Start burst is now disabled until the scenario barcode is filled, but a burst scans from the ticket list. Intended?


Start burst 现在要等场景条码填好才能点,可批量扫码用的是票据列表。这是有意的吗?

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Author

Mateo Rossi · author

It keeps the four scenario buttons behind the same field for now. The burst itself still cycles through tickets and ignores the barcode.


目前是让四个场景按钮都依赖同一个输入框。批量扫码本身仍然轮流使用 tickets,不使用这个条码。

@TN019
TN019 merged commit 762d9e7 into main Dec 1, 2026
1 check failed
@TN019
TN019 deleted the fix/docker-access-and-status branch December 1, 2026 00:14
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.

1 participant