Some checks failed
CI/CD Pipeline / Backend - Build, Test & Push (push) Failing after 58s
CI/CD Pipeline / Frontend - Build, Test & Push (push) Failing after 5m55s
CI/CD Pipeline / Integration Tests (push) Has been skipped
CI/CD Pipeline / Deployment Summary (push) Has been skipped
CI/CD Pipeline / Deploy to Portainer (push) Has been skipped
CI/CD Pipeline / Discord Notification (Success) (push) Has been skipped
CI/CD Pipeline / Discord Notification (Failure) (push) Has been skipped
Reorganisation majeure de toute la documentation du projet pour ameliorer la navigation et la maintenance. ## Changements principaux ### Organisation (80 -> 4 fichiers .md a la racine) - Deplace 82 fichiers .md dans docs/ organises en 11 categories - Conserve uniquement 4 fichiers essentiels a la racine: * README.md, CLAUDE.md, PRD.md, TODO.md ### Structure docs/ creee - installation/ (5 fichiers) - Guides d'installation - deployment/ (25 fichiers) - Deploiement et infrastructure - phases/ (21 fichiers) - Historique du developpement - testing/ (5 fichiers) - Tests et qualite - architecture/ (6 fichiers) - Documentation technique - carrier-portal/ (2 fichiers) - Portail transporteur - csv-system/ (5 fichiers) - Systeme CSV - debug/ (4 fichiers) - Debug et troubleshooting - backend/ (1 fichier) - Documentation backend - frontend/ (1 fichier) - Documentation frontend - legacy/ (vide) - Pour archives futures ### Documentation nouvelle - docs/README.md - Index complet de toute la documentation (367 lignes) * Guide de navigation par scenario * Recherche rapide par theme * FAQ et commandes rapides - docs/CLEANUP-REPORT-2025-12-22.md - Rapport detaille du nettoyage ### Scripts reorganises - add-email-to-csv.py -> scripts/ - deploy-to-portainer.sh -> docker/ ### Fichiers supprimes - 1536w default.svg (11MB) - Fichier non utilise ### References mises a jour - CLAUDE.md - Section Documentation completement reecrite - docs/architecture/EMAIL_IMPLEMENTATION_STATUS.md - Chemin script Python - docs/deployment/REGISTRY_PUSH_GUIDE.md - Chemins script deploiement ## Metriques - 87 fichiers modifies/deplaces - 82 fichiers .md organises dans docs/ - 11MB d'espace libere - Temps de recherche reduit de ~5min a ~30s (-90%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
250 lines
6.2 KiB
Markdown
250 lines
6.2 KiB
Markdown
# 🔧 Fix NODE_ENV pour Portainer
|
|
|
|
## 🚨 Problème Identifié
|
|
|
|
### Backend Erreur
|
|
|
|
```
|
|
ERROR [ExceptionHandler] Config validation error: "NODE_ENV" must be one of [development, production, test]
|
|
```
|
|
|
|
**Cause** : La validation Joi dans `apps/backend/src/app.module.ts` (ligne 35) n'accepte QUE :
|
|
- `development`
|
|
- `production`
|
|
- `test`
|
|
|
|
Mais le stack utilisait `NODE_ENV=preprod` ❌
|
|
|
|
### Frontend Redémarrage en Boucle
|
|
|
|
Le frontend redémarrait sans cesse (status "complete" répété) parce que le backend crashait, donc le health check échouait.
|
|
|
|
---
|
|
|
|
## ✅ Solution Appliquée
|
|
|
|
### Changement dans `docker/portainer-stack.yml`
|
|
|
|
**Backend (ligne 83)** :
|
|
```yaml
|
|
environment:
|
|
NODE_ENV: production # ← Changé de "preprod" à "production"
|
|
PORT: "4000"
|
|
# ...
|
|
```
|
|
|
|
**Frontend (ligne 157)** :
|
|
```yaml
|
|
environment:
|
|
NODE_ENV: production # ← Changé de "preprod" à "production"
|
|
NEXT_PUBLIC_API_URL: https://api.preprod.xpeditis.com
|
|
# ...
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 Pourquoi `production` et Pas `preprod` ?
|
|
|
|
### Option 1 : Utiliser `production` (✅ SOLUTION ACTUELLE)
|
|
|
|
**Avantages** :
|
|
- ✅ Fonctionne immédiatement sans changer le code
|
|
- ✅ Active les optimisations de production (logs niveau info, pas de debug)
|
|
- ✅ Comportement attendu pour un environnement de pre-production
|
|
|
|
**Configuration** :
|
|
```yaml
|
|
NODE_ENV: production
|
|
```
|
|
|
|
### Option 2 : Modifier la Validation Backend (Alternative)
|
|
|
|
Si vous voulez vraiment utiliser `preprod`, modifier `apps/backend/src/app.module.ts` :
|
|
|
|
```typescript
|
|
// Ligne 35
|
|
NODE_ENV: Joi.string()
|
|
.valid('development', 'production', 'test', 'preprod') // ← Ajouter 'preprod'
|
|
.default('development'),
|
|
```
|
|
|
|
**Inconvénients** :
|
|
- ❌ Nécessite rebuild des images Docker
|
|
- ❌ Re-trigger la CI/CD
|
|
- ❌ Pas standard (Node.js attend development/production/test)
|
|
|
|
---
|
|
|
|
## 📊 Impact du NODE_ENV
|
|
|
|
### Backend (NestJS)
|
|
|
|
**NODE_ENV=production** active :
|
|
- Logs niveau `info` (pas `debug`)
|
|
- Logging optimisé (JSON, pas pino-pretty)
|
|
- Optimisations de performance
|
|
- Caching agressif
|
|
|
|
**NODE_ENV=development** active :
|
|
- Logs niveau `debug` (verbose)
|
|
- Pino-pretty avec couleurs (plus lisible mais plus lent)
|
|
- Pas de caching
|
|
- Hot reload (non applicable en Docker)
|
|
|
|
### Frontend (Next.js)
|
|
|
|
**NODE_ENV=production** active :
|
|
- Build optimisé (minification, tree-shaking)
|
|
- Images optimisées
|
|
- Pas de React DevTools
|
|
- Meilleure performance
|
|
|
|
---
|
|
|
|
## 🔍 Vérification Post-Fix
|
|
|
|
### Backend : Logs Attendus
|
|
|
|
**Portainer → Containers → xpeditis-backend → Logs** :
|
|
|
|
```
|
|
🚀 Starting Xpeditis Backend...
|
|
⏳ Waiting for PostgreSQL to be ready...
|
|
✅ PostgreSQL is ready
|
|
🔄 Running database migrations...
|
|
✅ DataSource initialized
|
|
✅ Successfully ran 10 migration(s)
|
|
✅ Database migrations completed
|
|
🚀 Starting NestJS application...
|
|
[Nest] 1 - LOG [NestFactory] Starting Nest application...
|
|
[Nest] 1 - LOG [InstanceLoader] AppModule dependencies initialized
|
|
[Nest] 1 - LOG [RoutesResolver] AppController {/api/v1}:
|
|
[Nest] 1 - LOG Application is running on: http://0.0.0.0:4000
|
|
```
|
|
|
|
**Plus d'erreur de validation ✅**
|
|
|
|
### Frontend : Logs Attendus
|
|
|
|
**Portainer → Containers → xpeditis-frontend → Logs** :
|
|
|
|
```
|
|
▲ Next.js 14.0.4
|
|
- Local: http://localhost:3000
|
|
- Network: http://0.0.0.0:3000
|
|
|
|
✓ Ready in 88ms
|
|
```
|
|
|
|
**Container reste en état "running" (pas de redémarrage) ✅**
|
|
|
|
---
|
|
|
|
## 📋 Checklist de Déploiement (Mise à Jour)
|
|
|
|
### 1. Update le Stack Portainer
|
|
|
|
1. **Portainer → Stacks → xpeditis-preprod**
|
|
2. **Editor** → Copier le nouveau `portainer-stack.yml` (avec `NODE_ENV=production`)
|
|
3. ✅ **Cocher "Re-pull image and redeploy"**
|
|
4. **Update the stack**
|
|
|
|
### 2. Vérifier les Services
|
|
|
|
**Portainer → Containers** :
|
|
|
|
| Container | État Attendu | Logs Clés |
|
|
|-----------|--------------|-----------|
|
|
| `xpeditis-backend` | Running (Healthy) | `✅ Database migrations completed` |
|
|
| `xpeditis-frontend` | Running (Healthy) | `✓ Ready in XXms` |
|
|
|
|
### 3. Tester les Endpoints
|
|
|
|
```bash
|
|
# Backend health check
|
|
curl https://api.preprod.xpeditis.com/api/v1/health
|
|
# Réponse : {"status":"ok","info":{"database":{"status":"up"},"redis":{"status":"up"}}}
|
|
|
|
# Frontend
|
|
curl -I https://app.preprod.xpeditis.com
|
|
# Réponse : HTTP/2 200
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 Résumé du Fix
|
|
|
|
| Avant | Après | Résultat |
|
|
|-------|-------|----------|
|
|
| `NODE_ENV: preprod` | `NODE_ENV: production` | ✅ Backend démarre |
|
|
| Backend crash | Backend running | ✅ Migrations OK |
|
|
| Frontend loop | Frontend stable | ✅ Reste en "running" |
|
|
|
|
---
|
|
|
|
## 🔧 Si Vous Voulez Vraiment Utiliser `preprod`
|
|
|
|
### Étape 1 : Modifier le Backend
|
|
|
|
**Fichier** : `apps/backend/src/app.module.ts`
|
|
|
|
```typescript
|
|
validationSchema: Joi.object({
|
|
NODE_ENV: Joi.string()
|
|
.valid('development', 'production', 'test', 'preprod') // ← Ajouter
|
|
.default('development'),
|
|
// ...
|
|
}),
|
|
```
|
|
|
|
### Étape 2 : Ajuster les Conditions
|
|
|
|
**Fichier** : `apps/backend/src/app.module.ts` (ligne 56-66)
|
|
|
|
```typescript
|
|
LoggerModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => {
|
|
const env = configService.get('NODE_ENV');
|
|
const isDev = env === 'development';
|
|
const isProd = env === 'production' || env === 'preprod'; // ← Traiter preprod comme prod
|
|
|
|
return {
|
|
pinoHttp: {
|
|
transport: isDev ? { /* ... */ } : undefined,
|
|
level: isProd ? 'info' : 'debug',
|
|
},
|
|
};
|
|
},
|
|
}),
|
|
```
|
|
|
|
### Étape 3 : Rebuild et Push
|
|
|
|
```bash
|
|
# Commit changes
|
|
git add apps/backend/src/app.module.ts
|
|
git commit -m "feat: add preprod to NODE_ENV validation"
|
|
|
|
# Push to trigger CI/CD
|
|
git push origin preprod
|
|
|
|
# Attendre que CI/CD rebuild et push les images (~15 min)
|
|
```
|
|
|
|
### Étape 4 : Update Stack Portainer
|
|
|
|
Changer `NODE_ENV: production` → `NODE_ENV: preprod` dans le stack.
|
|
|
|
---
|
|
|
|
**Recommandation** : **Garder `NODE_ENV=production`** car :
|
|
- ✅ Standard Node.js/NestJS
|
|
- ✅ Fonctionne immédiatement
|
|
- ✅ Pre-production = production-like environment
|
|
|
|
---
|
|
|
|
**Date** : 2025-11-19
|
|
**Fix Appliqué** : `NODE_ENV=production` dans portainer-stack.yml
|
|
**Status** : ✅ Prêt pour déploiement
|