Files
2026-11-03 13:21:28 +08:00

48 lines
1.5 KiB
Docker
Raw Permalink 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.
# ---- 构建阶段:由 data/ + templates/ 生成静态站点 ----
FROM node:22-alpine AS build
WORKDIR /app
# 跳过 Playwright 浏览器下载(构建无需浏览器)
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
# 国内镜像安装依赖(CI runner 在阿里云);pnpm 版本与本地生成 lockfile 的一致
RUN npm install -g pnpm@11.28.5 --registry=https://registry.npmmirror.com
COPY package.json pnpm-lock.yaml .npmrc ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN node scripts/build.mjs && node scripts/check.mjs
# ---- PDF 阶段(仅构建期中间依赖:Chromium + 微软雅黑,产出 dist/pdf/)----
FROM node:22-alpine AS pdf
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache chromium fontconfig
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
CHROMIUM_PATH=/usr/bin/chromium
# 微软雅黑字库(仅本阶段使用,不进入最终镜像)
COPY assets/fonts/ /usr/share/fonts/yahei/
RUN fc-cache -f
WORKDIR /app
COPY package.json ./
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY scripts/ scripts/
COPY data/ data/
RUN node scripts/pdf.mjs
# ---- 运行阶段:Nginx 托管 dist/(干净镜像:无 Chromium/字体/Node) ----
FROM nginx:alpine
# 复制 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 复制构建产物(HTML + txt + css + img + pdf)
COPY --from=pdf /app/dist/ /usr/share/nginx/html/
# 暴露端口
EXPOSE 80
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]