FROM node:16-alpine AS builder

WORKDIR /app

# 安装HBuilderX（使用最新稳定版链接，避免alpha版过期）
RUN apk add --no-cache wget unzip \
    && wget https://download.dcloud.net.cn/hbuilderx/latest/HBuilderX.4.0.14.20240425.full.zip -O hbx.zip \
    && unzip hbx.zip -d /opt/hbuilderx \
    && chmod +x /opt/hbuilderx/cli  # 确保cli可执行

# 复制项目文件
COPY . .

# 使用HBuilderX CLI构建H5项目
RUN /opt/hbuilderx/cli publish --platform h5 --project . --outDir dist

# 生产环境
FROM nginx:1.21-alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 8333
CMD ["nginx", "-g", "daemon off;"]
