66 lines
1.6 KiB
Docker
66 lines
1.6 KiB
Docker
# ============================================
|
|
# 构建阶段 - 使用本地私有仓库镜像
|
|
# ============================================
|
|
FROM localhost:15000/base/node:18-alpine AS builder
|
|
|
|
# 设置时区
|
|
ENV TZ=Asia/Shanghai
|
|
RUN apk add --no-cache tzdata && \
|
|
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
|
|
echo $TZ > /etc/timezone
|
|
|
|
# 启用 pnpm
|
|
RUN corepack enable && corepack prepare [email protected] --activate
|
|
|
|
WORKDIR /app
|
|
|
|
# 安装构建依赖
|
|
RUN apk add --no-cache python3 make g++ git
|
|
|
|
# 复制依赖文件(利用缓存)
|
|
COPY package.json pnpm-lock.yaml .npmrc pnpm-workspace.yaml ./
|
|
COPY packages/ ./packages/
|
|
COPY tsconfig.json vite.config.ts ./
|
|
|
|
# 安装依赖
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# 复制源代码
|
|
COPY . .
|
|
|
|
# 生产构建
|
|
ENV NODE_ENV=production
|
|
RUN pnpm run build
|
|
|
|
# ============================================
|
|
# 生产阶段 - 使用 nginx
|
|
# ============================================
|
|
FROM localhost:15000/base/nginx:alpine
|
|
|
|
# 设置时区
|
|
ENV TZ=Asia/Shanghai
|
|
RUN apk add --no-cache tzdata curl && \
|
|
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
|
|
echo $TZ > /etc/timezone
|
|
|
|
# 复制构建产物
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
|
|
# 复制 nginx 配置
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# 设置权限
|
|
RUN chown -R nginx:nginx /usr/share/nginx/html && \
|
|
chmod -R 755 /usr/share/nginx/html
|
|
|
|
EXPOSE 80
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
|
CMD curl -f http://localhost/ || exit 1
|
|
|
|
# 使用非 root 用户运行
|
|
USER nginx
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|