All checks were successful
CI/CD Pipeline / Backend - Build, Test & Push (push) Successful in 5m45s
CI/CD Pipeline / Frontend - Build, Test & Push (push) Successful in 28m26s
CI/CD Pipeline / Integration Tests (push) Has been skipped
CI/CD Pipeline / Deployment Summary (push) Successful in 1s
CI/CD Pipeline / Deploy to Portainer (push) Successful in 14s
CI/CD Pipeline / Discord Notification (Failure) (push) Has been skipped
CI/CD Pipeline / Discord Notification (Success) (push) Successful in 1s
220 lines
6.1 KiB
Markdown
220 lines
6.1 KiB
Markdown
# 🚨 Fix 404 - Traefik Ne Route Pas vers les Containers
|
|
|
|
## ✅ Diagnostic
|
|
|
|
**Symptômes** :
|
|
- ✅ Backend démarre correctement : `Nest application successfully started`
|
|
- ✅ Frontend démarre correctement : `✓ Ready in XXms`
|
|
- ❌ 404 sur https://app.preprod.xpeditis.com
|
|
- ❌ 404 sur https://api.preprod.xpeditis.com
|
|
|
|
**Conclusion** : Les containers fonctionnent, mais **Traefik ne les trouve pas**.
|
|
|
|
---
|
|
|
|
## 🔍 Causes Possibles
|
|
|
|
### Cause 1 : Containers Pas dans le Réseau Traefik
|
|
|
|
**Vérification** :
|
|
```bash
|
|
# Vérifier que les containers sont dans traefik_network
|
|
docker network inspect traefik_network --format '{{range .Containers}}{{.Name}} {{end}}'
|
|
|
|
# Devrait afficher :
|
|
# xpeditis_xpeditis-backend.X.XXX
|
|
# xpeditis_xpeditis-frontend.X.XXX
|
|
```
|
|
|
|
**Si absents**, le problème vient du fait que Docker Swarm ne connecte pas automatiquement les services aux réseaux externes.
|
|
|
|
---
|
|
|
|
### Cause 2 : Labels Traefik Mal Interprétés en Swarm Mode
|
|
|
|
En Docker Swarm, les labels doivent être sous `deploy.labels` et non directement sous `labels`.
|
|
|
|
**Configuration Actuelle (INCORRECTE pour Swarm)** :
|
|
```yaml
|
|
xpeditis-backend:
|
|
labels: # ← Ne fonctionne PAS en Swarm mode
|
|
- "traefik.enable=true"
|
|
```
|
|
|
|
**Configuration Correcte pour Swarm** :
|
|
```yaml
|
|
xpeditis-backend:
|
|
deploy:
|
|
labels: # ← Doit être sous deploy.labels
|
|
- "traefik.enable=true"
|
|
```
|
|
|
|
---
|
|
|
|
### Cause 3 : Traefik Pas Configuré pour Swarm Mode
|
|
|
|
Traefik doit avoir `swarmMode: true` dans sa configuration.
|
|
|
|
**Vérification** :
|
|
```bash
|
|
docker service inspect traefik --pretty | grep -A 5 "Args"
|
|
|
|
# Devrait contenir :
|
|
# --providers.docker.swarmMode=true
|
|
```
|
|
|
|
---
|
|
|
|
## ✅ Solution : Corriger le Stack pour Swarm Mode
|
|
|
|
### Modification 1 : Déplacer Labels sous `deploy.labels`
|
|
|
|
**Backend** :
|
|
```yaml
|
|
xpeditis-backend:
|
|
image: rg.fr-par.scw.cloud/weworkstudio/xpeditis-backend:preprod
|
|
restart: unless-stopped
|
|
# ... environment ...
|
|
networks:
|
|
- xpeditis_internal
|
|
- traefik_network
|
|
deploy:
|
|
labels: # ← DÉPLACER ICI
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.xpeditis-api.rule=Host(`api.preprod.xpeditis.com`)"
|
|
- "traefik.http.routers.xpeditis-api.entrypoints=websecure"
|
|
- "traefik.http.routers.xpeditis-api.tls=true"
|
|
- "traefik.http.routers.xpeditis-api.tls.certresolver=letsencrypt"
|
|
- "traefik.http.services.xpeditis-api.loadbalancer.server.port=4000"
|
|
- "traefik.docker.network=traefik_network"
|
|
```
|
|
|
|
**Frontend** :
|
|
```yaml
|
|
xpeditis-frontend:
|
|
image: rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend:preprod
|
|
restart: unless-stopped
|
|
# ... environment ...
|
|
networks:
|
|
- traefik_network
|
|
deploy:
|
|
labels: # ← DÉPLACER ICI
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.xpeditis-app.rule=Host(`app.preprod.xpeditis.com`) || Host(`www.preprod.xpeditis.com`)"
|
|
- "traefik.http.routers.xpeditis-app.entrypoints=websecure"
|
|
- "traefik.http.routers.xpeditis-app.tls=true"
|
|
- "traefik.http.routers.xpeditis-app.tls.certresolver=letsencrypt"
|
|
- "traefik.http.services.xpeditis-app.loadbalancer.server.port=3000"
|
|
- "traefik.docker.network=traefik_network"
|
|
```
|
|
|
|
**MinIO** :
|
|
```yaml
|
|
xpeditis-minio:
|
|
image: minio/minio:latest
|
|
restart: unless-stopped
|
|
# ... environment ...
|
|
networks:
|
|
- xpeditis_internal
|
|
- traefik_network
|
|
deploy:
|
|
labels: # ← DÉPLACER ICI
|
|
- "traefik.enable=true"
|
|
- "traefik.http.routers.xpeditis-minio-api.rule=Host(`s3.preprod.xpeditis.com`)"
|
|
- "traefik.http.routers.xpeditis-minio-api.entrypoints=websecure"
|
|
- "traefik.http.routers.xpeditis-minio-api.tls=true"
|
|
- "traefik.http.routers.xpeditis-minio-api.tls.certresolver=letsencrypt"
|
|
- "traefik.http.services.xpeditis-minio-api.loadbalancer.server.port=9000"
|
|
|
|
- "traefik.http.routers.xpeditis-minio-console.rule=Host(`minio.preprod.xpeditis.com`)"
|
|
- "traefik.http.routers.xpeditis-minio-console.entrypoints=websecure"
|
|
- "traefik.http.routers.xpeditis-minio-console.tls=true"
|
|
- "traefik.http.routers.xpeditis-minio-console.tls.certresolver=letsencrypt"
|
|
- "traefik.http.services.xpeditis-minio-console.loadbalancer.server.port=9001"
|
|
|
|
- "traefik.docker.network=traefik_network"
|
|
```
|
|
|
|
---
|
|
|
|
## 📋 Stack Complet Corrigé pour Swarm
|
|
|
|
Je vais créer le fichier corrigé complet dans le prochain message.
|
|
|
|
---
|
|
|
|
## 🔧 Vérification Post-Update
|
|
|
|
Après avoir updaté le stack :
|
|
|
|
### 1. Vérifier que Traefik Voit les Services
|
|
|
|
```bash
|
|
# Voir les routers Traefik
|
|
docker exec $(docker ps -q -f name=traefik) traefik healthcheck
|
|
|
|
# Ou via logs Traefik
|
|
docker service logs traefik --tail 50 | grep xpeditis
|
|
```
|
|
|
|
**Logs attendus** :
|
|
```
|
|
Creating router xpeditis-api
|
|
Creating service xpeditis-api
|
|
```
|
|
|
|
### 2. Vérifier les Containers Connectés au Network
|
|
|
|
```bash
|
|
docker network inspect traefik_network | grep -A 5 xpeditis
|
|
```
|
|
|
|
### 3. Tester les Endpoints
|
|
|
|
```bash
|
|
curl -I https://api.preprod.xpeditis.com/api/v1/health
|
|
# Devrait retourner : HTTP/2 200
|
|
|
|
curl -I https://app.preprod.xpeditis.com
|
|
# Devrait retourner : HTTP/2 200
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 Résumé du Fix
|
|
|
|
| Problème | Cause | Solution |
|
|
|----------|-------|----------|
|
|
| 404 sur API/Frontend | Labels Traefik sous `labels` au lieu de `deploy.labels` | Déplacer tous les labels sous `deploy.labels` |
|
|
| Traefik ne voit pas les services | Swarm mode nécessite configuration spéciale | Utiliser `deploy.labels` |
|
|
|
|
---
|
|
|
|
## ⚠️ Note Importante : Docker Compose vs Swarm
|
|
|
|
**Docker Compose (standalone)** :
|
|
```yaml
|
|
services:
|
|
app:
|
|
labels: # ← Fonctionne ici
|
|
- "traefik.enable=true"
|
|
```
|
|
|
|
**Docker Swarm** :
|
|
```yaml
|
|
services:
|
|
app:
|
|
deploy:
|
|
labels: # ← REQUIS en Swarm mode
|
|
- "traefik.enable=true"
|
|
```
|
|
|
|
Votre stack utilise `deploy.placement.constraints`, donc vous êtes **en mode Swarm**, d'où le problème.
|
|
|
|
---
|
|
|
|
**Date** : 2025-11-19
|
|
**Problème** : Labels Traefik mal placés (hors de `deploy`)
|
|
**Solution** : Déplacer tous les labels sous `deploy.labels`
|
|
**ETA Fix** : 5 minutes
|