portal/Dockerfile

79 lines
2.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# =======================================================
# Global ARGs — 必须在所有 FROM 之前声明
# =======================================================
ARG NODE_BUILDER_IMAGE=node:22-bookworm
ARG NODE_RUNTIME_IMAGE=node:22-slim
# -------------------------------------------------------
# Stage 1 — Builder (Turbopack + standalone)
# -------------------------------------------------------
FROM ${NODE_BUILDER_IMAGE} AS builder
WORKDIR /app/dashboard
ENV NEXT_TELEMETRY_DISABLED=1 \
NEXT_PRIVATE_TURBOPACK=1
# ---------------------------
# 基础镜像升级到最新
# ---------------------------
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl git \
&& apt-get upgrade -y \
&& rm -rf /var/lib/apt/lists/* \
&& corepack enable \
&& corepack prepare yarn@4.12.0 --activate
COPY . .
RUN rm -rf src/content/blog/* \
&& mkdir -p src/content/blog
RUN find . -name "package-lock.json" -delete
RUN yarn install --immutable
RUN yarn next build
# -------------------------------------------------------
# Stage 2 — Runtime (极致瘦身)
# -------------------------------------------------------
FROM ${NODE_RUNTIME_IMAGE} AS runner
WORKDIR /app/dashboard/
ENV NODE_ENV=production \
RUNTIME_ENV=prod \
REGION=cn \
PORT=3000
# ---------------------------
# 安装 tini修复子进程 + 更快退出)
# 基础镜像升级到最新
# ---------------------------
RUN apt-get update \
&& apt-get install -y --no-install-recommends tini ca-certificates \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends --only-upgrade libpam-modules libpam-modules-bin libpam-runtime libpam0g zlib1g \
&& rm -rf /var/lib/apt/lists/*
# ---------------------------
# 导入 standalone 的运行产物
# ---------------------------
COPY --from=builder /app/dashboard/.next/standalone ./
COPY --from=builder /app/dashboard/.next/static ./static
COPY --from=builder /app/dashboard/public ./public
COPY --from=builder /app/dashboard/src/content/blog ./src/content/blog
# ---------------------------
# 额外瘦身(可减少 1540 MB
# ---------------------------
#RUN rm -rf node_modules/next/dist/compiled/@vercel/og/* \
# && rm -rf node_modules/sharp/vendor/* \
# && find node_modules -name "*.md" -delete \
# && find node_modules -name "*.map" -delete
# (如果 Edge Runtime 里用不到 font/SWC 也可移除,比现在更狠)
EXPOSE 3000
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "server.js"]