File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11FROM node:lts-bookworm-slim
22
3+ # 安装必要的系统依赖
4+ RUN apt-get update && apt-get install -y \
5+ curl \
6+ wget \
7+ gnupg \
8+ && rm -rf /var/lib/apt/lists/*
9+
310WORKDIR /app
411
12+ # 复制 package 文件
13+ COPY package*.json ./
14+ COPY tsconfig.json ./
15+
16+ # 安装所有依赖(包括开发依赖,用于构建)
17+ # 跳过 postinstall 脚本(避免过早安装 Playwright)
18+ RUN npm ci --ignore-scripts
19+
20+ # 复制源代码
521COPY . .
622
7- RUN npm install \
8- && npm run build \
9- && npx playwright install --with-deps chromium \
10- && apt-get clean \
11- && npm prune --omit=dev \
12- && npm cache clean --force \
13- && rm -rf /var/lib/apt/lists/* \
14- && rm -rf /var/cache/apt/*
23+ # 单独构建项目(不运行 prepare 脚本)
24+ RUN npm run prebuild && npm run build
25+
26+ # 安装 Playwright,增加重试和更好的错误处理
27+ RUN for i in 1 2 3; do \
28+ echo "Attempt $i: Installing Playwright..." && \
29+ npx playwright install --with-deps chromium && break || \
30+ if [ $i -eq 3 ]; then \
31+ echo "Failed to install Playwright after 3 attempts" && exit 1; \
32+ fi && \
33+ echo "Attempt $i failed, retrying in 30 seconds..." && \
34+ sleep 30; \
35+ done
36+
37+ # 清理缓存和不需要的文件
38+ RUN npm prune --omit=dev && \
39+ apt-get clean && \
40+ npm cache clean --force && \
41+ rm -rf /var/lib/apt/lists/* && \
42+ rm -rf /var/cache/apt/* && \
43+ rm -rf /tmp/*
1544
16- CMD ["node" , "build/index.js" ]
45+ CMD ["node" , "build/index.js" ]
You can’t perform that action at this time.
0 commit comments