Skip to content

feat(server): add REST API + Docker for light-ocr#24

Closed
chatre7 wants to merge 9 commits into
arcships:mainfrom
chatre7:feat/rest-api-docker
Closed

feat(server): add REST API + Docker for light-ocr#24
chatre7 wants to merge 9 commits into
arcships:mainfrom
chatre7:feat/rest-api-docker

Conversation

@chatre7

@chatre7 chatre7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a standalone Node.js/Express REST API server (server/) wrapping the published @arcships/light-ocr npm package: GET /health, GET /info, POST /ocr (multipart image upload)
  • Add a single-stage server/Dockerfile (node:22-trixie-slim — verified node:22-slim's glibc 2.36 is too old for the native addon, which needs 2.38+) and a root docker-compose.yml
  • Execution mode (cpu/auto/webgpu), queue capacity, and port are configurable via env vars; graceful shutdown drains the engine on SIGTERM/SIGINT
  • Design doc: docs/superpowers/specs/2026-07-21-rest-api-docker-design.md
  • Implementation plan: docs/superpowers/plans/2026-07-21-rest-api-docker.md

This is additive only — no changes to bindings/node or the C++ core.

Test plan

  • npm test in server/ — 15/15 tests pass (node --test), including a real POST /ocr recognition of docs/assets/benchmark-generated-hello-123.png ("HELLO 123", 98.9% confidence)
  • docker build -f server/Dockerfile -t light-ocr-api . succeeds
  • docker run + curl /health, curl /info, curl -F image=@... /ocr all verified working against the built image
  • docker stop verified graceful shutdown (exit code 0)

🤖 Generated with Claude Code

chatre7 and others added 9 commits July 21, 2026 11:13
Design a standalone Express server under server/ that wraps the
published @arcships/light-ocr npm package and a single-stage Dockerfile
that runs it, so the OCR engine can be called over HTTP.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Pin @arcships/light-ocr to an exact version, tag Docker images by the
server's own version, and document the manual update process.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Six-task TDD plan: error mapping, engine lifecycle wrapper, health/info
endpoints, POST /ocr, graceful shutdown, and Dockerfile/compose/docs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Verified with a real docker build/run/curl cycle: node:22-slim's glibc
2.36 is too old for the native addon (needs 2.38+), so the base image
is node:22-trixie-slim instead. Spec and plan docs updated to match.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@eric8810

Copy link
Copy Markdown
Contributor

感谢提交这个 PR,server-side OCR 服务是一个真实的需求场景,实现质量也很扎实。

我们刚更新了 Roadmap 并新增了 Monorepo 设计文档(见 #26),明确了 @arcships/light-ocr-server 的产品定位和工程路径。总结一下对 PR #24 的影响:

设计共识

  • @arcships/light-ocr-server 已作为可选部署制品加入 Roadmap §3.1,定位是 HTTP REST API + Docker 镜像,不替代 CLI 作为本地入口。
  • server 的开发和分发需要 monorepo 结构(设计文档)。Monorepo 迁移计划在 N2(runtime 提取)启动时执行,当前 N1(CLI)施工中,不动仓库结构。
  • 在 monorepo 就绪前,server 作为独立仓库存在(如 light-ocr-server),引用已发布的 @arcships/light-ocr

对你的 PR 的具体影响

代码结构和实现思路完全可用,需要调整的主要是放置位置

  1. light-ocr/server/ 迁移到独立仓库 light-ocr-server/。短期方案——等 monorepo 就绪后,代码会回归到 packages/light-ocr-server/
  2. server/package.json 的包名保持 @arcships/light-ocr-server,精确锁定 @arcships/light-ocr 版本。
  3. Dockerfile、错误映射、graceful shutdown、测试 的实现逻辑不变。唯一需要注意的是测试图片引用——独立仓库需要自带 test fixture 或用公开 URL,不能依赖 docs/assets/ 下的文件。
  4. 根目录 .gitignore 不需要改动——独立仓库有自己的 .gitignore
  5. 根目录 docker-compose.yml 暂时放在独立仓库——等 monorepo 后统一放置。

建议

  • 把这个 PR 的目标改为你个人的 light-ocr-server 仓库
  • 关闭当前指向 arcships/light-ocr main 分支的 PR
  • 等 monorepo 迁移完成后(预计 N2 阶段),用 workspace 结构重新提 PR 到 packages/light-ocr-server/

如果你愿意按这个方向调整,我可以帮忙 review 独立仓库版本。

chatre7 added a commit to chatre7/light-ocr-server that referenced this pull request Jul 21, 2026
Standalone repo per arcships/light-ocr#24 review feedback: server
deployment artifacts live here until the light-ocr monorepo migration
(N2 phase) lands, at which point this moves to packages/light-ocr-server/.

GET /health, GET /info, POST /ocr (multipart image upload) backed by
one shared @arcships/light-ocr engine instance. Single-stage Dockerfile
(node:22-trixie-slim - glibc 2.36 in node:22-slim is too old for the
native addon, which needs 2.38+). Graceful shutdown drains the engine
on SIGTERM/SIGINT.

15/15 tests pass (node --test); docker build/run/curl verified locally
against a real image, including graceful `docker stop`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chatre7

chatre7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed guidance — makes sense. I've moved the implementation to a standalone repo per your suggestion:

https://github.com/chatre7/light-ocr-server

Changes from this PR's version:

  • Package renamed to @arcships/light-ocr-server, still pins @arcships/light-ocr to an exact version
  • Same Dockerfile, error mapping, graceful shutdown, and test suite (15/15 passing, docker build/run/curl verified)
  • Test fixture is now bundled in the new repo (test/fixtures/hello-123.png) instead of referencing docs/assets/ from this repo
  • Root .gitignore here is unaffected; the new repo has its own

Closing this PR — will resubmit against packages/light-ocr-server/ once the monorepo migration reaches N2, per your note.

@chatre7 chatre7 closed this Jul 21, 2026
eric8810 added a commit that referenced this pull request Jul 22, 2026
Migrate the REST and Docker implementation promised by PR #24 into the N2 workspace while keeping its package private at 0.1.0.

Bound uploads before buffering, preserve OcrError semantics, support Linux x64 and arm64 images, and route workspace checks away from the full Core CI job.

Co-authored-by: chatre7 <chatree.yosnak@gmail.com>
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