fix(docker): prevent backend crash loop caused by pdf-parse native deps
pdf-parse@2.4.5 pulls in @napi-rs/canvas (native Skia binary) which crashes on import in Alpine containers. Moved to lazy require() so the app starts normally and pdf-parse loads only when PDF conversion is actually requested. - Lazy-load pdf-parse in pdfToStatement to avoid startup crash - Add libc6-compat, fontconfig, freetype to Alpine runner stage - Increase npm fetch timeouts in both Dockerfiles for slow networks - Add connectionTimeoutMillis to pg Pool for faster failure detection
This commit is contained in:
@@ -5,6 +5,11 @@ COPY package.json package-lock.json* ./
|
||||
COPY shared ./shared
|
||||
COPY backend ./backend
|
||||
|
||||
# Увеличенные таймауты для нестабильной сети
|
||||
RUN npm config set fetch-retry-mintimeout 20000 && \
|
||||
npm config set fetch-retry-maxtimeout 120000 && \
|
||||
npm config set fetch-timeout 300000
|
||||
|
||||
RUN npm install
|
||||
|
||||
FROM node:20-alpine AS build
|
||||
@@ -22,6 +27,10 @@ FROM node:20-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# @napi-rs/canvas (dep of pdf-parse) ships a musl pre-built binary that
|
||||
# needs these compatibility / font libraries at runtime.
|
||||
RUN apk add --no-cache libc6-compat fontconfig freetype
|
||||
|
||||
COPY --from=build /app/backend/dist ./dist
|
||||
COPY --from=build /app/backend/package.json ./package.json
|
||||
COPY --from=build /app/node_modules ./node_modules
|
||||
|
||||
Reference in New Issue
Block a user