Déploiement Stack Python - Production
Date : 2026-01-25
Statut : ✅ Configuration Production Complétée
Dernière mise à jour : 2026-01-25
🚀 Changements Récents (2026-01-25)
- ✅ Renommage :
python-ml-service→python-services - ✅ Word Generation : python-docx ajouté
- ✅ Excel Generation : openpyxl ajouté
- ✅ Variables env :
USE_PYTHON_WORD,USE_PYTHON_EXCELajoutées
✅ Configuration Production
Docker Compose Production
Fichier : infra/docker-compose.prod.yml
Services :
- ✅ Service
python-servicesavec toutes les variables d'environnement - ✅ Service
qdrantavec health check et volumes persistants - ✅ Dépendances correctes (api/worker dépendent de python-services)
Configuration :
python-services:
image: ${CI_REGISTRY_IMAGE}/python-services:${DEPLOY_TAG:-latest}
environment:
DEBUG: "false"
EMBEDDING_MODEL: ${EMBEDDING_MODEL:-sentence-transformers/all-MiniLM-L6-v2}
QDRANT_HOST: qdrant
REDIS_HOST: redis
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:8000/health > /dev/null || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
qdrant:
image: qdrant/qdrant:latest
volumes:
- ${APP_DIR}/.data/qdrant:/qdrant/storage
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:6333/health > /dev/null || exit 1"]
CI/CD (GitLab)
Fichier : .gitlab-ci.yml
Configuration :
# --- PYTHON SERVICES (PDF, Word, Excel, ML, embeddings) ---
- docker build -f python-service/Dockerfile -t "$CI_REGISTRY_IMAGE/python-services:$CI_COMMIT_SHORT_SHA" python-service
- docker tag "$CI_REGISTRY_IMAGE/python-services:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE/python-services:latest"
- docker push "$CI_REGISTRY_IMAGE/python-services:$CI_COMMIT_SHORT_SHA"
- docker push "$CI_REGISTRY_IMAGE/python-services:latest"
📋 Variables d'Environnement
Fichier .env
# Python Services
PYTHON_SERVICE_URL=http://python-services:8000
PYTHON_ML_SERVICE_URL=${PYTHON_SERVICE_URL} # Legacy alias
# Embeddings
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
EMBEDDING_DEVICE=cpu
# Qdrant (Vector DB)
QDRANT_HOST=qdrant
QDRANT_PORT=6333
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
# Document Generation
USE_PYTHON_PDF=true
USE_PYTHON_WORD=true
USE_PYTHON_EXCEL=true
# Intent Detection
USE_PYTHON_INTENT=true
# OCR
USE_VISION_OCR=true
🚀 Déploiement
1. Build des Images
Le pipeline CI/CD build automatiquement :
api(NestJS backend)web(Frontend)python-services(Python Services)liquibase(Migrations)
2. Déploiement
Le script infra/deploy.sh déploie automatiquement tous les services.
Services déployés :
- ✅
db- PostgreSQL - ✅
redis- Redis - ✅
api- NestJS API - ✅
worker- BullMQ Workers - ✅
python-services- Python Services - ✅
qdrant- Vector Database - ✅
web- Frontend build - ✅
web_server- Nginx
3. Vérification
# Health check Python Services
curl http://localhost:8000/health
# Liste des fonctionnalités
curl http://localhost:8000/
# Word service
curl http://localhost:8000/api/word/health
# Excel service
curl http://localhost:8000/api/excel/health
# PDF templates
curl http://localhost:8000/api/pdf/templates
📊 Architecture Production
┌─────────────┐
│ Nginx │ (Port 8081)
└──────┬──────┘
│
├──→ Frontend (web)
│
└──→ API (api:8080)
│
├──→ Worker (worker)
│ │
│ ├──→ Python Services (python-services:8000)
│ │ ├──→ Qdrant (qdrant:6333)
│ │ └──→ Redis (redis:6379)
│ │
│ └──→ Redis (redis:6379)
│
└──→ PostgreSQL (db:5432)
✅ Checklist Déploiement
Avant Déploiement
- Dockerfile optimisé (multi-stage)
- docker-compose.prod.yml mis à jour
- CI/CD mis à jour (build python-services)
- Variables d'environnement documentées
- Health checks configurés
Variables d'Environnement
-
PYTHON_SERVICE_URLconfiguré -
USE_PYTHON_PDF=true -
USE_PYTHON_WORD=true -
USE_PYTHON_EXCEL=true -
USE_PYTHON_INTENT=true -
QDRANT_HOSTconfiguré -
REDIS_HOSTconfiguré
Post-Déploiement
- Vérifier health checks
- Vérifier logs Python Services
- Tester endpoints PDF, Word, Excel
- Vérifier métriques
🔧 Maintenance
Logs
# Logs Python Services
docker-compose -f infra/docker-compose.prod.yml logs python-services
# Logs Qdrant
docker-compose -f infra/docker-compose.prod.yml logs qdrant
# Logs Worker
docker-compose -f infra/docker-compose.prod.yml logs worker
Redémarrage
# Redémarrer Python Services
docker-compose -f infra/docker-compose.prod.yml restart python-services
# Redémarrer tous les services
docker-compose -f infra/docker-compose.prod.yml restart
📝 Notes
- Image Docker :
python-servicesest buildée et pushée dans le registry GitLab - Health Checks : Tous les services ont des health checks configurés
- Dépendances : Le worker attend que python-services et qdrant soient healthy
- Volumes : Qdrant utilise un volume persistant pour les données vectorielles
Statut : ✅ Production Ready