Files
one-pipe-system/Dockerfile
2026-09-20 15:39:56 +08:00

62 lines
1.8 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.
# ================================
# 阶段 1: 构建阶段
# ================================
FROM --platform=linux/amd64 node:20-alpine AS builder
# 使用阿里云镜像源加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
WORKDIR /build
# 安装 pnpm,显式指定镜像源,避免继承开发机不可用的 npm 代理
RUN npm install --global pnpm@10.15.0 --registry=https://registry.npmmirror.com
RUN pnpm config set registry https://registry.npmmirror.com
# 限制 Node 堆,防止前端构建耗尽宿主机内存
ARG NODE_OPTIONS=--max-old-space-size=1536
ENV NODE_OPTIONS=${NODE_OPTIONS}
# 复制 package.json 和 pnpm-lock.yaml(利用 Docker 缓存)
COPY package.json pnpm-lock.yaml ./
# 安装依赖
RUN pnpm install --frozen-lockfile
# 复制源代码
COPY . .
# 构建生产版本(跳过类型检查,直接构建)
RUN pnpm run nd
# ================================
# 阶段 2: 运行阶段
# ================================
FROM --platform=linux/amd64 nginx:1.31.2-alpine
# 使用阿里云镜像源加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 设置时区
RUN apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
# 删除默认 nginx 配置
RUN rm -rf /etc/nginx/conf.d/default.conf
# 复制自定义 nginx 配置
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
# 从构建阶段复制构建产物
COPY --from=builder /build/dist /usr/share/nginx/html
# 暴露端口
EXPOSE 80
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:80/health || exit 1
# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]