games_app/docker-compose.yml
2026-06-29 15:01:23 +02:00

347 lines
9.8 KiB
YAML

# 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}
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@host.docker.internal:${POSTGRES_PORT:-5432}/${POSTGRES_DB}
REDIS_URL: redis://redis:6379
REDIS_ENABLED: "true"
REDIS_ROUND_CACHE: "true"
BET_ASYNC: "true"
JWT_SECRET: ${JWT_SECRET}
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:-}
POLYGON_RPC_URL: ${POLYGON_RPC_URL}
POLYGON_CONFIRMATIONS: ${POLYGON_CONFIRMATIONS:-8}
USDC_POLYGON_CONTRACT: ${USDC_POLYGON_CONTRACT:-}
ALLOW_WITHDRAWALS: ${ALLOW_WITHDRAWALS:-false}
RATE_LIMIT_MAX: ${RATE_LIMIT_MAX:-2000}
INITIAL_SETUP_TOKEN: ${INITIAL_SETUP_TOKEN:-}
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:-}
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}
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
command: redis-server --appendonly yes
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
networks:
- prediqo-net
backend:
<<: *backend-common
container_name: crypto_wallet_api
depends_on:
redis:
condition: service_healthy
environment:
<<: *backend-env
PORT: 4000
API_PREFIX: /api/v1
ENGINE_ENABLED: "false"
WS_ENABLED: "false"
command: ["sh", "-c", "node dist/db/migrate.js 2>/dev/null || true && node dist/apps/api.js"]
expose:
- "4000"
backend-engine:
<<: *backend-common
container_name: crypto_wallet_engine
depends_on:
redis:
condition: service_healthy
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
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
environment:
<<: *backend-env
WORKER_ID: ${WORKER_ID:-worker-1}
ENGINE_ENABLED: "false"
command: ["node", "dist/apps/worker-bets.js"]
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}
container_name: prediqo_web
restart: unless-stopped
depends_on:
- backend
expose:
- "80"
# 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
- backend
- backend-ws
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
- backend
- backend-ws
ports:
- "${PREDIQO_HTTP_PORT:-9080}:80"
- "${PREDIQO_HTTPS_PORT:-9443}:443"
environment:
CERTBOT_DOMAIN: ${CERTBOT_DOMAIN1}
CERTBOT_DOMAIN1: ${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 l'enregistrement TXT à créer chez redirectme.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}
-d ${CERTBOT_DOMAIN1}
--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
command: >-
renew --manual
--preferred-challenges dns
--manual-public-ip-logging-ok
--deploy-hook sh -c "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
- backend
- backend-ws
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
networks:
prediqo-net:
driver: bridge
volumes:
postgres_data:
redis_data:
letsencrypt:
certbot-www: