- Add cleanup-chromium.sh script for manual zombie process cleanup - Add docker-entrypoint.sh with signal handlers for graceful shutdown - Add lib/process-cleanup.ts for automatic cleanup on app termination - Enhanced forceCleanup() method in tradingview-automation.ts: - Individual page closing before browser termination - Force kill remaining processes with SIGKILL - Reset operation locks after cleanup - Improved browser launch args to prevent zombie processes: - Better crash reporter handling - Enhanced background process management - Removed problematic --single-process flag - Updated Dockerfile to use new entrypoint with cleanup handlers - Set DOCKER_ENV environment variable for container detection - Add proper signal handling (SIGINT, SIGTERM, SIGQUIT) - Automatic cleanup of temporary Puppeteer profiles Resolves zombie Chromium process accumulation issue
88 lines
2.1 KiB
Docker
88 lines
2.1 KiB
Docker
# Dockerfile for Next.js 15 + Puppeteer/Chromium + Prisma + Tailwind + OpenAI
|
|
FROM node:20-slim
|
|
|
|
# Use build arguments for CPU optimization
|
|
ARG JOBS=8
|
|
ARG NODE_OPTIONS="--max-old-space-size=4096"
|
|
|
|
# Set environment variables for parallel builds
|
|
ENV JOBS=${JOBS}
|
|
ENV NODE_OPTIONS=${NODE_OPTIONS}
|
|
ENV npm_config_jobs=${JOBS}
|
|
|
|
# Install system dependencies for Chromium
|
|
RUN apt-get update && apt-get install -y \
|
|
wget \
|
|
ca-certificates \
|
|
fonts-liberation \
|
|
libappindicator3-1 \
|
|
libasound2 \
|
|
libatk-bridge2.0-0 \
|
|
libatk1.0-0 \
|
|
libcups2 \
|
|
libdbus-1-3 \
|
|
libdrm2 \
|
|
libgbm1 \
|
|
libnspr4 \
|
|
libnss3 \
|
|
libx11-xcb1 \
|
|
libxcomposite1 \
|
|
libxdamage1 \
|
|
libxrandr2 \
|
|
xdg-utils \
|
|
libxss1 \
|
|
libgconf-2-4 \
|
|
libxtst6 \
|
|
libxrandr2 \
|
|
libasound2 \
|
|
libpangocairo-1.0-0 \
|
|
libgdk-pixbuf2.0-0 \
|
|
libgtk-3-0 \
|
|
libxshmfence1 \
|
|
--no-install-recommends && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Chromium (Debian 12+ uses 'chromium' instead of 'chromium-browser')
|
|
RUN apt-get update && apt-get install -y \
|
|
chromium \
|
|
--no-install-recommends && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files and install dependencies
|
|
COPY package.json package-lock.json* pnpm-lock.yaml* yarn.lock* .npmrc* ./
|
|
|
|
# Install dependencies with maximum parallelism
|
|
RUN npm config set maxsockets 8 && \
|
|
npm config set fetch-retries 3 && \
|
|
npm ci --no-audit --no-fund --prefer-offline
|
|
|
|
# Copy the rest of the app
|
|
COPY . .
|
|
|
|
# Generate Prisma client
|
|
RUN npx prisma generate
|
|
|
|
# Build the Next.js application for production
|
|
RUN npm run build
|
|
|
|
# Fix permissions for node_modules binaries
|
|
RUN chmod +x node_modules/.bin/*
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Copy startup script
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# Set environment variables for Puppeteer
|
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
|
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
|
ENV DOCKER_ENV=true
|
|
|
|
# Start the app with cleanup handlers
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|