FROM node:20.10.0-slim

WORKDIR /app

# 安装 Chrome 运行依赖
RUN apt-get update && apt-get install -y \
    ca-certificates \
    fonts-liberation \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libc6 \
    libcairo2 \
    libcups2 \
    libdbus-1-3 \
    libexpat1 \
    libfontconfig1 \
    libgbm1 \
    libgcc1 \
    libglib2.0-0 \
    libgtk-3-0 \
    libnspr4 \
    libnss3 \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libstdc++6 \
    libx11-6 \
    libx11-xcb1 \
    libxcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    libxss1 \
    libxtst6 \
    lsb-release \
    wget \
    xdg-utils \
    chromium \
    && rm -rf /var/lib/apt/lists/*
    
# 安装中文字体
RUN apt-get update && apt-get install -y fonts-wqy-microhei && fc-cache -f -v

COPY SPIDER/. .

RUN test -f package.json || (echo "package.json missing" && exit 1)
RUN test -f .env || (echo ".env file missing in SPIDER directory" && exit 1)

RUN npm run build

EXPOSE 3000
CMD ["npm", "start"]