# 构建阶段
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:22-alpine AS build
WORKDIR /app

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

RUN yarn config set registry https://registry.npmmirror.com && \
    yarn config set network-timeout 60000

COPY package*.json yarn.lock ./
RUN yarn install --frozen-lockfile

COPY . .

# 使用环境变量 + 构建命令
ENV NEXT_DISABLE_ESLINT=1
RUN yarn build --no-lint

# 部署阶段
FROM crpi-jlsdxetsdmy4ckxh.cn-shenzhen.personal.cr.aliyuncs.com/zsq_proxy/node:22-alpine AS production
WORKDIR /app

ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=4096"

COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/node_modules ./node_modules

EXPOSE 3002

CMD ["yarn", "start"]