@@ -43,29 +43,46 @@ RUN addgroup --system --gid 1001 nodejs && \
4343COPY --from=builder --chown=bunuser:nodejs /app/package.json ./
4444COPY --from=builder --chown=bunuser:nodejs /app/bun.lock* ./
4545
46- # 🚨 关键优化:在 runner 阶段重新安装生产依赖
47- # 这样可以确保完全没有 devDependencies,并且只安装运行时需要的包
46+ # 🚨 关键优化:只安装生产依赖(已改用程序化迁移,不需要 drizzle-kit)
4847RUN bun install --production --frozen-lockfile
4948
50- # 从 builder 阶段复制编译后的代码
49+ # 从 builder 阶段复制编译后的代码和迁移文件
5150COPY --from=builder --chown=bunuser:nodejs /app/dist ./dist
52-
53- # 🔥 终极清理:删除所有不必要的文件
54- RUN rm -rf /app/node_modules/.cache && \
55- rm -rf /tmp/* && \
56- rm -rf /var/cache/apk/* && \
57- # 🚨 强制删除 TypeScript 及其相关包(生产环境不需要)
58- rm -rf /app/node_modules/typescript && \
59- rm -rf /app/node_modules/@typescript-eslint && \
60- rm -rf /app/node_modules/typescript-eslint && \
61- # 删除测试相关目录
62- find /app/node_modules -type d \( -name "test" -o -name "tests" -o -name "__tests__" -o -name "*.test.*" -o -name "*.spec.*" -o -name "docs" -o -name "doc" -o -name "examples" -o -name "example" -o -name "benchmark" -o -name "benchmarks" \) -exec rm -rf {} + 2>/dev/null || true && \
63- # 删除文档和配置文件
64- find /app/node_modules -type f \( -name "*.md" -o -name "*.map" -o -name "CHANGELOG*" -o -name "LICENSE*" -o -name "README*" -o -name "*.ts" -o -name "*.tsx" -o -name "*.json" ! -name "package.json" \) ! -path "*/node_modules/@types/*" -delete 2>/dev/null || true && \
65- # 删除类型定义文件(运行时不需要)
66- find /app/node_modules -type f -name "*.d.ts" ! -path "*/node_modules/@types/*" -delete 2>/dev/null || true && \
67- # 删除源码文件(只保留编译后的代码)
68- find /app/node_modules -type f \( -name "*.js" ! -name "*.min.js" \) -path "*/src/*" -delete 2>/dev/null || true
51+ COPY --from=builder --chown=bunuser:nodejs /app/drizzle ./drizzle
52+
53+ # 🔥 终极清理:删除所有不必要的文件以减小镜像大小
54+ # 注意:避免删除关键依赖包(如 postgres)的必要文件
55+ RUN rm -rf /app/node_modules/.cache /tmp/* /var/cache/apk/* && \
56+ # 删除测试、文档、示例等目录(排除关键依赖包)
57+ find /app/node_modules -type d \( \
58+ -name "test" -o -name "tests" -o -name "__tests__" -o \
59+ -name "*.test.*" -o -name "*.spec.*" -o \
60+ -name "docs" -o -name "doc" -o \
61+ -name "examples" -o -name "example" -o \
62+ -name "benchmark" -o -name "benchmarks" \
63+ \) ! -path "*/node_modules/postgres/*" \
64+ ! -path "*/node_modules/drizzle-orm/*" \
65+ -exec rm -rf {} + 2>/dev/null || true && \
66+ # 删除文档、源码映射等(排除关键依赖包)
67+ find /app/node_modules -type f \( \
68+ -name "*.md" -o -name "*.map" -o \
69+ -name "CHANGELOG*" -o -name "LICENSE*" -o -name "README*" \
70+ \) ! -path "*/node_modules/postgres/*" \
71+ ! -path "*/node_modules/drizzle-orm/*" \
72+ -delete 2>/dev/null || true && \
73+ # 删除 TypeScript 源文件(但保留 .d.ts 类型定义文件,某些包可能需要)
74+ find /app/node_modules -type f \( \
75+ -name "*.ts" -o -name "*.tsx" \
76+ \) ! -name "*.d.ts" \
77+ ! -path "*/node_modules/@types/*" \
78+ ! -path "*/node_modules/postgres/*" \
79+ ! -path "*/node_modules/drizzle-orm/*" \
80+ -delete 2>/dev/null || true && \
81+ # 删除 package.json 以外的 JSON 配置文件(排除关键依赖包)
82+ find /app/node_modules -type f -name "*.json" ! -name "package.json" ! -path "*/node_modules/@types/*" \
83+ ! -path "*/node_modules/postgres/*" \
84+ ! -path "*/node_modules/drizzle-orm/*" \
85+ -delete 2>/dev/null || true
6986
7087# 设置环境变量,提升性能
7188ENV NODE_ENV=production
0 commit comments