From 72722ab6bf89223239604a39b2750d5c766e199c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=93=B6=E5=86=9B?= Date: Sat, 19 Sep 2026 17:00:12 +0800 Subject: [PATCH] =?UTF-8?q?build:=20Dockerfile=20=E6=94=B9=E5=8D=95?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=EF=BC=88=E6=9C=AC=E5=9C=B0=20dist=20+=20npm?= =?UTF-8?q?=20=E8=A3=85=E4=BE=9D=E8=B5=96=EF=BC=89=EF=BC=8C=E9=94=81?= =?UTF-8?q?=E5=AE=9A=20linux/amd64=20=E9=80=82=E9=85=8D=E7=BB=BF=E8=81=94?= =?UTF-8?q?=20NAS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - Dockerfile | 29 ++++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) 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