# 构建阶段
FROM registry.cn-hangzhou.aliyuncs.com/wehome-base/node:20-alpine as builder

# 设置 pnpm 源为 npmmirror
RUN npm install -g pnpm --registry=https://registry.npmmirror.com
RUN pnpm config set registry https://registry.npmmirror.com

WORKDIR /app

# 复制项目文件
COPY package.json pnpm-lock.yaml ./

# 安装依赖
RUN pnpm install
RUN pnpm install @tarojs/binding-linux-x64-musl

# 复制源代码
COPY . .

# 构建项目
RUN pnpm build:h5

# 生产阶段
FROM registry.cn-hangzhou.aliyuncs.com/wehome-base/nginx:latest

# 创建必要的目录
RUN mkdir -p /usr/share/nginx/app/dist

# 删除默认的 nginx 配置
RUN rm -rf /etc/nginx/nginx.conf

# 复制自定义的 nginx 配置
COPY ./nginx.conf /etc/nginx/nginx.conf

# 从构建阶段复制构建好的文件
COPY --from=builder /app/dist /usr/share/nginx/app/dist

# 暴露端口
EXPOSE 10000
