This commit is contained in:
mike
2025-12-12 12:58:57 +01:00
parent 92f145e6b3
commit a5222646e8
3 changed files with 28 additions and 32 deletions

View File

@@ -2,7 +2,7 @@
FROM node:20-alpine AS builder
WORKDIR /app
# Install chromium dependencies for whatsapp-web.js
# Install chromium build dependencies + git (for patch-package)
RUN apk add --no-cache \
chromium \
nss \
@@ -15,13 +15,13 @@ RUN apk add --no-cache \
# Copy package files
COPY package*.json ./
# Install dependencies
# Install all dependencies (incl dev) for patch-package
RUN npm ci --production=false
# Copy patches directory if it exists
# Copy patch directory if present
COPY patches ./patches
# Run postinstall (patch-package)
# Apply patch-package (best-effort)
RUN npm run postinstall || true
# Copy application files
@@ -32,42 +32,40 @@ COPY swagger.yml ./
FROM node:20-alpine
WORKDIR /app
# Install chromium and runtime dependencies
# Install Chromium runtime dependencies + su-exec
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
ttf-freefont \
su-exec
# Tell Puppeteer to use installed chromium
# Puppeteer / whatsapp-web.js settings
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
#RUN groupadd -r whatsapp && useradd -r -g whatsapp whatsapp
#DEV Create non-root user
RUN addgroup -S whatsapp || true && \
adduser -D -S -G whatsapp whatsapp || true
# Create non-root service user
RUN addgroup -S whatsapp && \
adduser -D -S -G whatsapp whatsapp
# Copy dependencies from builder
# Copy node_modules from builder
COPY --from=builder --chown=whatsapp:whatsapp /app/node_modules ./node_modules
# Copy application files
# Copy application code
COPY --chown=whatsapp:whatsapp server.js ./
COPY --chown=whatsapp:whatsapp package*.json ./
COPY --chown=whatsapp:whatsapp swagger.yml ./
COPY --chown=whatsapp:whatsapp package*.json ./
# Create volume directories
RUN mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth && \
chown -R whatsapp:whatsapp /app
# Pre-create required folders (will be overwritten by volumes)
RUN mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth
USER whatsapp
# ENTRYPOINT: fix permissions as root → switch to whatsapp → run server
ENTRYPOINT ["sh", "-c", "\
mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth && \
chown -R whatsapp:whatsapp /app && \
exec su-exec whatsapp node server.js \
"]
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3001/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1); }).on('error', () => process.exit(1));"
CMD ["node", "server.js"]

View File

@@ -1,6 +1,5 @@
services:
wapp:
user: "1000:1000"
build:
context: ${WAPP_APP_ROOT}
dockerfile: Dockerfile
@@ -11,6 +10,7 @@ services:
networks:
- traefik_net
- default
environment:
# Server configuration
- PORT=3001
@@ -37,10 +37,10 @@ services:
volumes:
# Persistent data volumes
- whatsapp-data:/app/data
- whatsapp-media:/app/media
- whatsapp-cache:/app/.wwebjs_cache
- whatsapp-auth:/app/.wwebjs_auth
- whatsapp-data:/app/data:rw
- whatsapp-media:/app/media:rw
- whatsapp-cache:/app/.wwebjs_cache:rw
- whatsapp-auth:/app/.wwebjs_auth:rw
# Uncomment labels below when ready to use Traefik
labels:
@@ -58,6 +58,7 @@ services:
retries: 3
start_period: 40s
networks:
traefik_net:
external: true

View File

@@ -4,14 +4,11 @@ const YAML = require('yamljs');
const path = require('path');
const swaggerPath = path.join(__dirname, 'swagger.yml');
const swaggerDoc = YAML.load(swaggerPath);
const express = require('express')
const http = require('http')
const socketIo = require('socket.io')
const { Sequelize, DataTypes, Op } = require('sequelize')
const { Client, LocalAuth, Location, Poll, List, Buttons } = require('whatsapp-web.js')
const path = require('path')
const fs = require('fs').promises
const crypto = require('crypto')
const qrcode = require('qrcode-terminal')