This commit is contained in:
2026-01-25 20:12:33 +08:00
parent 3c3868e2a7
commit fd7cb4485c
364 changed files with 66196 additions and 0 deletions

56
Dockerfile Normal file
View File

@@ -0,0 +1,56 @@
# 多阶段构建 - 前端 Dockerfile
# 阶段 1: 构建阶段
FROM node:20-alpine AS builder
# 设置工作目录
WORKDIR /app
# 配置 npm 国内镜像
RUN npm config set registry https://registry.npmmirror.com
# 复制 package 文件
COPY package*.json ./
# 安装所有依赖(包括 devDependencies
RUN npm ci
# 复制源代码
COPY . .
# 构建生产版本
RUN npm run build
# 阶段 2: 运行阶段
FROM nginx:alpine
# 配置 Alpine 国内镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装 tzdata 用于时区设置
RUN apk --no-cache add tzdata
# 设置时区为上海
ENV TZ=Asia/Shanghai
# 删除默认的 nginx 配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/
# 从构建阶段复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 创建非 root 用户nginx 已经有了,但我们确保权限正确)
RUN chown -R nginx:nginx /usr/share/nginx/html && \
chmod -R 755 /usr/share/nginx/html
# 暴露端口
EXPOSE 2613
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:2613/ || exit 1
# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]