chore: 优化 Docker 构建以适配中国服务器网络环境
- apt-get 切换阿里云镜像(http://),解决 slim 镜像无 ca-certificates 的 https 问题 - pnpm 切换 npmmirror 注册源,加速依赖下载 - 修复 better-sqlite3 编译:hoisted 模式、onlyBuiltDependencies、显式 rebuild - 新增 mkdir -p data 避免容器启动时数据目录缺失 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17
Dockerfile
17
Dockerfile
@@ -2,7 +2,7 @@ FROM node:22-slim AS frontend
|
||||
RUN corepack enable pnpm
|
||||
WORKDIR /app/web
|
||||
COPY web/package.json ./
|
||||
RUN pnpm install
|
||||
RUN pnpm config set registry https://registry.npmmirror.com && pnpm install
|
||||
COPY web/ ./
|
||||
RUN pnpm run build
|
||||
|
||||
@@ -10,14 +10,27 @@ FROM node:22-slim AS production
|
||||
RUN corepack enable pnpm
|
||||
WORKDIR /app
|
||||
|
||||
# Switch to Aliyun mirror for faster apt downloads in China
|
||||
RUN sed -i \
|
||||
-e 's|http://deb.debian.org|http://mirrors.aliyun.com|g' \
|
||||
-e 's|http://security.debian.org|http://mirrors.aliyun.com|g' \
|
||||
/etc/apt/sources.list.d/debian.sources
|
||||
|
||||
# Build tools needed to compile better-sqlite3 native addon
|
||||
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY server/package.json ./server/
|
||||
WORKDIR /app/server
|
||||
RUN pnpm install --prod
|
||||
# hoisted mode: flat node_modules so native addons (better-sqlite3) can locate their .node files
|
||||
# pnpm v10 blocks build scripts by default; onlyBuiltDependencies allows better-sqlite3 to compile,
|
||||
# and explicit rebuild ensures the native addon is built even if install skipped it.
|
||||
RUN echo "node-linker=hoisted" > .npmrc && \
|
||||
pnpm config set registry https://registry.npmmirror.com && \
|
||||
pnpm install --prod && \
|
||||
pnpm rebuild better-sqlite3
|
||||
|
||||
COPY server/ ./
|
||||
RUN mkdir -p data
|
||||
COPY --from=frontend /app/web/dist /app/web/dist
|
||||
|
||||
EXPOSE 3456
|
||||
|
||||
Reference in New Issue
Block a user