talas-group/03_APPS_&_SERVICES/CONFIGURATION_ENVIRONNEMENT.md

257 lines
8.5 KiB
Markdown
Raw Permalink Normal View History

# Configuration & Environnement Veza
> Variables d'environnement, Docker Compose, et paramètres de déploiement.
> Source : `.env.example`, `docker-compose*.yml`, `Makefile`
## Variables d'environnement
Toutes les variables sont définies dans `.env.example` à la racine du monorepo.
### Core
| Variable | Exemple | Description |
|----------|---------|-------------|
| `APP_DOMAIN` | `veza.fr` | Domaine principal |
| `FRONTEND_URL` | `http://veza.fr:5173` | URL frontend |
| `PORT_BACKEND` | `18080` | Port API backend |
| `PORT_STREAM` | `18082` | Port stream server |
| `APP_ENV` | `development` | Environnement (development/staging/production) |
### Base de données (PostgreSQL)
| Variable | Exemple | Description |
|----------|---------|-------------|
| `DB_USER` | `veza` | Utilisateur PostgreSQL |
| `DB_PASSWORD` | `password` | Mot de passe |
| `DB_NAME` | `veza` | Nom de la base |
| `DATABASE_URL` | `postgres://veza:password@localhost:15432/veza?sslmode=disable` | URL complète |
### Redis
| Variable | Exemple | Description |
|----------|---------|-------------|
| `REDIS_URL` | `redis://:password@localhost:16379` | URL Redis |
| `REDIS_PASSWORD` | `devpassword` | Mot de passe Redis |
### RabbitMQ
| Variable | Exemple | Description |
|----------|---------|-------------|
| `RABBITMQ_URL` | `amqp://veza:password@localhost:15672/` | URL AMQP |
| `RABBITMQ_DEFAULT_USER` | `veza` | Utilisateur |
| `RABBITMQ_DEFAULT_PASS` | `devpassword` | Mot de passe |
### JWT & Sécurité
| Variable | Exemple | Description |
|----------|---------|-------------|
| `JWT_SECRET` | `min-32-characters...` | Secret JWT (fallback HS256) |
| `JWT_PRIVATE_KEY_PATH` | `/path/to/jwt-private.pem` | Clé privée RS256 |
| `JWT_PUBLIC_KEY_PATH` | `/path/to/jwt-public.pem` | Clé publique RS256 |
| `JWT_ISSUER` | `veza-api` | Émetteur JWT |
| `JWT_AUDIENCE` | `veza-platform` | Audience JWT |
| `OAUTH_ENCRYPTION_KEY` | `<32-byte-hex>` | Chiffrement OAuth |
| `OAUTH_ALLOWED_REDIRECT_DOMAINS` | `https://veza.fr:5173` | Domaines OAuth autorisés |
| `CHAT_JWT_SECRET` | `<différent de JWT_SECRET>` | Secret JWT chat |
### Stockage S3 (MinIO)
| Variable | Exemple | Description |
|----------|---------|-------------|
| `S3_ENABLED` | `true` | Activer S3 |
| `S3_BUCKET` | `veza-uploads` | Nom du bucket |
| `S3_REGION` | `us-east-1` | Région |
| `S3_ENDPOINT` | `http://localhost:19000` | Endpoint MinIO |
| `S3_ACCESS_KEY` | `...` | Clé d'accès |
| `S3_SECRET_KEY` | `...` | Clé secrète |
### Streaming & Live
| Variable | Exemple | Description |
|----------|---------|-------------|
| `STREAM_HLS_BASE_URL` | `http://localhost:18083/live` | URL base HLS |
| `NGINX_RTMP_HOST` | `localhost` | Hôte RTMP |
| `RTMP_CALLBACK_SECRET` | `<shared-secret>` | Secret callbacks RTMP |
### Elasticsearch
| Variable | Exemple | Description |
|----------|---------|-------------|
| `ELASTICSEARCH_URL` | `http://localhost:19200` | URL Elasticsearch |
| `ELASTICSEARCH_AUTO_INDEX` | `true` | Auto-indexation au démarrage |
### Antivirus
| Variable | Exemple | Description |
|----------|---------|-------------|
| `ENABLE_CLAMAV` | `true` | Activer le scan antivirus |
| `CLAMAV_REQUIRED` | `true` | Échouer si ClamAV indisponible |
### Paiements
| Variable | Exemple | Description |
|----------|---------|-------------|
| `STRIPE_CONNECT_ENABLED` | `true` | Activer Stripe Connect |
| `HYPERSWITCH_WEBHOOK_SECRET` | `<secret>` | Secret webhook paiement |
### Logs & Monitoring
| Variable | Exemple | Description |
|----------|---------|-------------|
| `LOG_LEVEL` | `INFO` | Niveau de log (DEBUG active les stack traces) |
| `LOG_DIR` | `/var/log/veza` | Répertoire des logs |
| `LOG_FORMAT` | `json` | Format (json en prod, text en dev) |
| `SENTRY_DSN` | `https://...@ingest.sentry.io/0` | DSN Sentry |
| `SENTRY_ENVIRONMENT` | `development` | Environnement Sentry |
| `SENTRY_SAMPLE_RATE_ERRORS` | `1.0` | Taux échantillonnage erreurs |
| `SENTRY_SAMPLE_RATE_TRANSACTIONS` | `0.1` | Taux échantillonnage transactions |
| `PROMETHEUS_URL` | `http://prometheus:9090` | URL Prometheus |
### Frontend
| Variable | Exemple | Description |
|----------|---------|-------------|
| `VITE_API_URL` | `/api/v1` | URL API (relative ou absolue) |
| `VITE_USE_MSW` | `1` | Activer mocks MSW |
| `VITE_STORYBOOK` | `1` | Mode Storybook |
| `VITE_SENTRY_DSN` | `https://...` | DSN Sentry frontend |
---
## Docker Compose
### Développement (`docker-compose.yml`)
Services d'infrastructure pour le développement local :
| Service | Image | Port exposé | Port interne |
|---------|-------|------------|--------------|
| `postgres` | PostgreSQL 16 | 15432 | 5432 |
| `redis` | Redis 7 | 16379 | 6379 |
| `rabbitmq` | RabbitMQ 3 | 15672 (AMQP), 25672 (management) | 5672, 15672 |
| `clamav` | ClamAV 1.4 | 13310 | 3310 |
| `minio` | MinIO | 19000 | 9000 |
| `elasticsearch` | Elasticsearch | 19200 | 9200 |
```bash
# Lancer l'infrastructure
docker-compose up -d
# Ou via Makefile
make infra
```
### Production (`docker-compose.prod.yml`)
Mêmes services avec :
- **Volumes persistants** pour les données
- **Limites de ressources** (CPU, mémoire)
- **Health checks** sur tous les services
- **Configuration logging** centralisée
- **Isolation réseau** entre services
- **Restart policy** : `unless-stopped`
---
## Dockerfiles des services applicatifs
### Backend API (Go)
| Fichier | Base | Taille | Usage |
|---------|------|--------|-------|
| `veza-backend-api/Dockerfile` | `golang:1.21-alpine` | ~300 Mo | Développement |
| `veza-backend-api/Dockerfile.production` | `scratch` | ~15 Mo | Production (binaire statique) |
### Stream Server (Rust)
| Fichier | Base | Taille | Usage |
|---------|------|--------|-------|
| `veza-stream-server/Dockerfile` | `rust:latest` | ~1 Go | Développement |
| `veza-stream-server/Dockerfile.production` | `debian:bookworm-slim` | ~100 Mo | Production |
### Frontend (React)
| Fichier | Base | Taille | Usage |
|---------|------|--------|-------|
| `apps/web/Dockerfile` | `node:20-alpine``nginx:alpine` | ~50 Mo | Développement |
| `apps/web/Dockerfile.production` | `nginx:latest` | ~30 Mo | Production |
---
## Commandes Makefile
```bash
# Développement
make dev # Stack complète (backend Docker, web local)
make dev-full # Tous les services locaux + hot reload
make dev-web # Frontend seul
make dev-backend-api # Backend seul
make dev-stream-server # Stream server seul
# Infrastructure
make infra # docker-compose up -d
# Build
make build # Build tous les conteneurs
# Base de données
make migrate-up # Appliquer les migrations
make migrate-down # Rollback dernière migration
# Tests
make test # Tous les tests
make test-backend # Tests backend Go
make test-frontend # Tests frontend Vitest
make test-e2e # Tests end-to-end
```
---
## Nginx (reverse proxy frontend)
Fichier : `apps/web/nginx.conf`
Configuration du reverse proxy en production :
```
Client → Nginx (port 80/443)
├── / → fichiers statiques (SPA)
├── /api/* → Backend Go (port 8080)
├── /ws/* → Chat WebSocket (port 8081)
└── /stream/* → Stream Server Rust (port 8082)
```
Fonctionnalités :
- **SPA fallback** : Toutes les routes non-API renvoient `index.html`
- **Gzip** : Compression activée
- **Cache** : Headers pour assets statiques (JS, CSS, images)
- **Sécurité** : X-Frame-Options, X-Content-Type-Options
---
## Différences dev / staging / production
| Aspect | Développement | Staging | Production |
|--------|--------------|---------|------------|
| `APP_ENV` | development | staging | production |
| CORS | Wildcard `*` | Domaines staging | Domaines stricts |
| CSRF | Optionnel (si Redis) | Obligatoire | Obligatoire |
| Swagger/docs | Activé | Activé | **Désactivé** |
| pprof debug | Activé | Désactivé | **Désactivé** |
| Logs | Texte, DEBUG | JSON, INFO | JSON, WARN+ |
| Stack traces | Dans les réponses | Pas dans les réponses | Pas dans les réponses |
| Sentry | Optionnel | Activé | Activé |
| ClamAV | Optionnel | Recommandé | **Obligatoire** |
| Redis | Optionnel | Obligatoire | **Obligatoire** |
| Rate limiting | Souple | Modéré | Strict (DDoS) |
---
## Documents liés
- [[ARCHITECTURE_VEZA]] — Architecture globale
- [[ROUTES_API]] — Endpoints API
- [[SCHEMA_BASE_DE_DONNEES]] — Schéma PostgreSQL
- [[SERVEUR_STREAMING_RUST]] — Serveur streaming
- [[FRONTEND_REACT]] — Architecture frontend