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 FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Install chromium dependencies for whatsapp-web.js # Install chromium build dependencies + git (for patch-package)
RUN apk add --no-cache \ RUN apk add --no-cache \
chromium \ chromium \
nss \ nss \
@@ -15,13 +15,13 @@ RUN apk add --no-cache \
# Copy package files # Copy package files
COPY package*.json ./ COPY package*.json ./
# Install dependencies # Install all dependencies (incl dev) for patch-package
RUN npm ci --production=false RUN npm ci --production=false
# Copy patches directory if it exists # Copy patch directory if present
COPY patches ./patches COPY patches ./patches
# Run postinstall (patch-package) # Apply patch-package (best-effort)
RUN npm run postinstall || true RUN npm run postinstall || true
# Copy application files # Copy application files
@@ -32,42 +32,40 @@ COPY swagger.yml ./
FROM node:20-alpine FROM node:20-alpine
WORKDIR /app WORKDIR /app
# Install chromium and runtime dependencies # Install Chromium runtime dependencies + su-exec
RUN apk add --no-cache \ RUN apk add --no-cache \
chromium \ chromium \
nss \ nss \
freetype \ freetype \
harfbuzz \ harfbuzz \
ca-certificates \ 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 \ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
#RUN groupadd -r whatsapp && useradd -r -g whatsapp whatsapp # Create non-root service user
#DEV Create non-root user RUN addgroup -S whatsapp && \
RUN addgroup -S whatsapp || true && \ adduser -D -S -G whatsapp whatsapp
adduser -D -S -G whatsapp whatsapp || true
# Copy dependencies from builder # Copy node_modules from builder
COPY --from=builder --chown=whatsapp:whatsapp /app/node_modules ./node_modules 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 server.js ./
COPY --chown=whatsapp:whatsapp package*.json ./
COPY --chown=whatsapp:whatsapp swagger.yml ./ COPY --chown=whatsapp:whatsapp swagger.yml ./
COPY --chown=whatsapp:whatsapp package*.json ./
# Create volume directories # Pre-create required folders (will be overwritten by volumes)
RUN mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth && \ RUN mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth
chown -R whatsapp:whatsapp /app
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 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: services:
wapp: wapp:
user: "1000:1000"
build: build:
context: ${WAPP_APP_ROOT} context: ${WAPP_APP_ROOT}
dockerfile: Dockerfile dockerfile: Dockerfile
@@ -11,6 +10,7 @@ services:
networks: networks:
- traefik_net - traefik_net
- default - default
environment: environment:
# Server configuration # Server configuration
- PORT=3001 - PORT=3001
@@ -37,10 +37,10 @@ services:
volumes: volumes:
# Persistent data volumes # Persistent data volumes
- whatsapp-data:/app/data - whatsapp-data:/app/data:rw
- whatsapp-media:/app/media - whatsapp-media:/app/media:rw
- whatsapp-cache:/app/.wwebjs_cache - whatsapp-cache:/app/.wwebjs_cache:rw
- whatsapp-auth:/app/.wwebjs_auth - whatsapp-auth:/app/.wwebjs_auth:rw
# Uncomment labels below when ready to use Traefik # Uncomment labels below when ready to use Traefik
labels: labels:
@@ -58,6 +58,7 @@ services:
retries: 3 retries: 3
start_period: 40s start_period: 40s
networks: networks:
traefik_net: traefik_net:
external: true external: true

View File

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