添加 部署文件
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# ==================== 第一阶段:构建 ====================
|
||||
FROM node:20-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
|
||||
|
||||
# 拷贝源码并构建
|
||||
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;"]
|
||||
Reference in New Issue
Block a user