- Scripts de déploiement (deploy.sh, stop.sh, check-config.sh) - Documentation complète (README, QUICKSTART, etc.) - Configuration portable avec chemins relatifs
307 lines
8.2 KiB
Markdown
307 lines
8.2 KiB
Markdown
# 📝 Résumé des Modifications - Configuration Portable
|
|
|
|
Ce document résume les modifications apportées pour rendre le déploiement portable et simplifié.
|
|
|
|
## 🎯 Objectifs Atteints
|
|
|
|
✅ **Chemins relatifs** : Plus de chemins absolus du type `/home/innotex/...`
|
|
✅ **Variables d'environnement** : Configuration centralisée via fichiers `.env`
|
|
✅ **Détection automatique de l'hôte** : L'API fonctionne avec localhost, IP ou domaine
|
|
✅ **Déploiement unifié** : Un seul script pour tout démarrer
|
|
✅ **Portabilité totale** : Fonctionne sur n'importe quelle machine Linux
|
|
|
|
## 📁 Fichiers Créés
|
|
|
|
### Dossier racine (`Serveur NationsGlory/`)
|
|
- **`deploy.sh`** : Script principal de déploiement (démarre MC + Web)
|
|
- **`stop.sh`** : Script d'arrêt de tous les services
|
|
- **`check-config.sh`** : Script de vérification de configuration
|
|
- **`README.md`** : Documentation principale du projet
|
|
- **`QUICKSTART.md`** : Guide de démarrage rapide
|
|
|
|
### Application Web (`WebNationsGlory_ServeurBuild_Red/`)
|
|
- **`.env.example`** : Template de configuration avec toutes les variables
|
|
- **`nginx.conf.example`** : Configuration nginx pour production avec SSL
|
|
|
|
## 🔧 Fichiers Modifiés
|
|
|
|
### Application Web
|
|
|
|
#### `docker-compose.yml`
|
|
**Avant** :
|
|
```yaml
|
|
environment:
|
|
SERVER_DIR: /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red
|
|
volumes:
|
|
- /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red:/mc-server
|
|
```
|
|
|
|
**Après** :
|
|
```yaml
|
|
env_file:
|
|
- .env
|
|
environment:
|
|
SERVER_DIR: /mc-server
|
|
RCON_HOST: ${RCON_HOST:-localhost}
|
|
# ... autres variables
|
|
volumes:
|
|
- ${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}:/mc-server:ro
|
|
network_mode: host # Pour accès depuis l'extérieur
|
|
```
|
|
|
|
#### `backend/src/server.js`
|
|
**Modification** : CORS dynamique pour supporter toutes les origines
|
|
```javascript
|
|
// Avant
|
|
app.use(cors({ origin: true, credentials: true }));
|
|
|
|
// Après
|
|
app.use(cors({
|
|
origin: (origin, callback) => {
|
|
const allowedOrigin = process.env.CORS_ORIGIN || true;
|
|
callback(null, allowedOrigin);
|
|
},
|
|
credentials: true
|
|
}));
|
|
```
|
|
|
|
#### `frontend/public/js/app.js`
|
|
**Avant** :
|
|
```javascript
|
|
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
|
? 'http://localhost:4001/api'
|
|
: `http://${window.location.hostname}:4001/api`;
|
|
```
|
|
|
|
**Après** :
|
|
```javascript
|
|
const API_URL = (() => {
|
|
const protocol = window.location.protocol; // http: ou https:
|
|
const hostname = window.location.hostname; // IP ou domaine
|
|
const port = '4001';
|
|
|
|
if (window.location.port === port) {
|
|
return `${protocol}//${hostname}:${port}/api`;
|
|
}
|
|
|
|
return `${protocol}//${hostname}:${port}/api`;
|
|
})();
|
|
```
|
|
|
|
✅ **Supporte automatiquement** : `http:` et `https:`, localhost, IP, domaine
|
|
|
|
### Serveur Minecraft
|
|
|
|
#### `docker-compose.yml`
|
|
Ajout du support des variables d'environnement :
|
|
```yaml
|
|
env_file:
|
|
- .env
|
|
environment:
|
|
SERVER_PORT: ${SERVER_PORT:-25565}
|
|
RCON_PORT: ${RCON_PORT:-25575}
|
|
RCON_PASSWORD: ${RCON_PASSWORD:-minecraft}
|
|
# ... etc
|
|
```
|
|
|
|
#### `.env.example`
|
|
Complété avec toutes les variables nécessaires
|
|
|
|
## 🔐 Configuration Requise
|
|
|
|
### Fichier `.env` du serveur Minecraft
|
|
|
|
```bash
|
|
cp NationsGlory_ServeurBuild_Red/.env.example NationsGlory_ServeurBuild_Red/.env
|
|
nano NationsGlory_ServeurBuild_Red/.env
|
|
```
|
|
|
|
**Paramètres importants** :
|
|
- `RCON_PASSWORD` : Changez pour la production
|
|
|
|
### Fichier `.env` de l'application web
|
|
|
|
```bash
|
|
cp WebNationsGlory_ServeurBuild_Red/.env.example WebNationsGlory_ServeurBuild_Red/.env
|
|
nano WebNationsGlory_ServeurBuild_Red/.env
|
|
```
|
|
|
|
**Paramètres critiques** :
|
|
- `SESSION_SECRET` : Générez avec `openssl rand -base64 32`
|
|
- `RCON_PASSWORD` : **Doit être identique** au serveur MC
|
|
- `MC_SERVER_PATH` : Chemin relatif vers le serveur (défaut: `../NationsGlory_ServeurBuild_Red`)
|
|
|
|
## 🚀 Utilisation
|
|
|
|
### 1. Vérification de la configuration
|
|
```bash
|
|
./check-config.sh
|
|
```
|
|
|
|
### 2. Déploiement
|
|
```bash
|
|
./deploy.sh
|
|
```
|
|
|
|
### 3. Accès
|
|
- **Serveur Minecraft** : `votre-ip:25565`
|
|
- **Interface Web** : `http://votre-ip:4001`
|
|
|
|
### 4. Arrêt
|
|
```bash
|
|
./stop.sh
|
|
```
|
|
|
|
## 🌐 Accès à Distance
|
|
|
|
L'application web fonctionne maintenant nativement avec :
|
|
|
|
- ✅ `http://localhost:4001` (local)
|
|
- ✅ `http://192.168.1.X:4001` (réseau local)
|
|
- ✅ `http://votre-ip-publique:4001` (internet)
|
|
- ✅ `http://votre-domaine.com:4001` (domaine)
|
|
- ✅ `https://votre-domaine.com` (avec nginx reverse proxy)
|
|
|
|
**Aucune configuration supplémentaire nécessaire** dans le code.
|
|
|
|
## 📦 Portabilité
|
|
|
|
### Déployer sur une nouvelle machine
|
|
|
|
1. **Copier le dossier** `Serveur NationsGlory` complet
|
|
2. **Créer les fichiers `.env`** :
|
|
```bash
|
|
cd WebNationsGlory_ServeurBuild_Red
|
|
cp .env.example .env
|
|
nano .env # Configurer SESSION_SECRET et RCON_PASSWORD
|
|
|
|
cd ../NationsGlory_ServeurBuild_Red
|
|
cp .env.example .env
|
|
nano .env # Configurer RCON_PASSWORD (même valeur)
|
|
```
|
|
3. **Déployer** :
|
|
```bash
|
|
cd ..
|
|
./deploy.sh
|
|
```
|
|
|
|
**C'est tout !** 🎉
|
|
|
|
### Pas de dépendances aux chemins
|
|
|
|
- ❌ Plus de `/home/innotex/...`
|
|
- ❌ Plus de configuration IP hardcodée
|
|
- ✅ Tout est relatif au dossier parent
|
|
- ✅ Détection automatique de l'environnement
|
|
|
|
## 🔒 Sécurité
|
|
|
|
### Checklist de production
|
|
|
|
- [ ] Changez `SESSION_SECRET` dans `.env` de l'app web
|
|
- [ ] Changez `RCON_PASSWORD` dans les deux `.env`
|
|
- [ ] Ouvrez les ports firewall (25565, 25575, 4001)
|
|
- [ ] Configurez nginx avec SSL (optionnel mais recommandé)
|
|
- [ ] Restreignez l'accès admin (firewall, VPN)
|
|
- [ ] Configurez les sauvegardes automatiques
|
|
|
|
### Exemple de génération de secrets
|
|
|
|
```bash
|
|
# SESSION_SECRET
|
|
openssl rand -base64 32
|
|
|
|
# RCON_PASSWORD (alphanumérique)
|
|
openssl rand -base64 16 | tr -dc 'a-zA-Z0-9'
|
|
```
|
|
|
|
## 📊 Architecture
|
|
|
|
```
|
|
Serveur NationsGlory/
|
|
├── deploy.sh # Démarrage unifié
|
|
├── stop.sh # Arrêt unifié
|
|
├── check-config.sh # Vérification
|
|
│
|
|
├── NationsGlory_ServeurBuild_Red/
|
|
│ ├── .env # Config du serveur MC
|
|
│ ├── docker-compose.yml # Orchestration Docker
|
|
│ └── mcpc.jar # Serveur Minecraft
|
|
│
|
|
└── WebNationsGlory_ServeurBuild_Red/
|
|
├── .env # Config de l'app web
|
|
├── docker-compose.yml # Orchestration Docker
|
|
├── backend/ # API Node.js
|
|
└── frontend/ # Interface web
|
|
|
|
Communication:
|
|
- App Web → Serveur MC (RCON sur localhost:25575)
|
|
- Client Web → App Web (HTTP sur port 4001)
|
|
- Client MC → Serveur MC (TCP sur port 25565)
|
|
```
|
|
|
|
## 🎓 Points Techniques
|
|
|
|
### 1. Montage relatif du serveur MC
|
|
|
|
Le docker-compose de l'app web monte le serveur avec un chemin relatif :
|
|
```yaml
|
|
volumes:
|
|
- ${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}:/mc-server:ro
|
|
```
|
|
|
|
Le `:ro` (read-only) assure que l'app web ne modifie pas les fichiers du serveur.
|
|
|
|
### 2. Network mode host
|
|
|
|
```yaml
|
|
network_mode: host
|
|
```
|
|
|
|
Permet à l'application d'être accessible depuis l'extérieur sans NAT Docker.
|
|
Nécessaire pour que l'API fonctionne avec n'importe quelle IP/domaine.
|
|
|
|
### 3. Détection automatique du protocole
|
|
|
|
Le frontend détecte automatiquement `http:` ou `https:` depuis `window.location.protocol`,
|
|
permettant le support SSL transparent via nginx.
|
|
|
|
### 4. Variables d'environnement avec valeurs par défaut
|
|
|
|
```yaml
|
|
RCON_PORT: ${RCON_PORT:-25575}
|
|
```
|
|
|
|
Si `RCON_PORT` n'est pas défini dans `.env`, utilise `25575`.
|
|
|
|
## 🐛 Dépannage
|
|
|
|
### Le script deploy.sh échoue
|
|
|
|
```bash
|
|
./check-config.sh # Vérifier la configuration
|
|
```
|
|
|
|
### L'app web ne se connecte pas au serveur MC
|
|
|
|
1. Vérifiez que `RCON_PASSWORD` est identique
|
|
2. Vérifiez que le serveur MC a démarré complètement
|
|
3. Testez RCON : `docker exec -it mc-nationsglory rcon-cli`
|
|
|
|
### L'API ne répond pas depuis l'extérieur
|
|
|
|
1. Vérifiez le pare-feu : `sudo ufw status`
|
|
2. Ouvrez le port : `sudo ufw allow 4001/tcp`
|
|
3. Testez : `curl http://votre-ip:4001/api/health`
|
|
|
|
## 📚 Références
|
|
|
|
- [Docker Compose Documentation](https://docs.docker.com/compose/)
|
|
- [Express.js CORS](https://expressjs.com/en/resources/middleware/cors.html)
|
|
- [Nginx Reverse Proxy](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/)
|
|
|
|
---
|
|
|
|
**Date de modification** : Février 2026
|
|
**Version** : 2.0 - Configuration portable
|