# syntax=docker/dockerfile:1 # OpenWA — Hugging Face Spaces single-container deployment # # Architecture inside the container: # nginx (port 7860, the only HF-exposed port) # ├─ / → React dashboard static files # ├─ /api/ → proxy → NestJS API (localhost:2785) # └─ /socket.io/ → proxy → NestJS API (WebSocket upgrade) # # Intentionally excluded (not available on HF Spaces): # • docker-proxy / Docker-in-Docker (no /var/run/docker.sock) # • Traefik, PostgreSQL, Redis, MinIO (use SQLite + local storage) # ── Stage 1: Build dashboard ────────────────────────────────────────────────── FROM node:20-alpine AS dashboard-builder WORKDIR /app COPY dashboard/package*.json ./ RUN npm ci COPY dashboard/ . RUN npm run build # ── Stage 2: Build API ──────────────────────────────────────────────────────── FROM node:22-slim AS api-builder WORKDIR /app RUN apt-get update && apt-get install -y \ python3 make g++ \ && rm -rf /var/lib/apt/lists/* COPY package*.json ./ RUN npm ci COPY . . RUN npm run build # ── Stage 3: Production image ───────────────────────────────────────────────── FROM node:22-slim # nginx + supervisord + Chromium/Puppeteer deps RUN apt-get update && apt-get install -y \ nginx \ supervisor \ chromium \ fonts-liberation \ libatk-bridge2.0-0 \ libatk1.0-0 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libgbm1 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libx11-xcb1 \ libxcomposite1 \ libxdamage1 \ libxrandr2 \ xdg-utils \ curl \ && rm -rf /var/lib/apt/lists/* ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true # API runs on this internal port; nginx fronts port 7860 ENV PORT=2785 ENV NODE_ENV=production ENV DATABASE_TYPE=sqlite ENV REDIS_ENABLED=false ENV STORAGE_TYPE=local # Allow all origins for HF Space demo ENV CORS_ORIGINS=* WORKDIR /app # Production Node dependencies COPY package*.json ./ RUN npm ci --omit=dev && npm cache clean --force # Compiled API COPY --from=api-builder /app/dist ./dist # Dashboard static files served by nginx COPY --from=dashboard-builder /app/dist /usr/share/nginx/html # Data dirs (sessions/media/plugins all written here at runtime) RUN mkdir -p ./data/sessions ./data/media ./data/plugins # ── nginx config ────────────────────────────────────────────────────────────── # Remove any default site that would conflict with port 7860 RUN rm -f /etc/nginx/sites-enabled/default RUN cat <<'NGINXCONF' > /etc/nginx/conf.d/openwa.conf server { listen 7860; server_name localhost; root /usr/share/nginx/html; index index.html; gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/x-font-ttf font/opentype image/svg+xml image/x-icon; # API requests → NestJS location /api/ { proxy_pass http://127.0.0.1:2785; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; # Forward large media payloads client_max_body_size 50m; proxy_read_timeout 120s; } # WebSocket → NestJS location /socket.io/ { proxy_pass http://127.0.0.1:2785; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } # SPA fallback — all other paths serve index.html location / { try_files $uri $uri/ /index.html; } } NGINXCONF # ── supervisord config ──────────────────────────────────────────────────────── RUN cat <<'SUPCONF' > /etc/supervisor/conf.d/openwa.conf [supervisord] nodaemon=true logfile=/dev/null logfile_maxbytes=0 pidfile=/run/supervisord.pid [program:nginx] command=nginx -g "daemon off;" autostart=true autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 priority=10 [program:api] command=node /app/dist/main directory=/app autostart=true autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 ; Give the API time to start before nginx begins accepting traffic startsecs=5 priority=20 SUPCONF EXPOSE 7860 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]