diff --git a/.dockerignore b/.dockerignore index 03da613..a7d0b6f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ # node_modules 与产物 node_modules frontend/node_modules -frontend/dist backend/node_modules backend/data manager-data diff --git a/Dockerfile b/Dockerfile index cb59edc..ea0000b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,21 @@ -# ============ 阶段一:构建前端(Vue3 + Vite) ============ -FROM node:18-slim AS frontend-build -WORKDIR /build -RUN corepack enable -COPY frontend/package.json frontend/pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile -COPY frontend/ ./ -RUN pnpm build - -# ============ 阶段二:运行时(Express + better-sqlite3) ============ -FROM node:18-slim +# 本地已构建好 frontend/dist,镜像内无需 pnpm/corepack/构建工具链 +FROM --platform=linux/amd64 node:18-slim ENV NODE_ENV=production \ PORT=3000 \ - DATA_DIR=/app/data + DATA_DIR=/app/data \ + npm_config_registry=https://registry.npmmirror.com WORKDIR /app -RUN corepack enable -# 后端依赖(better-sqlite3 在 node:18 有预编译二进制,无需编译工具链) -COPY backend/package.json backend/pnpm-lock.yaml ./ -RUN pnpm install --prod --frozen-lockfile +# 后端依赖:仅 express + better-sqlite3(node:18 有预编译二进制) +COPY backend/package.json ./ +RUN npm install --production COPY backend/ ./ -# 前端产物托管在 /frontend/dist(server.js 中 distDir 指向 ../frontend/dist) -COPY --from=frontend-build /build/dist /frontend/dist +# 前端产物(本地构建好的 dist) +COPY frontend/dist /frontend/dist -# 非 root 运行(§3.7 安全:UID 10000) +# 非 root 运行 RUN mkdir -p /app/data && chown -R 10000:10000 /app/data USER 10000:10000