# Prediqo — stack Docker autonome (ports dédiés, sans impact sur les autres apps du VPS). # # VPS partagé — HTTPS Let's Encrypt (gratuit) via DNS, port 9443 : # 1. npm run phase-b:up (HTTP temporaire, optionnel) # 2. npm run ssl:dns-init (certificat DNS — interactif sur le VPS) # 3. Mettre à jour .env (URLs https://...:9443) puis : # npm run phase-b:up:https (rebuild frontend + nginx HTTPS) # # VPS dédié (80/443 standard) : # npm run ssl:init && npm run phase-b:up:ssl x-backend-common: &backend-common build: context: ./backend dockerfile: Dockerfile restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway" networks: - prediqo-net environment: &backend-env NODE_ENV: ${NODE_ENV:-production} # Depuis les conteneurs : host.docker.internal (pas localhost). # Définissez DATABASE_URL dans .env pour contrôler l’URL complète (recommandé sur VPS). DATABASE_URL: ${DATABASE_URL:-postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@host.docker.internal:${POSTGRES_PORT:-5432}/${POSTGRES_DB}} DATABASE_PASSWORD: ${DATABASE_PASSWORD:-} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_USER: ${POSTGRES_USER:-postgres} # Auth URL — password from .env (REDIS_PASSWORD). Never publish Redis on the host. REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379 REDIS_ENABLED: ${REDIS_ENABLED:-true} REDIS_ROUND_CACHE: ${REDIS_ROUND_CACHE:-true} BET_ASYNC: ${BET_ASYNC:-true} JWT_SECRET: ${JWT_SECRET} TURNSTILE_SITE_KEY: ${TURNSTILE_SITE_KEY:-} TURNSTILE_SECRET_KEY: ${TURNSTILE_SECRET_KEY:-} JWT_ACCESS_EXPIRY: ${JWT_ACCESS_EXPIRY:-15m} JWT_REFRESH_EXPIRY: ${JWT_REFRESH_EXPIRY:-7d} ENCRYPTION_KEY: ${ENCRYPTION_KEY} PLATFORM_MNEMONIC: ${PLATFORM_MNEMONIC} TRON_NODE_URL: ${TRON_NODE_URL} TRON_API_KEY: ${TRON_API_KEY:-} TRON_CONFIRMATIONS: ${TRON_CONFIRMATIONS:-3} USDT_TRC20_CONTRACT: ${USDT_TRC20_CONTRACT:-} BSC_RPC_URL: ${BSC_RPC_URL:-https://bsc-dataseed.binance.org} # Comma-separated RPCs used when primary eth_getLogs returns limit exceeded (-32005) BSC_RPC_FALLBACKS: ${BSC_RPC_FALLBACKS:-https://rpc-bsc.48.club} BSC_CONFIRMATIONS: ${BSC_CONFIRMATIONS:-15} USDT_BEP20_CONTRACT: ${USDT_BEP20_CONTRACT:-} BSC_GETLOGS_BLOCK_RANGE: ${BSC_GETLOGS_BLOCK_RANGE:-2000} BSC_UNPAID_LOOKBACK_BLOCKS: ${BSC_UNPAID_LOOKBACK_BLOCKS:-200000} BSCSCAN_API_KEY: ${BSCSCAN_API_KEY:-} ETHERSCAN_API_KEY: ${ETHERSCAN_API_KEY:-} BSC_EXPLORER_API_URL: ${BSC_EXPLORER_API_URL:-} POLYGON_RPC_URL: ${POLYGON_RPC_URL} POLYGON_CONFIRMATIONS: ${POLYGON_CONFIRMATIONS:-8} USDC_POLYGON_CONTRACT: ${USDC_POLYGON_CONTRACT:-} ALLOW_WITHDRAWALS: ${ALLOW_WITHDRAWALS:-false} # Treasury: auto-enqueue deposit → cold sweeps (requires active cold wallet in Admin → Treasury) SWEEP_ENABLED: ${SWEEP_ENABLED:-false} # true = sweep HD→cold without Approvals (still validates cold allowlist / balances) SWEEP_AUTO_EXECUTE: ${SWEEP_AUTO_EXECUTE:-false} # Optional: auto only below this raw amount; larger still need Approvals SWEEP_AUTO_MAX_AMOUNT_RAW: ${SWEEP_AUTO_MAX_AMOUNT_RAW:-} # Optional: comma-separated allowed cold addresses (recommended if auto-execute) SWEEP_COLD_ALLOWLIST: ${SWEEP_COLD_ALLOWLIST:-} SWEEP_MIN_AMOUNT_RAW: ${SWEEP_MIN_AMOUNT_RAW:-1000000} SWEEP_POLL_INTERVAL_MS: ${SWEEP_POLL_INTERVAL_MS:-120000} SWEEP_BSC_GAS_TOPUP_WEI: ${SWEEP_BSC_GAS_TOPUP_WEI:-1000000000000000} SWEEP_TRON_GAS_TOPUP_SUN: ${SWEEP_TRON_GAS_TOPUP_SUN:-15000000} # Optional USDT floor left on hot after Hot→Cold (raw chain units; 0 = no fixed USDT reserve) HOT_USDT_MIN_RESERVE_RAW: ${HOT_USDT_MIN_RESERVE_RAW:-0} RATE_LIMIT_MAX: ${RATE_LIMIT_MAX:-2000} INITIAL_SETUP_TOKEN: ${INITIAL_SETUP_TOKEN:-} # Emergency Super Admin 2FA reset CLI only (not an HTTP API). Min 32 chars; leave empty to disable break-glass. BREAK_GLASS_TOKEN: ${BREAK_GLASS_TOKEN:-} TRUST_PROXY: ${TRUST_PROXY:-true} APP_PUBLIC_URL: ${APP_PUBLIC_URL:-https://prediqo.redirectme.net:9443} EMAIL_TRANSPORT: ${EMAIL_TRANSPORT:-console} SMTP_HOST: ${SMTP_HOST:-} SMTP_PORT: ${SMTP_PORT:-587} SMTP_SECURE: ${SMTP_SECURE:-false} SMTP_USER: ${SMTP_USER:-} SMTP_PASS: ${SMTP_PASS:-} EMAIL_FROM: ${EMAIL_FROM:-} EMAIL_REPLY_TO: ${EMAIL_REPLY_TO:-} VERIFY_EMAIL_PATH: ${VERIFY_EMAIL_PATH:-/verify-email} RESET_PASSWORD_PATH: ${RESET_PASSWORD_PATH:-/reset-password} PASSWORD_RESET_EXPIRY_HOURS: ${PASSWORD_RESET_EXPIRY_HOURS:-1} SENTRY_DSN: ${SENTRY_DSN:-} SENTRY_TRACES_SAMPLE_RATE: ${SENTRY_TRACES_SAMPLE_RATE:-0.1} SENTRY_RELEASE: ${SENTRY_RELEASE:-} # Empty = auto (on in production NODE_ENV). Set true/false to force. CLAMAV_ENABLED: ${CLAMAV_ENABLED:-} CLAMAV_HOST: ${CLAMAV_HOST:-clamav} CLAMAV_PORT: ${CLAMAV_PORT:-3310} CLAMAV_TIMEOUT_MS: ${CLAMAV_TIMEOUT_MS:-30000} REQUIRE_ADMIN_2FA: ${REQUIRE_ADMIN_2FA:-} ANDROID_APK_EXPECTED_CERT_SHA256: ${ANDROID_APK_EXPECTED_CERT_SHA256:-} ANDROID_APK_EXPECTED_PACKAGE: ${ANDROID_APK_EXPECTED_PACKAGE:-com.prediqo.mobile} APK_MAX_UPLOAD_BYTES: ${APK_MAX_UPLOAD_BYTES:-125829120} APK_DOWNLOAD_TOKEN_TTL_SECONDS: ${APK_DOWNLOAD_TOKEN_TTL_SECONDS:-3600} # Admin SSL expiry page — comma-separated host[:port]; empty = APP_PUBLIC_URL + www SSL_STATUS_HOSTS: ${SSL_STATUS_HOSTS:-} SSL_STATUS_WARN_DAYS: ${SSL_STATUS_WARN_DAYS:-30} SSL_STATUS_CRITICAL_DAYS: ${SSL_STATUS_CRITICAL_DAYS:-7} SSL_STATUS_TIMEOUT_MS: ${SSL_STATUS_TIMEOUT_MS:-8000} # Admin VPS monitor (Prometheus on monitoring-net + prediqo-net; no public ports) PROMETHEUS_URL: ${PROMETHEUS_URL:-http://prometheus:9090} VPS_MONITOR_TIMEOUT_MS: ${VPS_MONITOR_TIMEOUT_MS:-8000} services: postgres: profiles: ["docker-db"] image: postgres:16-alpine container_name: crypto_wallet_db restart: unless-stopped environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} volumes: - postgres_data:/var/lib/postgresql/data ports: - "${POSTGRES_PORT:-5432}:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 5s timeout: 5s retries: 5 networks: - prediqo-net pgbouncer: profiles: ["docker-db"] image: edoburu/pgbouncer:1.22.1-p0 container_name: crypto_wallet_pgbouncer restart: unless-stopped depends_on: postgres: condition: service_healthy environment: DB_USER: ${POSTGRES_USER} DB_PASSWORD: ${POSTGRES_PASSWORD} DB_HOST: postgres DB_NAME: ${POSTGRES_DB} POOL_MODE: transaction MAX_CLIENT_CONN: 500 DEFAULT_POOL_SIZE: 25 AUTH_TYPE: scram-sha-256 ports: - "${PGBOUNCER_PORT:-6432}:5432" networks: - prediqo-net redis: image: redis:7-alpine container_name: crypto_wallet_redis restart: unless-stopped # Hardened: requirepass, no host port (Docker network only), dangerous cmds disabled. # Set REDIS_PASSWORD in .env (required). Do not map 6379 to the host on a VPS. environment: REDIS_PASSWORD: ${REDIS_PASSWORD:?Set REDIS_PASSWORD in .env} command: - redis-server - --appendonly - yes - --requirepass - ${REDIS_PASSWORD} - --protected-mode - "yes" - --rename-command - FLUSHALL - "" - --rename-command - FLUSHDB - "" - --rename-command - CONFIG - "" - --rename-command - KEYS - "" - --rename-command - DEBUG - "" - --rename-command - REPLICAOF - "" - --rename-command - SLAVEOF - "" # Intentionally no `ports:` — Redis stays on prediqo-net only. volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "--no-auth-warning", "ping"] interval: 5s timeout: 3s retries: 5 networks: - prediqo-net # Antivirus pour uploads FAQ/Support (profil opt-in : --profile clamav) clamav: profiles: ["clamav"] image: clamav/clamav:1.4 container_name: prediqo_clamav restart: unless-stopped networks: - prediqo-net healthcheck: test: ["CMD", "clamdscan", "--ping"] interval: 30s timeout: 10s retries: 5 start_period: 300s backend: <<: *backend-common container_name: crypto_wallet_api depends_on: redis: condition: service_healthy postgres: condition: service_healthy required: false # Reach Prometheus on monitoring-net (exporters stay off the public internet; no published ports). networks: - prediqo-net - monitoring-net environment: <<: *backend-env PORT: 4000 API_PREFIX: /api/v1 ENGINE_ENABLED: "false" WS_ENABLED: "false" command: ["sh", "-c", "if [ \"${RUN_MIGRATE_ON_START:-0}\" = \"1\" ]; then node dist/db/migrate.js || exit 1; fi; exec node dist/apps/api.js"] # Persist support/FAQ uploads — without this, FIM baselines outlive files and spam "deleted" alerts. # Nested apk_releases volume keeps APK binaries separable for backup/migration. volumes: - upload_data:/app/data - apk_releases:/app/data/apk-releases expose: - "4000" healthcheck: test: [ "CMD", "node", "-e", "require('http').get('http://127.0.0.1:4000/health',(r)=>{r.resume();process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))", ] interval: 5s timeout: 5s retries: 12 start_period: 30s backend-engine: <<: *backend-common container_name: crypto_wallet_engine depends_on: redis: condition: service_healthy postgres: condition: service_healthy required: false environment: <<: *backend-env ENGINE_ENABLED: "true" ENGINE_LEADER: "1" command: ["node", "dist/apps/engine.js"] backend-ws: <<: *backend-common container_name: crypto_wallet_ws depends_on: redis: condition: service_healthy postgres: condition: service_healthy required: false environment: <<: *backend-env WS_ENABLED: "true" WS_PORT: 4001 WS_PATH: /ws/v1/games/candle-predict ENGINE_ENABLED: "false" command: ["node", "dist/apps/ws.js"] expose: - "4001" backend-worker-bets: <<: *backend-common container_name: crypto_wallet_worker_bets depends_on: redis: condition: service_healthy postgres: condition: service_healthy required: false environment: <<: *backend-env WORKER_ID: ${WORKER_ID:-worker-1} ENGINE_ENABLED: "false" command: ["node", "dist/apps/worker-bets.js"] healthcheck: test: [ "CMD", "node", "-e", "const Redis=require('ioredis');const r=new Redis(process.env.REDIS_URL||'');if(!process.env.REDIS_URL)process.exit(1);r.ping().then(()=>process.exit(0)).catch(()=>process.exit(1)).finally(()=>r.quit());", ] interval: 15s timeout: 5s retries: 3 start_period: 20s prediqo-web: build: context: ./prediqo_web dockerfile: Dockerfile args: VITE_API_BASE_URL: ${VITE_API_BASE_URL} VITE_WS_URL: ${VITE_WS_URL} VITE_WS_ENABLED: ${VITE_WS_ENABLED:-true} VITE_SENTRY_DSN: ${VITE_SENTRY_DSN:-} VITE_SENTRY_TRACES_SAMPLE_RATE: ${VITE_SENTRY_TRACES_SAMPLE_RATE:-0.1} container_name: prediqo-web restart: unless-stopped depends_on: - backend expose: - "80" networks: - prediqo-net # Entrée HTTP sur un port dédié (défaut 9080) — n'utilise pas 80/443 du VPS. nginx: profiles: ["http"] image: nginx:1.27-alpine container_name: prediqo_nginx restart: unless-stopped depends_on: prediqo-web: condition: service_started backend: condition: service_healthy backend-ws: condition: service_started ports: - "${PREDIQO_HTTP_PORT:-9080}:80" environment: CERTBOT_DOMAIN1: ${CERTBOT_DOMAIN1:-prediqo.redirectme.net} volumes: - certbot-www:/var/www/certbot - ./nginx/default-http-only.conf.template:/etc/nginx/templates/default.conf.template:ro networks: - prediqo-net # HTTPS sur port dédié 9443 — certificat Let's Encrypt via DNS (gratuit). nginx-https-dns: profiles: ["https-dns"] image: nginx:1.27-alpine container_name: prediqo_nginx_https restart: unless-stopped depends_on: prediqo-web: condition: service_started backend: condition: service_healthy backend-ws: condition: service_started ports: - "${PREDIQO_HTTP_PORT:-9080}:80" - "${PREDIQO_HTTPS_PORT:-9443}:443" environment: CERTBOT_DOMAIN: ${CERTBOT_DOMAIN1} CERTBOT_DOMAIN1: ${CERTBOT_DOMAIN1} CERTBOT_DOMAIN2: ${CERTBOT_DOMAIN2:-www.${CERTBOT_DOMAIN1}} PREDIQO_HTTPS_PORT: ${PREDIQO_HTTPS_PORT:-9443} volumes: - letsencrypt:/etc/letsencrypt - certbot-www:/var/www/certbot - ./nginx/default-https-custom-port.conf.template:/etc/nginx/templates/default.conf.template:ro command: > /bin/sh -c "LAST=''; (while :; do CUR=$$(cat /var/www/certbot/.cert-renewed 2>/dev/null || true); if [ -n \"$$CUR\" ] && [ \"$$CUR\" != \"$$LAST\" ]; then nginx -s reload || true; LAST=\"$$CUR\"; fi; sleep 60; done) & exec /docker-entrypoint.sh nginx -g 'daemon off;'" networks: - prediqo-net # Let's Encrypt gratuit — validation DNS (sans utiliser le port 80 du VPS). # Interactif : Certbot affiche un TXT par domaine (apex + www). # .env : CERTBOT_DOMAIN1=tloto.net CERTBOT_DOMAIN2=www.tloto.net certbot-dns-init: image: certbot/certbot:v2.11.0 profiles: ["dns-init"] volumes: - letsencrypt:/etc/letsencrypt command: >- certonly --manual --preferred-challenges dns --email ${CERTBOT_EMAIL} --cert-name ${CERTBOT_DOMAIN1} -d ${CERTBOT_DOMAIN1} -d ${CERTBOT_DOMAIN2:-www.${CERTBOT_DOMAIN1}} --expand --agree-tos --no-eff-email --manual-public-ip-logging-ok networks: - prediqo-net certbot-dns-renew: image: certbot/certbot:v2.11.0 profiles: ["dns-renew"] volumes: - letsencrypt:/etc/letsencrypt - certbot-www:/var/www/certbot # deploy-hook must be ONE argv; a bare `sh -c "..."` was parsed as Certbot flags. entrypoint: certbot command: - renew - --manual - --preferred-challenges - dns - --manual-public-ip-logging-ok - --deploy-hook - sh -c "mkdir -p /var/www/certbot && date +%s > /var/www/certbot/.cert-renewed" networks: - prediqo-net # HTTPS standard 80/443 — uniquement sur VPS dédié : npm run phase-b:up:ssl nginx-ssl: profiles: ["ssl"] image: nginx:1.27-alpine container_name: prediqo_nginx_ssl restart: unless-stopped depends_on: prediqo-web: condition: service_started backend: condition: service_healthy backend-ws: condition: service_started ports: - "${PREDIQO_HTTP_PORT:-80}:80" - "${PREDIQO_HTTPS_PORT:-443}:443" environment: CERTBOT_DOMAIN: ${CERTBOT_DOMAIN1} CERTBOT_DOMAIN1: ${CERTBOT_DOMAIN1} volumes: - letsencrypt:/etc/letsencrypt - certbot-www:/var/www/certbot - ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro command: > /bin/sh -c "LAST=''; (while :; do CUR=$$(cat /var/www/certbot/.cert-renewed 2>/dev/null || true); if [ -n \"$$CUR\" ] && [ \"$$CUR\" != \"$$LAST\" ]; then nginx -s reload || true; LAST=\"$$CUR\"; fi; sleep 60; done) & exec /docker-entrypoint.sh nginx -g 'daemon off;'" networks: - prediqo-net certbot-init: image: certbot/certbot:v2.11.0 profiles: ["ssl-init"] ports: - "${PREDIQO_HTTP_PORT:-80}:80" volumes: - letsencrypt:/etc/letsencrypt command: >- certonly --standalone --email ${CERTBOT_EMAIL} -d ${CERTBOT_DOMAIN1} --agree-tos --no-eff-email --non-interactive networks: - prediqo-net certbot-renew: image: certbot/certbot:v2.11.0 profiles: ["ssl"] restart: unless-stopped volumes: - letsencrypt:/etc/letsencrypt - certbot-www:/var/www/certbot entrypoint: /bin/sh command: > -c "trap exit TERM; while :; do certbot renew --webroot -w /var/www/certbot --deploy-hook 'date +%s > /var/www/certbot/.cert-renewed' --quiet; sleep 12h; done" networks: - prediqo-net # ── VPS monitoring (profile: monitoring) ────────────────────────────────── # No published ports. Backend reads allowlisted metrics via PROMETHEUS_URL. # Exception (documented): cAdvisor mounts docker.sock read-only; backend never does. prometheus: profiles: ['monitoring'] image: prom/prometheus:v2.55.1 container_name: prediqo_prometheus restart: unless-stopped # Justified exception: image USER=nobody but Docker named volumes are root-owned # on first create → process exits 1 (permission denied) in a restart loop. # Running as root here only writes TSDB data; no ports published. user: root command: # Boolean flags: omit to keep defaults (lifecycle/admin API off). Do NOT pass =false. - --config.file=/etc/prometheus/prometheus.yml - --storage.tsdb.path=/prometheus - --storage.tsdb.retention.time=${MONITORING_RETENTION:-15d} - --web.listen-address=0.0.0.0:9090 volumes: - ./deploy/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro - prometheus_data:/prometheus networks: - monitoring-net - prediqo-net healthcheck: test: ['CMD', 'wget', '-qO-', 'http://127.0.0.1:9090/-/healthy'] interval: 15s timeout: 5s retries: 5 start_period: 20s mem_limit: 512m cpus: 0.50 # Intentionally no ports: — not reachable from the public internet node-exporter: profiles: ['monitoring'] image: prom/node-exporter:v1.8.2 container_name: prediqo_node_exporter restart: unless-stopped command: - --path.rootfs=/host - --path.procfs=/host/proc - --path.sysfs=/host/sys - --collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/) volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/host:ro,rslave networks: - monitoring-net pid: host mem_limit: 128m cpus: 0.20 # Intentionally no ports: cadvisor: profiles: ['monitoring'] image: gcr.io/cadvisor/cadvisor:v0.49.1 container_name: prediqo_cadvisor restart: unless-stopped command: - --docker_only=true - --housekeeping_interval=30s - --store_container_labels=false - --disable_metrics=advtcp,udp,sched,process,hugetlb,referenced_memory,resctrl,cpu_topology,tcp,memory_numa volumes: - /:/rootfs:ro - /var/run:/var/run:ro - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro - /dev/disk/:/dev/disk:ro # Least privilege for container metrics — RO sock; never mount this on backend/web - /var/run/docker.sock:/var/run/docker.sock:ro networks: - monitoring-net mem_limit: 256m cpus: 0.30 # Intentionally no ports: networks: prediqo-net: driver: bridge monitoring-net: # Dedicated bridge for exporters ↔ Prometheus. No published ports on those # services (security). Do NOT set internal:true — it breaks dual-homed # Prometheus reachability from crypto_wallet_api on prediqo-net. driver: bridge volumes: postgres_data: redis_data: upload_data: apk_releases: letsencrypt: certbot-www: prometheus_data: