# 多阶段构建

# 阶段1：构建前端
FROM node:18-alpine AS builder

WORKDIR /app

# 复制前端代码
COPY ../ui ./ui
WORKDIR /app/ui
RUN npm install && npm run build

# 阶段2：运行服务端
FROM node:18-alpine

WORKDIR /app

# 安装依赖
COPY package*.json ./
RUN npm install --production

# 复制服务端代码
COPY src ./src

# 复制构建好的前端
COPY --from=builder /app/ui/dist-web ./public

# 暴露端口
EXPOSE 3000

# 启动
CMD ["node", "src/index.js"]
