feat: one-command Docker init for local and VPS

Add docker:local:* scripts with .env.docker (host Postgres), phase-b:init migrate-then-up for production, and document deploy workflows in DEPLOY-VPS.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Your Name 2026-06-30 18:04:48 +02:00
parent c4f2dbea89
commit 53850a4462
7 changed files with 147 additions and 11 deletions

70
.env.docker.example Normal file
View File

@ -0,0 +1,70 @@
# =============================================================================
# Docker LOCAL — même stack que le VPS (redis, nginx :9080, Postgres sur l'HÔTE)
#
# cp .env.docker.example .env.docker
# # Éditer POSTGRES_PASSWORD, secrets (JWT, ENCRYPTION_KEY, PLATFORM_MNEMONIC, INITIAL_SETUP_TOKEN)
# # Créer la base sur PostgreSQL local : games_platform_db
# npm run docker:local:init # 1er démarrage : migrate puis up (une seule commande)
# npm run docker:local:up # démarrages suivants
# npm run docker:local:migrate # après changement de schéma
# open http://localhost:9080/setup
#
# Comme le VPS : les conteneurs utilisent host.docker.internal (pas localhost).
# Seule différence vs VPS : URLs localhost au lieu du domaine public.
# Le fichier .env.docker reste local (gitignore) — le VPS garde son propre .env.
# =============================================================================
NODE_ENV=production
POSTGRES_USER=postgres
POSTGRES_PASSWORD=local_dev_postgres_password
POSTGRES_DB=games_platform_db
POSTGRES_PORT=5432
PGBOUNCER_PORT=6432
# Conteneurs Docker → PostgreSQL installé sur Windows (comme le VPS)
DATABASE_URL=postgresql://postgres:local_dev_postgres_password@host.docker.internal:5432/games_platform_db
DATABASE_PASSWORD=local_dev_postgres_password
RUN_MIGRATE_ON_START=0
BACKEND_PORT=4000
WS_PORT=4001
REDIS_PORT=6379
WORKER_ID=worker-1
JWT_SECRET=local-dev-jwt-secret-min-32-chars-change-me
JWT_ACCESS_EXPIRY=15m
JWT_REFRESH_EXPIRY=7d
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
PLATFORM_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
TRON_NODE_URL=https://api.shasta.trongrid.io
TRON_CONFIRMATIONS=3
USDT_TRC20_CONTRACT=
POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
POLYGON_CONFIRMATIONS=8
USDC_POLYGON_CONTRACT=
ALLOW_WITHDRAWALS=false
RATE_LIMIT_MAX=2000
PREDIQO_HTTP_PORT=9080
PREDIQO_HTTPS_PORT=9443
CERTBOT_EMAIL=dev@localhost
CERTBOT_DOMAIN1=localhost
APP_PUBLIC_URL=http://localhost:9080
INITIAL_SETUP_TOKEN=local-docker-setup-token-min-32-chars
# Figées au build prediqo-web — doivent correspondre au port nginx local
VITE_API_BASE_URL=http://localhost:9080
VITE_WS_ENABLED=true
VITE_WS_URL=ws://localhost:9080/ws/v1/games/candle-predict
REDIS_ENABLED=true
REDIS_ROUND_CACHE=true
BET_ASYNC=true
WS_ENABLED=true
WS_PATH=/ws/v1/games/candle-predict
EMAIL_TRANSPORT=console

View File

@ -1,4 +1,27 @@
# Docker Compose + Phase B — copy to .env in repo root
# =============================================================================
# Prediqo — variables d'environnement (NE PAS committer le fichier .env réel)
#
# DÉVELOPPEMENT LOCAL avec Docker (stack identique au VPS, Postgres sur l'hôte) :
# • cp .env.docker.example .env.docker
# • npm run docker:local:up && npm run docker:local:migrate
# • http://localhost:9080
#
# DÉVELOPPEMENT LOCAL sans Docker :
# • backend/.env ← copier depuis backend/.env.example (localhost:5432, port 4000)
# • prediqo_web/.env ← copier depuis prediqo_web/.env.example (VITE → localhost:4000)
# • Pas besoin de .env à la racine pour coder au quotidien.
# • Lancer : cd backend && npm run dev | cd prediqo_web && npm run dev
#
# VPS (Docker Compose) :
# • .env à la RACINE uniquement (copier ce fichier → .env, valeurs production)
# • 1er déploiement : npm run phase-b:init (HTTP :9080)
# • ou HTTPS : npm run phase-b:init:https (après certificat DNS)
# • ensuite : npm run phase-b:up
# • après git pull + schema.sql : npm run db:migrate
# • Le .env du VPS reste sur le serveur — jamais écrasé par git pull.
# =============================================================================
# Docker Compose + Phase B — copy to .env in repo root (VPS)
# Migrations manuelles (base vide ou après changement de schéma) : npm run db:migrate
# Frontend: cd prediqo_web && npm run dev
@ -46,12 +69,18 @@ PREDIQO_HTTPS_PORT=9443
CERTBOT_EMAIL=your-email@example.com
CERTBOT_DOMAIN1=prediqo.redirectme.net
APP_PUBLIC_URL=https://prediqo.redirectme.net:9443
APP_PUBLIC_URL=http://prediqo.redirectme.net:9080
INITIAL_SETUP_TOKEN=your-random-setup-token-min-32-chars
VITE_API_BASE_URL=https://prediqo.redirectme.net:9443
# Figées au build Docker (prediqo-web) — mode HTTP VPS :
VITE_API_BASE_URL=http://prediqo.redirectme.net:9080
VITE_WS_ENABLED=true
VITE_WS_URL=wss://prediqo.redirectme.net:9443/ws/v1/games/candle-predict
VITE_WS_URL=ws://prediqo.redirectme.net:9080/ws/v1/games/candle-predict
# Mode HTTPS VPS (décommenter après certificat) :
# APP_PUBLIC_URL=https://prediqo.redirectme.net:9443
# VITE_API_BASE_URL=https://prediqo.redirectme.net:9443
# VITE_WS_URL=wss://prediqo.redirectme.net:9443/ws/v1/games/candle-predict
# Phase B feature flags (used by Docker services)
REDIS_ENABLED=true

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ build/
.env
.env.*
!.env.example
!.env.docker.example
!**/.env.example
# Logs & OS

View File

@ -121,6 +121,9 @@ services:
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
required: false
environment:
<<: *backend-env
PORT: 4000
@ -149,6 +152,9 @@ services:
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
required: false
environment:
<<: *backend-env
ENGINE_ENABLED: "true"
@ -161,6 +167,9 @@ services:
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
required: false
environment:
<<: *backend-env
WS_ENABLED: "true"
@ -177,6 +186,9 @@ services:
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
required: false
environment:
<<: *backend-env
WORKER_ID: ${WORKER_ID:-worker-1}

View File

@ -166,8 +166,12 @@ VITE_WS_URL=ws://prediqo.redirectme.net:9080/ws/v1/games/candle-predict
```
```bash
# 1er déploiement (migrations + démarrage en une commande)
npm run phase-b:init
# équivalent : migrate puis docker compose --profile http up -d --build
# démarrages suivants ou après git pull (sans changement de schéma)
npm run phase-b:up
# équivalent : docker compose --profile http up -d --build
```
Accès : **http://prediqo.redirectme.net:9080** (avec le port, en **http**)
@ -193,8 +197,12 @@ Attendez 1–5 min (propagation DNS), puis validez dans le terminal.
#### Étape 2 — Démarrer la stack HTTPS
```bash
# 1er déploiement HTTPS (migrations + stack)
npm run phase-b:init:https
# équivalent : migrate puis docker compose --profile https-dns up -d --build
# démarrages suivants
npm run phase-b:up:https
# équivalent : docker compose --profile https-dns up -d --build
```
Accès : **https://prediqo.redirectme.net:9443**
@ -218,6 +226,10 @@ Ensuite, gérez les rôles depuis **Admin → Users**.
| Action | Commande |
|--------|----------|
| **1er déploiement HTTP** | `npm run phase-b:init` |
| **1er déploiement HTTPS** | `npm run phase-b:init:https` |
| Démarrer / rebuild (HTTP) | `npm run phase-b:up` |
| Migrations seules | `npm run db:migrate` |
| État des conteneurs | `npm run phase-b:status` |
| Logs en direct | `npm run phase-b:logs` |
| Redémarrer | `npm run phase-b:restart` |

View File

@ -3,7 +3,15 @@
"private": true,
"description": "Prediqo monorepo — Phase B Docker Compose helpers",
"scripts": {
"phase-b:init": "docker compose run --rm --no-deps --build backend node dist/db/migrate.js && docker compose --profile http up -d --build",
"phase-b:init:https": "docker compose run --rm --no-deps --build backend node dist/db/migrate.js && docker compose --profile https-dns up -d --build",
"phase-b:up": "docker compose --profile http up -d --build",
"docker:local:up": "docker compose --env-file .env.docker --profile http up -d --build",
"docker:local:init": "docker compose --env-file .env.docker run --rm --no-deps --build backend node dist/db/migrate.js && docker compose --env-file .env.docker --profile http up -d --build",
"docker:local:down": "docker compose --env-file .env.docker --profile http down",
"docker:local:migrate": "docker compose --env-file .env.docker run --rm --no-deps backend node dist/db/migrate.js",
"docker:local:logs": "docker compose --env-file .env.docker logs -f nginx backend backend-engine backend-ws backend-worker-bets redis prediqo-web",
"docker:local:status": "docker compose --env-file .env.docker ps",
"phase-b:up:https": "docker compose --profile https-dns up -d --build",
"phase-b:up:ssl": "docker compose --profile ssl up -d --build",
"phase-b:down": "docker compose down",
@ -13,6 +21,6 @@
"ssl:init": "docker compose --profile ssl-init run --rm certbot-init",
"ssl:dns-init": "docker compose --profile dns-init run --rm -it certbot-dns-init",
"ssl:dns-renew": "docker compose --profile dns-renew run --rm -it certbot-dns-renew",
"db:migrate": "docker compose run --rm --no-deps backend node dist/db/migrate.js"
"db:migrate": "docker compose run --rm --no-deps --build backend node dist/db/migrate.js"
}
}

View File

@ -1,8 +1,12 @@
# Local dev
# Local dev (npm run dev — Vite sur :5173)
VITE_API_BASE_URL=http://localhost:4000
VITE_WS_ENABLED=true
VITE_WS_URL=ws://localhost:4001/ws/v1/games/candle-predict
# Production (VPS — baked into Docker image via root .env)
# VITE_API_BASE_URL=https://prediqo.redirectme.net
# VITE_WS_URL=wss://prediqo.redirectme.net/ws/v1/games/candle-predict
# VPS HTTP (port 9080 — figé au build Docker via .env racine)
# VITE_API_BASE_URL=http://prediqo.redirectme.net:9080
# VITE_WS_URL=ws://prediqo.redirectme.net:9080/ws/v1/games/candle-predict
# VPS HTTPS (port 9443)
# VITE_API_BASE_URL=https://prediqo.redirectme.net:9443
# VITE_WS_URL=wss://prediqo.redirectme.net:9443/ws/v1/games/candle-predict