Skip to content

[Enhance Request] 镜像瘦身 #1252

Description

@john5du

背景

当前 ghcr.io/ding113/claude-code-hub:latest amd64 镜像压缩层约 226MB。初步分析后,主要体积来源不是基础镜像,而是 Next.js standalone 运行产物及重复复制的构建目录。

可选瘦身方案

1. 移除重复复制的 .next/server

deploy/Dockerfile 当前复制了 .next/standalone,之后又额外复制完整 .next/server。远端镜像层分析显示,.next/server 额外复制层约 45MB 压缩体积,且 .next/standalone 内已经包含部分 server 产物。

预期收益:约 45MB 压缩体积,优先级最高。

风险:需验证 Server Actions、App Router 页面、API routes 是否仍正常。

2. 清理生产运行不需要的 sourcemap / trace 文件

.next/server 中包含大量 .js.map.nft.json 文件。运行时通常不需要 sourcemap,.nft.json 也主要用于 tracing、debug、build 分析。

预期收益:可能减少几十 MB,需实际 build 后验证。

风险:错误栈可读性下降;若某些运行时逻辑依赖 .nft.json,需要排查。

3. 收窄 next.config.ts 中的 tracing includes

当前 outputFileTracingIncludes 手动包含了:

"./node_modules/next/dist/**/*"

本地 node_modules/next/dist 未压缩约 168MB,可能导致 standalone 产物过大。可以改为只包含自定义 server 实际需要的 Next runtime 文件,而不是整个 next/dist

预期收益:潜在收益较大,可能为几十 MB。

风险:需要仔细验证自定义 server.js、WebSocket、Next programmatic API 是否完整可用。

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions