Some checks failed
CI / test-and-build (push) Failing after 25s
Co-authored-by: Cursor <cursoragent@cursor.com>
238 lines
6.7 KiB
Markdown
238 lines
6.7 KiB
Markdown
# Migration Tloto → nouveau VPS (fresh install)
|
||
|
||
**Cible :** `deploy@191.215.41.53` (hôte déjà durci)
|
||
**Stratégie :** réinstallation propre (DB + secrets **nouveaux**), car les comptes DB sont des tests et les fonds utiles sont sur MetaMask (cold).
|
||
|
||
> Ne **pas** restaurer le dump de l’ancien VPS.
|
||
> Ne **pas** réutiliser `ENCRYPTION_KEY` / `PLATFORM_MNEMONIC` de l’ancien serveur.
|
||
|
||
Garde l’**ancien** VPS en ligne jusqu’au cutover DNS validé.
|
||
|
||
---
|
||
|
||
## Vue d’ensemble
|
||
|
||
| Phase | Quoi | Ancien VPS | Nouveau VPS |
|
||
|-------|------|------------|-------------|
|
||
| A | Préparer code + `.env` + Postgres | Prod inchangée | Clone + secrets frais |
|
||
| B | Stack HTTP smoke test | Prod inchangée | `:9080` sur l’IP |
|
||
| C | Admin setup + hot wallets | — | `/setup`, seed hots |
|
||
| D | HTTPS + DNS `tloto.net` | Puis arrêter | `:9443` / gateway |
|
||
| E | Fermer l’ancien | Stop stack | Prod unique |
|
||
|
||
---
|
||
|
||
## Phase A — Clone, secrets, base vide
|
||
|
||
Sur ton PC (PowerShell) :
|
||
|
||
```powershell
|
||
ssh deploy@191.215.41.53
|
||
```
|
||
|
||
Sur le VPS :
|
||
|
||
```bash
|
||
sudo apt-get update -y
|
||
# Node optionnel (pour npm run phase-b:*) — sinon docker compose seul
|
||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||
sudo apt-get install -y nodejs
|
||
|
||
cd ~
|
||
git clone https://github.com/japhni/games-project.git games_app
|
||
cd games_app
|
||
git checkout master
|
||
git pull
|
||
|
||
cp .env.example .env
|
||
chmod 600 .env
|
||
```
|
||
|
||
### Générer les secrets (sur le VPS) — sauvegarde offline
|
||
|
||
```bash
|
||
echo "ENCRYPTION_KEY=$(openssl rand -hex 32)"
|
||
echo "JWT_SECRET=$(openssl rand -base64 48 | tr -d '\n=/+' | head -c 48)"
|
||
echo "REDIS_PASSWORD=$(openssl rand -hex 32)"
|
||
echo "INITIAL_SETUP_TOKEN=$(openssl rand -hex 24)"
|
||
echo "BREAK_GLASS_TOKEN=$(openssl rand -hex 32)"
|
||
echo "POSTGRES_PASSWORD=$(openssl rand -hex 24)"
|
||
# Mnemonic 24 mots — générer hors ligne (MetaMask / outil BIP39) puis coller dans .env
|
||
```
|
||
|
||
Édite `.env` (`nano .env`) — points critiques :
|
||
|
||
```env
|
||
POSTGRES_USER=postgres
|
||
POSTGRES_PASSWORD=<généré>
|
||
POSTGRES_DB=games_platform_db
|
||
DATABASE_URL=postgresql://postgres:<généré>@host.docker.internal:5432/games_platform_db
|
||
DATABASE_PASSWORD=<généré>
|
||
|
||
REDIS_PASSWORD=<généré>
|
||
JWT_SECRET=<généré>
|
||
ENCRYPTION_KEY=<64 hex>
|
||
PLATFORM_MNEMONIC=<24 mots BIP39 nouveaux>
|
||
INITIAL_SETUP_TOKEN=<généré>
|
||
BREAK_GLASS_TOKEN=<généré>
|
||
|
||
# Phase B smoke (IP) — avant DNS
|
||
APP_PUBLIC_URL=http://191.215.41.53:9080
|
||
CORS_ORIGINS=http://191.215.41.53:9080
|
||
VITE_API_BASE_URL=http://191.215.41.53:9080
|
||
VITE_WS_ENABLED=true
|
||
VITE_WS_URL=ws://191.215.41.53:9080/ws/v1/games/candle-predict
|
||
|
||
# Mainnet (prod)
|
||
TRON_NODE_URL=https://api.trongrid.io
|
||
TRON_CONFIRMATIONS=20
|
||
BSC_RPC_URL=https://bsc-dataseed.binance.org
|
||
BSC_CONFIRMATIONS=15
|
||
ALLOW_WITHDRAWALS=false
|
||
SWEEP_ENABLED=false
|
||
|
||
# Optionnel : reprendre Turnstile / SMTP depuis l’ancien .env (pas les clés crypto)
|
||
# TURNSTILE_SITE_KEY=...
|
||
# TURNSTILE_SECRET_KEY=...
|
||
# SMTP_*=...
|
||
# EMAIL_FROM=...
|
||
|
||
RUN_MIGRATE_ON_START=0
|
||
CERTBOT_EMAIL=ton@email.com
|
||
CERTBOT_DOMAIN1=tloto.net
|
||
CERTBOT_DOMAIN2=www.tloto.net
|
||
```
|
||
|
||
### Postgres hôte — user + DB
|
||
|
||
```bash
|
||
# Définir le mot de passe postgres OS si besoin, puis :
|
||
sudo -u postgres psql -c "ALTER USER postgres PASSWORD '<même POSTGRES_PASSWORD que .env>';"
|
||
sudo -u postgres psql -c "SELECT 1 FROM pg_database WHERE datname='games_platform_db'" | grep -q 1 \
|
||
|| sudo -u postgres createdb -O postgres games_platform_db
|
||
|
||
# listen localhost déjà posé par harden-vps.sh
|
||
sudo ss -tlnp | grep 5432
|
||
```
|
||
|
||
---
|
||
|
||
## Phase B — Premier démarrage HTTP
|
||
|
||
```bash
|
||
cd ~/games_app
|
||
# Si npm disponible :
|
||
sudo npm run phase-b:init
|
||
|
||
# Sinon Docker seul :
|
||
sudo docker compose run --rm --no-deps --build backend node dist/db/migrate.js
|
||
sudo docker compose --profile http --profile clamav up -d --build
|
||
```
|
||
|
||
Vérifs :
|
||
|
||
```bash
|
||
sudo docker compose ps
|
||
curl -fsS http://127.0.0.1:9080/health
|
||
curl -fsS http://191.215.41.53:9080/setup/status
|
||
```
|
||
|
||
Navigateur : `http://191.215.41.53:9080/setup` avec `INITIAL_SETUP_TOKEN`.
|
||
|
||
---
|
||
|
||
## Phase C — Post-setup
|
||
|
||
1. Créer Super Admin + activer **2FA** + sauver recovery codes offline.
|
||
2. (Recommandé) 2ᵉ admin.
|
||
3. Seed hot wallets **une seule fois** :
|
||
|
||
```bash
|
||
cd ~/games_app
|
||
sudo docker compose run --rm --no-deps --build backend node dist/scripts/seedHotWallets.js
|
||
sudo npm run phase-b:verify-deposit-addresses
|
||
# ou : sudo docker compose run --rm --no-deps backend node dist/scripts/verifyDepositAddresses.js
|
||
```
|
||
|
||
4. Noter les **nouvelles** adresses hot TRON + BSC (différentes de l’ancien mnémonique).
|
||
5. Configurer cold MetaMask dans Treasury + `SWEEP_COLD_ALLOWLIST` si besoin.
|
||
6. SQL recommandé :
|
||
|
||
```sql
|
||
INSERT INTO system_settings (key, value, updated_at)
|
||
VALUES ('encryption_key_rotated_at', NOW()::text, NOW())
|
||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW();
|
||
```
|
||
|
||
7. Intervalles Candle Predict : le seed applique Min tie **2** / Max **95** / Pool **1.9** / Payout **1.9**.
|
||
|
||
---
|
||
|
||
## Phase D — Cutover DNS + HTTPS
|
||
|
||
1. TTL DNS bas (si possible) sur `tloto.net` / `www`.
|
||
2. Mettre à jour `.env` **avant** rebuild web :
|
||
|
||
```env
|
||
APP_PUBLIC_URL=https://tloto.net:9443
|
||
CORS_ORIGINS=https://tloto.net:9443,https://www.tloto.net:9443
|
||
VITE_API_BASE_URL=https://tloto.net:9443
|
||
VITE_WS_URL=wss://tloto.net:9443/ws/v1/games/candle-predict
|
||
```
|
||
|
||
(Adapte si le gateway sert l’apex en `:443` sans port — voir `docs/DEPLOY-VPS.md`.)
|
||
|
||
3. Enregistrements **A** → `191.215.41.53`.
|
||
4. Certificat :
|
||
|
||
```bash
|
||
cd ~/games_app
|
||
sudo npm run ssl:dns-init # ou parcours documenté dans DEPLOY-VPS
|
||
sudo npm run phase-b:up:https
|
||
```
|
||
|
||
5. Smoke :
|
||
|
||
```bash
|
||
curl -fsS https://tloto.net:9443/health
|
||
# login admin, dépôt test BEP20, retraits toujours OFF
|
||
```
|
||
|
||
6. App mobile : rebuild avec `API_BASE_URL` / prod si hardcodé autrement.
|
||
|
||
---
|
||
|
||
## Phase E — Ancien VPS
|
||
|
||
Après validation (24–48 h recommandées) :
|
||
|
||
```bash
|
||
# Sur l’ANCIEN serveur uniquement
|
||
cd ~/…/games_app # chemin réel
|
||
sudo npm run phase-b:down
|
||
# optionnel : snapshot / pg_dump archive offline avant DROP
|
||
```
|
||
|
||
Ne supprime l’ancien dump/host qu’après confirmation MetaMask + nouvelle prod OK.
|
||
|
||
---
|
||
|
||
## Rollback rapide
|
||
|
||
Si le nouveau VPS échoue après DNS : remettre les **A** vers l’**ancienne** IP, remonter l’ancienne stack. Les nouveaux hot du VPS B restent orphelins jusqu’à réutilisation éventuelle de leur mnémonique (gardé offline).
|
||
|
||
---
|
||
|
||
## Checklist express
|
||
|
||
- [ ] Fonds cold MetaMask OK ; hot ancien vidé (dust OK)
|
||
- [ ] `ssh deploy@191.215.41.53` OK
|
||
- [ ] Clone `games_app` + `.env` **nouveaux** secrets
|
||
- [ ] DB `games_platform_db` créée
|
||
- [ ] `phase-b:init` HTTP + `/setup`
|
||
- [ ] Hot wallets seed + verify
|
||
- [ ] DNS → nouvelle IP + HTTPS
|
||
- [ ] Ancien VPS arrêté
|
||
|
||
Références : [PREDEPLOY-CHECKLIST.md](./PREDEPLOY-CHECKLIST.md), [docs/DEPLOY-VPS.md](../../docs/DEPLOY-VPS.md).
|