This commit is contained in:
Daniel
2026-03-04 00:39:01 +08:00
parent 95e2fe1c41
commit 3264b3252a
8 changed files with 152 additions and 17 deletions

View File

@@ -1,11 +1,23 @@
# 仅后端 API 镜像(前端自行部署
# 前端 + 后端合一镜像:构建阶段产出 dist运行阶段提供静态与 API含修订页 /edit
# 国内服务器拉取慢时,可加 --build-arg REGISTRY=docker.m.daocloud.io/library
ARG REGISTRY=
# ---------- 阶段 1构建前端 ----------
FROM ${REGISTRY}node:20-slim AS frontend-builder
WORKDIR /app
RUN npm config set registry https://registry.npmmirror.com
COPY package*.json ./
RUN npm ci
COPY vite.config.ts index.html tsconfig.json tsconfig.app.json ./
COPY postcss.config.js tailwind.config.js ./
COPY src ./src
RUN npm run build
# ---------- 阶段 2运行API + 静态) ----------
FROM ${REGISTRY}node:20-slim
RUN npm config set registry https://registry.npmmirror.com
# Debian 12 使用 sources.list.d改为国内源避免 build 时连接超时
RUN rm -f /etc/apt/sources.list.d/debian.sources && \
echo 'deb http://mirrors.aliyun.com/debian bookworm main' > /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian bookworm-updates main' >> /etc/apt/sources.list && \
@@ -13,13 +25,11 @@ RUN rm -f /etc/apt/sources.list.d/debian.sources && \
apt-get update && apt-get install -y --no-install-recommends python3 make g++ && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY server ./server
COPY --from=frontend-builder /app/dist ./dist
ENV NODE_ENV=production
ENV API_PORT=3001