feat: add local Docker Compose stack for Mac testing
- Add docker-compose.local.yml with all services - Use production images from Scaleway registry - Configure local PostgreSQL, Redis, MinIO - Add comprehensive testing guide in LOCAL_TESTING.md - Includes debugging commands and troubleshooting This allows testing production Docker images locally before deploying to Portainer.
This commit is contained in:
parent
2505a36b13
commit
c002c9a1d3
374
LOCAL_TESTING.md
Normal file
374
LOCAL_TESTING.md
Normal file
@ -0,0 +1,374 @@
|
||||
# 🧪 Guide de Test Local avec Docker Compose
|
||||
|
||||
Ce guide explique comment tester les images Docker de production localement sur ton Mac.
|
||||
|
||||
## 📋 Prérequis
|
||||
|
||||
- Docker Desktop installé sur Mac
|
||||
- Accès au Scaleway Container Registry (credentials)
|
||||
|
||||
## 🔐 Étape 1: Login au Registry Scaleway
|
||||
|
||||
```bash
|
||||
# Login au registry Scaleway
|
||||
docker login rg.fr-par.scw.cloud/weworkstudio
|
||||
# Username: nologin
|
||||
# Password: <TON_REGISTRY_TOKEN>
|
||||
```
|
||||
|
||||
## 🚀 Étape 2: Lancer la Stack
|
||||
|
||||
```bash
|
||||
# Depuis la racine du projet
|
||||
cd /Users/david/Documents/xpeditis/dev/xpeditis2.0
|
||||
|
||||
# Lancer tous les services
|
||||
docker-compose -f docker-compose.local.yml up -d
|
||||
|
||||
# Suivre les logs
|
||||
docker-compose -f docker-compose.local.yml logs -f
|
||||
|
||||
# Suivre les logs d'un service spécifique
|
||||
docker-compose -f docker-compose.local.yml logs -f backend
|
||||
docker-compose -f docker-compose.local.yml logs -f frontend
|
||||
```
|
||||
|
||||
## 🔍 Étape 3: Vérifier que Tout Fonctionne
|
||||
|
||||
### Vérifier les services
|
||||
|
||||
```bash
|
||||
# Voir l'état de tous les conteneurs
|
||||
docker-compose -f docker-compose.local.yml ps
|
||||
|
||||
# Devrait afficher:
|
||||
# NAME STATUS PORTS
|
||||
# xpeditis-backend-local Up 0.0.0.0:4000->4000/tcp
|
||||
# xpeditis-frontend-local Up 0.0.0.0:3000->3000/tcp
|
||||
# xpeditis-postgres-local Up 0.0.0.0:5432->5432/tcp
|
||||
# xpeditis-redis-local Up 0.0.0.0:6379->6379/tcp
|
||||
# xpeditis-minio-local Up 0.0.0.0:9000-9001->9000-9001/tcp
|
||||
```
|
||||
|
||||
### Tester les endpoints
|
||||
|
||||
```bash
|
||||
# Backend Health Check
|
||||
curl http://localhost:4000/health
|
||||
# Devrait retourner: {"status":"ok"}
|
||||
|
||||
# Frontend
|
||||
open http://localhost:3000
|
||||
# Devrait ouvrir l'application dans le navigateur
|
||||
|
||||
# Backend API Docs
|
||||
open http://localhost:4000/api/docs
|
||||
# Devrait ouvrir Swagger UI
|
||||
|
||||
# MinIO Console
|
||||
open http://localhost:9001
|
||||
# Login: minioadmin / minioadmin
|
||||
```
|
||||
|
||||
## 🛠️ Étape 4: Créer le Bucket MinIO
|
||||
|
||||
1. **Ouvre MinIO Console**: http://localhost:9001
|
||||
2. **Login**:
|
||||
- Username: `minioadmin`
|
||||
- Password: `minioadmin`
|
||||
3. **Créer le bucket**:
|
||||
- Clique sur **Buckets** → **Create Bucket**
|
||||
- Nom: `xpeditis-csv-rates`
|
||||
- Access Policy: **Private**
|
||||
- **Create Bucket**
|
||||
|
||||
## 🗄️ Étape 5: Initialiser la Base de Données
|
||||
|
||||
```bash
|
||||
# Exécuter les migrations
|
||||
docker-compose -f docker-compose.local.yml exec backend npm run migration:run
|
||||
|
||||
# Ou se connecter à PostgreSQL directement
|
||||
docker-compose -f docker-compose.local.yml exec postgres psql -U xpeditis -d xpeditis_dev
|
||||
```
|
||||
|
||||
## 📊 Étape 6: Tester les Fonctionnalités
|
||||
|
||||
### 1. Créer un compte utilisateur
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:4000/api/v1/auth/register \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "test@example.com",
|
||||
"password": "Test1234!@#$",
|
||||
"firstName": "Test",
|
||||
"lastName": "User"
|
||||
}'
|
||||
```
|
||||
|
||||
### 2. Se connecter
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:4000/api/v1/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "test@example.com",
|
||||
"password": "Test1234!@#$"
|
||||
}'
|
||||
|
||||
# Récupère le token JWT de la réponse
|
||||
```
|
||||
|
||||
### 3. Tester l'upload CSV (avec token)
|
||||
|
||||
```bash
|
||||
TOKEN="<ton_jwt_token>"
|
||||
|
||||
curl -X POST http://localhost:4000/api/v1/admin/csv-rates/upload \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-F "file=@/path/to/your/file.csv" \
|
||||
-F "companyName=Test Company" \
|
||||
-F "companyEmail=test@company.com"
|
||||
```
|
||||
|
||||
### 4. Vérifier que le CSV est dans MinIO
|
||||
|
||||
1. Ouvre http://localhost:9001
|
||||
2. Va dans **Buckets** → **xpeditis-csv-rates**
|
||||
3. Tu devrais voir le fichier dans `csv-rates/test-company.csv`
|
||||
|
||||
## 🔄 Commandes Utiles
|
||||
|
||||
### Redémarrer un service
|
||||
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml restart backend
|
||||
docker-compose -f docker-compose.local.yml restart frontend
|
||||
```
|
||||
|
||||
### Voir les logs en temps réel
|
||||
|
||||
```bash
|
||||
# Tous les services
|
||||
docker-compose -f docker-compose.local.yml logs -f
|
||||
|
||||
# Backend uniquement
|
||||
docker-compose -f docker-compose.local.yml logs -f backend
|
||||
|
||||
# 100 dernières lignes
|
||||
docker-compose -f docker-compose.local.yml logs --tail=100 backend
|
||||
```
|
||||
|
||||
### Accéder à un conteneur
|
||||
|
||||
```bash
|
||||
# Shell dans le backend
|
||||
docker-compose -f docker-compose.local.yml exec backend sh
|
||||
|
||||
# Shell dans PostgreSQL
|
||||
docker-compose -f docker-compose.local.yml exec postgres psql -U xpeditis -d xpeditis_dev
|
||||
|
||||
# Shell dans Redis
|
||||
docker-compose -f docker-compose.local.yml exec redis redis-cli -a xpeditis_redis_password
|
||||
```
|
||||
|
||||
### Mettre à jour les images
|
||||
|
||||
```bash
|
||||
# Pull les dernières images depuis Scaleway
|
||||
docker-compose -f docker-compose.local.yml pull
|
||||
|
||||
# Redémarre avec les nouvelles images
|
||||
docker-compose -f docker-compose.local.yml up -d
|
||||
```
|
||||
|
||||
### Nettoyer complètement
|
||||
|
||||
```bash
|
||||
# Arrêter et supprimer les conteneurs
|
||||
docker-compose -f docker-compose.local.yml down
|
||||
|
||||
# Supprimer AUSSI les volumes (⚠️ EFFACE LES DONNÉES)
|
||||
docker-compose -f docker-compose.local.yml down -v
|
||||
|
||||
# Nettoyer les images inutilisées
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
## 🐛 Debugging
|
||||
|
||||
### Le backend ne démarre pas
|
||||
|
||||
```bash
|
||||
# Voir les logs détaillés
|
||||
docker-compose -f docker-compose.local.yml logs backend
|
||||
|
||||
# Erreurs communes:
|
||||
# - "Cannot connect to database" → Attends que PostgreSQL soit prêt
|
||||
# - "Redis connection failed" → Vérifie le password Redis
|
||||
# - "Port already in use" → Change le port dans docker-compose.local.yml
|
||||
```
|
||||
|
||||
### Le frontend ne se connecte pas au backend
|
||||
|
||||
```bash
|
||||
# Vérifie les variables d'environnement
|
||||
docker-compose -f docker-compose.local.yml exec frontend env | grep NEXT_PUBLIC
|
||||
|
||||
# Devrait afficher:
|
||||
# NEXT_PUBLIC_API_URL=http://localhost:4000
|
||||
# NEXT_PUBLIC_WS_URL=ws://localhost:4000
|
||||
```
|
||||
|
||||
### PostgreSQL ne démarre pas
|
||||
|
||||
```bash
|
||||
# Voir les logs
|
||||
docker-compose -f docker-compose.local.yml logs postgres
|
||||
|
||||
# Si "database system is shut down", supprime le volume:
|
||||
docker-compose -f docker-compose.local.yml down -v
|
||||
docker-compose -f docker-compose.local.yml up -d postgres
|
||||
```
|
||||
|
||||
### MinIO ne démarre pas
|
||||
|
||||
```bash
|
||||
# Voir les logs
|
||||
docker-compose -f docker-compose.local.yml logs minio
|
||||
|
||||
# Redémarre MinIO
|
||||
docker-compose -f docker-compose.local.yml restart minio
|
||||
```
|
||||
|
||||
## 📝 Variables d'Environnement
|
||||
|
||||
### Backend
|
||||
|
||||
| Variable | Valeur Locale | Description |
|
||||
|----------|---------------|-------------|
|
||||
| `DATABASE_HOST` | `postgres` | Nom du service PostgreSQL |
|
||||
| `DATABASE_PORT` | `5432` | Port PostgreSQL |
|
||||
| `DATABASE_USER` | `xpeditis` | User PostgreSQL |
|
||||
| `DATABASE_PASSWORD` | `xpeditis_dev_password` | Password PostgreSQL |
|
||||
| `DATABASE_NAME` | `xpeditis_dev` | Nom de la DB |
|
||||
| `REDIS_HOST` | `redis` | Nom du service Redis |
|
||||
| `REDIS_PASSWORD` | `xpeditis_redis_password` | Password Redis |
|
||||
| `AWS_S3_ENDPOINT` | `http://minio:9000` | URL MinIO |
|
||||
| `AWS_ACCESS_KEY_ID` | `minioadmin` | User MinIO |
|
||||
| `AWS_SECRET_ACCESS_KEY` | `minioadmin` | Password MinIO |
|
||||
| `AWS_S3_BUCKET` | `xpeditis-csv-rates` | Bucket CSV |
|
||||
|
||||
### Frontend
|
||||
|
||||
| Variable | Valeur Locale | Description |
|
||||
|----------|---------------|-------------|
|
||||
| `NEXT_PUBLIC_API_URL` | `http://localhost:4000` | URL du backend |
|
||||
| `NEXT_PUBLIC_WS_URL` | `ws://localhost:4000` | WebSocket URL |
|
||||
|
||||
## 🎯 Workflow de Test Complet
|
||||
|
||||
1. **Login au registry**:
|
||||
```bash
|
||||
docker login rg.fr-par.scw.cloud/weworkstudio
|
||||
```
|
||||
|
||||
2. **Lancer la stack**:
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml up -d
|
||||
```
|
||||
|
||||
3. **Attendre que tout démarre** (~30 secondes):
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml ps
|
||||
```
|
||||
|
||||
4. **Créer le bucket MinIO** via http://localhost:9001
|
||||
|
||||
5. **Exécuter les migrations**:
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml exec backend npm run migration:run
|
||||
```
|
||||
|
||||
6. **Tester l'application**:
|
||||
- Frontend: http://localhost:3000
|
||||
- Backend API: http://localhost:4000/api/docs
|
||||
- MinIO: http://localhost:9001
|
||||
|
||||
7. **Arrêter quand fini**:
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml down
|
||||
```
|
||||
|
||||
## 🚀 Comparer avec la Production
|
||||
|
||||
Cette stack locale utilise **EXACTEMENT les mêmes images Docker** que la production:
|
||||
- ✅ `rg.fr-par.scw.cloud/weworkstudio/xpeditis-backend:preprod`
|
||||
- ✅ `rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend:preprod`
|
||||
|
||||
**Différences avec la production**:
|
||||
- ❌ Pas de Traefik (accès direct aux ports)
|
||||
- ❌ Pas de SSL/HTTPS
|
||||
- ❌ Credentials simplifiés (minioadmin au lieu de secrets forts)
|
||||
- ✅ Mais le code applicatif est IDENTIQUE
|
||||
|
||||
## 📊 Monitoring
|
||||
|
||||
### Ressources utilisées
|
||||
|
||||
```bash
|
||||
# Voir la consommation CPU/RAM
|
||||
docker stats
|
||||
|
||||
# Devrait afficher quelque chose comme:
|
||||
# CONTAINER CPU % MEM USAGE / LIMIT MEM %
|
||||
# xpeditis-backend 2.5% 180MiB / 7.77GiB 2.26%
|
||||
# xpeditis-frontend 1.2% 85MiB / 7.77GiB 1.07%
|
||||
# xpeditis-postgres 0.5% 25MiB / 7.77GiB 0.31%
|
||||
```
|
||||
|
||||
### Vérifier les health checks
|
||||
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml ps
|
||||
|
||||
# La colonne STATUS devrait afficher "Up (healthy)"
|
||||
```
|
||||
|
||||
## 🔧 Problèmes Connus
|
||||
|
||||
### Port déjà utilisé
|
||||
|
||||
Si tu as déjà des services qui tournent en local:
|
||||
|
||||
```bash
|
||||
# Changer les ports dans docker-compose.local.yml:
|
||||
# Backend: "4001:4000" au lieu de "4000:4000"
|
||||
# Frontend: "3001:3000" au lieu de "3000:3000"
|
||||
# PostgreSQL: "5433:5432" au lieu de "5432:5432"
|
||||
```
|
||||
|
||||
### Erreur "pull access denied"
|
||||
|
||||
Tu n'es pas login au registry Scaleway:
|
||||
|
||||
```bash
|
||||
docker login rg.fr-par.scw.cloud/weworkstudio
|
||||
```
|
||||
|
||||
### Images trop anciennes
|
||||
|
||||
Force le pull des dernières images:
|
||||
|
||||
```bash
|
||||
docker-compose -f docker-compose.local.yml pull
|
||||
docker-compose -f docker-compose.local.yml up -d --force-recreate
|
||||
```
|
||||
|
||||
## 📞 Besoin d'Aide?
|
||||
|
||||
- **Logs backend**: `docker-compose -f docker-compose.local.yml logs backend`
|
||||
- **Logs frontend**: `docker-compose -f docker-compose.local.yml logs frontend`
|
||||
- **Status**: `docker-compose -f docker-compose.local.yml ps`
|
||||
- **Ressources**: `docker stats`
|
||||
150
docker-compose.local.yml
Normal file
150
docker-compose.local.yml
Normal file
@ -0,0 +1,150 @@
|
||||
version: '3.8'
|
||||
|
||||
# ============================================
|
||||
# Docker Compose pour développement local Mac
|
||||
# ============================================
|
||||
# Usage:
|
||||
# docker-compose -f docker-compose.local.yml up -d
|
||||
# docker-compose -f docker-compose.local.yml logs -f backend
|
||||
# docker-compose -f docker-compose.local.yml down
|
||||
|
||||
services:
|
||||
# PostgreSQL Database
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: xpeditis-postgres-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_DB: xpeditis_dev
|
||||
POSTGRES_USER: xpeditis
|
||||
POSTGRES_PASSWORD: xpeditis_dev_password
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U xpeditis"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Redis Cache
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: xpeditis-redis-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6379:6379"
|
||||
command: redis-server --requirepass xpeditis_redis_password --appendonly yes
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# MinIO S3 Storage
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: xpeditis-minio-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9000:9000" # API
|
||||
- "9001:9001" # Console
|
||||
command: server /data --console-address ":9001"
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
retries: 3
|
||||
|
||||
# Backend API (NestJS) - Image depuis Scaleway Registry
|
||||
backend:
|
||||
image: rg.fr-par.scw.cloud/weworkstudio/xpeditis-backend:preprod
|
||||
container_name: xpeditis-backend-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "4000:4000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_started
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
PORT: 4000
|
||||
|
||||
# Database
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: 5432
|
||||
DATABASE_USER: xpeditis
|
||||
DATABASE_PASSWORD: xpeditis_dev_password
|
||||
DATABASE_NAME: xpeditis_dev
|
||||
|
||||
# Redis
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: 6379
|
||||
REDIS_PASSWORD: xpeditis_redis_password
|
||||
|
||||
# JWT
|
||||
JWT_SECRET: dev-secret-key-change-in-production
|
||||
JWT_ACCESS_EXPIRATION: 15m
|
||||
JWT_REFRESH_EXPIRATION: 7d
|
||||
|
||||
# S3/MinIO
|
||||
AWS_S3_ENDPOINT: http://minio:9000
|
||||
AWS_REGION: us-east-1
|
||||
AWS_ACCESS_KEY_ID: minioadmin
|
||||
AWS_SECRET_ACCESS_KEY: minioadmin
|
||||
AWS_S3_BUCKET: xpeditis-csv-rates
|
||||
|
||||
# CORS
|
||||
CORS_ORIGIN: http://localhost:3000,http://localhost:3001
|
||||
|
||||
# App URLs
|
||||
FRONTEND_URL: http://localhost:3000
|
||||
API_URL: http://localhost:4000
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD", "node", "-e", "require('http').get('http://localhost:4000/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
# Frontend (Next.js) - Image depuis Scaleway Registry
|
||||
frontend:
|
||||
image: rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend:preprod
|
||||
container_name: xpeditis-frontend-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- backend
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
NEXT_PUBLIC_API_URL: http://localhost:4000
|
||||
NEXT_PUBLIC_WS_URL: ws://localhost:4000
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
redis_data:
|
||||
driver: local
|
||||
minio_data:
|
||||
driver: local
|
||||
Loading…
Reference in New Issue
Block a user