| # Use a specific version of Node for stability | |
| FROM node:18-alpine | |
| # Set the working directory inside the container | |
| WORKDIR /app | |
| # Install git, Chromium, and other dependencies for Puppeteer | |
| RUN apk add --no-cache \ | |
| git \ | |
| chromium \ | |
| nss \ | |
| freetype \ | |
| freetype-dev \ | |
| harfbuzz \ | |
| ca-certificates \ | |
| ttf-freefont | |
| # Copy package.json and package-lock.json first to leverage Docker caching | |
| COPY package*.json ./ | |
| # Install production dependencies | |
| RUN npm install --omit=dev | |
| # Install PM2 globally | |
| RUN npm install -g pm2 | |
| # Add environment variables for Puppeteer | |
| ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ | |
| PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \ | |
| PM2_PUBLIC_KEY=pheqiah2qgpu45w \ | |
| PM2_SECRET_KEY=xk8zhybf7ns8ybz | |
| # Copy other files and directories to the working directory | |
| COPY . . | |
| # Expose port 7860 | |
| EXPOSE 7860 | |
| # Run the application using PM2 | |
| CMD ["pm2", "runtime", "index.js", "--name", "API"] | |