# Build stage FROM node:20-slim AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm install # Copy source code COPY . . # Build TypeScript RUN npm run build # Production stage FROM node:20-slim AS production WORKDIR /app # Install Chromium dependencies for Puppeteer RUN apt-get update && apt-get install -y \ chromium \ fonts-liberation \ libasound2 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libgbm1 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libx11-xcb1 \ libxcomposite1 \ libxdamage1 \ libxfixes3 \ libxrandr2 \ libxss1 \ xdg-utils \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/* # Set Puppeteer to use installed Chromium ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium # Copy package files COPY package*.json ./ # Install production dependencies only RUN npm install --omit=dev # Copy built files from builder COPY --from=builder /app/dist ./dist # Create non-root user RUN groupadd -r nodejs && useradd -r -g nodejs nodejs # Change ownership of app directory RUN chown -R nodejs:nodejs /app USER nodejs # Expose port EXPOSE 3001 # Set environment variables ENV NODE_ENV=production ENV PORT=3001 # Start the application CMD ["node", "dist/index.js"]