36 lines
954 B
Docker
36 lines
954 B
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# ==================== 第一阶段:构建 ====================
|
|
FROM node:22-alpine AS builder
|
|
WORKDIR /build
|
|
|
|
# 安装 pnpm
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
# 先拷贝依赖声明,利用 Docker 层缓存
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
RUN pnpm install --frozen-lockfile --config.confirmModulesPurge=false
|
|
|
|
# 拷贝源码并构建
|
|
COPY . .
|
|
RUN pnpm build
|
|
|
|
# ==================== 第二阶段:Nginx serve 静态文件 ====================
|
|
FROM nginx:alpine
|
|
|
|
ENV TZ=Asia/Shanghai
|
|
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
|
|
|
# 拷贝构建产物
|
|
COPY --from=builder /build/dist /usr/share/nginx/html
|
|
|
|
# SPA history mode 配置
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
EXPOSE 80
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
|
CMD wget --spider -q http://localhost/ || exit 1
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|