refactor(docker): 优化Docker构建流程

- 简化多阶段构建结构
- 移除不必要的注释和空行
- 更新基础镜像为node:latest
- 调整工作目录创建方式
- 合并git克隆和依赖安装步骤
- 修改构建命令执行顺序
- 清理nginx html目录内容
- 调整文件复制路径逻辑
This commit is contained in:
coolxitech
2025-12-13 12:02:43 +08:00
parent 9986a05d44
commit 90f18952ec

View File

@@ -1,33 +1,24 @@
# ========= 阶段1构建 ========= FROM node:latest AS builder
FROM node:20-alpine AS builder
WORKDIR /app RUN mkdir -p /workspace
WORKDIR /workspace
# 使用国内镜像加速(可选但强烈建议)
RUN npm config set registry https://registry.npmmirror.com RUN npm config set registry https://registry.npmmirror.com
# 直接用 npm 全局安装 pnpm最稳最快 RUN cd /workspace
RUN npm install -g pnpm
# 复制依赖文件先缓存 RUN git clone https://github.com/setube/ogame-vue-ts.git
COPY package.json pnpm-lock.yaml ./
# 安装依赖 RUN mv ./ogame-vue-ts/* . ; rm -rf ./ogame-vue-ts/
RUN pnpm install --frozen-lockfile
# 复制源码并构建 RUN npm install -g pnpm ; pnpm install ; npx vite build
COPY . .
RUN pnpm run build
# ========= 阶段2运行时 =========
FROM nginx:alpine FROM nginx:alpine
# 复制构建产物 RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /app/dist /usr/share/nginx/html
# 解决 Vue Router history 模式 404 问题 COPY --from=builder /workspace/docs /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]