
- Infrastructure complète de traitement de documents notariaux - API FastAPI d'ingestion et d'orchestration - Pipelines Celery pour le traitement asynchrone - Support des formats PDF, JPEG, PNG, TIFF, HEIC - OCR avec Tesseract et correction lexicale - Classification automatique des documents avec Ollama - Extraction de données structurées - Indexation dans AnythingLLM et OpenSearch - Système de vérifications et contrôles métier - Base de données PostgreSQL pour le métier - Stockage objet avec MinIO - Base de données graphe Neo4j - Recherche plein-texte avec OpenSearch - Supervision avec Prometheus et Grafana - Scripts d'installation pour Debian - Documentation complète - Tests unitaires et de performance - Service systemd pour le déploiement - Scripts de déploiement automatisés
259 lines
5.7 KiB
Bash
Executable File
259 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Script de déploiement du pipeline notarial
|
|
# Usage: ./deploy.sh [environment] [action]
|
|
# Environment: dev, staging, prod
|
|
# Action: install, update, restart, stop
|
|
|
|
ENVIRONMENT=${1:-dev}
|
|
ACTION=${2:-install}
|
|
PROJECT_DIR="/opt/notariat-pipeline"
|
|
|
|
echo "=== Déploiement Pipeline Notarial ==="
|
|
echo "Environnement: $ENVIRONMENT"
|
|
echo "Action: $ACTION"
|
|
echo "Répertoire: $PROJECT_DIR"
|
|
|
|
# Fonction de logging
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
|
}
|
|
|
|
# Fonction d'erreur
|
|
error() {
|
|
echo "ERREUR: $1" >&2
|
|
exit 1
|
|
}
|
|
|
|
# Vérification des prérequis
|
|
check_prerequisites() {
|
|
log "Vérification des prérequis..."
|
|
|
|
# Vérification de Docker
|
|
if ! command -v docker &> /dev/null; then
|
|
error "Docker n'est pas installé"
|
|
fi
|
|
|
|
# Vérification de Docker Compose
|
|
if ! docker compose version &> /dev/null; then
|
|
error "Docker Compose n'est pas installé"
|
|
fi
|
|
|
|
# Vérification des permissions
|
|
if ! docker ps &> /dev/null; then
|
|
error "Permissions Docker insuffisantes"
|
|
fi
|
|
|
|
log "Prérequis validés"
|
|
}
|
|
|
|
# Installation
|
|
install() {
|
|
log "Installation du pipeline notarial..."
|
|
|
|
# Création du répertoire
|
|
sudo mkdir -p $PROJECT_DIR
|
|
sudo chown $USER:$USER $PROJECT_DIR
|
|
|
|
# Copie des fichiers
|
|
cp -r . $PROJECT_DIR/
|
|
cd $PROJECT_DIR
|
|
|
|
# Configuration de l'environnement
|
|
if [ ! -f "infra/.env" ]; then
|
|
cp infra/.env.example infra/.env
|
|
log "Fichier .env créé. Veuillez le configurer."
|
|
fi
|
|
|
|
# Installation des dépendances système
|
|
if command -v apt-get &> /dev/null; then
|
|
sudo apt-get update
|
|
sudo apt-get install -y curl wget
|
|
fi
|
|
|
|
# Installation de MinIO Client
|
|
if ! command -v mc &> /dev/null; then
|
|
curl https://dl.min.io/client/mc/release/linux-amd64/mc \
|
|
--create-dirs -o /tmp/mc
|
|
chmod +x /tmp/mc
|
|
sudo mv /tmp/mc /usr/local/bin/
|
|
fi
|
|
|
|
# Bootstrap de l'infrastructure
|
|
make bootstrap
|
|
|
|
# Installation du service systemd
|
|
if [ "$ENVIRONMENT" = "prod" ]; then
|
|
sudo cp ops/systemd/notariat-pipeline.service /etc/systemd/system/
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable notariat-pipeline
|
|
log "Service systemd installé et activé"
|
|
fi
|
|
|
|
log "Installation terminée"
|
|
}
|
|
|
|
# Mise à jour
|
|
update() {
|
|
log "Mise à jour du pipeline notarial..."
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
# Sauvegarde de la configuration
|
|
if [ -f "infra/.env" ]; then
|
|
cp infra/.env infra/.env.backup
|
|
fi
|
|
|
|
# Mise à jour du code
|
|
git pull origin main || log "Avertissement: Impossible de mettre à jour depuis Git"
|
|
|
|
# Restauration de la configuration
|
|
if [ -f "infra/.env.backup" ]; then
|
|
cp infra/.env.backup infra/.env
|
|
rm infra/.env.backup
|
|
fi
|
|
|
|
# Reconstruction des images
|
|
make build
|
|
|
|
# Redémarrage des services
|
|
make restart
|
|
|
|
log "Mise à jour terminée"
|
|
}
|
|
|
|
# Redémarrage
|
|
restart() {
|
|
log "Redémarrage du pipeline notarial..."
|
|
|
|
cd $PROJECT_DIR
|
|
make restart
|
|
|
|
log "Redémarrage terminé"
|
|
}
|
|
|
|
# Arrêt
|
|
stop() {
|
|
log "Arrêt du pipeline notarial..."
|
|
|
|
cd $PROJECT_DIR
|
|
make down
|
|
|
|
log "Arrêt terminé"
|
|
}
|
|
|
|
# Vérification de santé
|
|
health_check() {
|
|
log "Vérification de santé..."
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
# Attente du démarrage
|
|
sleep 10
|
|
|
|
# Test de l'API
|
|
if curl -s http://localhost:8000/api/health > /dev/null; then
|
|
log "API accessible"
|
|
else
|
|
error "API non accessible"
|
|
fi
|
|
|
|
# Test d'AnythingLLM
|
|
if curl -s http://localhost:3001/api/health > /dev/null; then
|
|
log "AnythingLLM accessible"
|
|
else
|
|
log "Avertissement: AnythingLLM non accessible"
|
|
fi
|
|
|
|
# Test de Grafana
|
|
if curl -s http://localhost:3000/api/health > /dev/null; then
|
|
log "Grafana accessible"
|
|
else
|
|
log "Avertissement: Grafana non accessible"
|
|
fi
|
|
|
|
log "Vérification de santé terminée"
|
|
}
|
|
|
|
# Sauvegarde
|
|
backup() {
|
|
log "Sauvegarde des données..."
|
|
|
|
BACKUP_DIR="/opt/backups/notariat-pipeline/$(date +%Y%m%d_%H%M%S)"
|
|
mkdir -p $BACKUP_DIR
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
# Sauvegarde de la base de données
|
|
docker exec postgres pg_dump -U notariat notariat > $BACKUP_DIR/database.sql
|
|
|
|
# Sauvegarde des volumes
|
|
docker run --rm -v notariat_pgdata:/data -v $BACKUP_DIR:/backup alpine tar czf /backup/pgdata.tar.gz -C /data .
|
|
docker run --rm -v notariat_minio:/data -v $BACKUP_DIR:/backup alpine tar czf /backup/minio.tar.gz -C /data .
|
|
|
|
# Sauvegarde de la configuration
|
|
cp infra/.env $BACKUP_DIR/
|
|
cp -r ops/seed $BACKUP_DIR/
|
|
|
|
log "Sauvegarde terminée: $BACKUP_DIR"
|
|
}
|
|
|
|
# Nettoyage
|
|
cleanup() {
|
|
log "Nettoyage des ressources..."
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
# Arrêt des services
|
|
make down
|
|
|
|
# Suppression des volumes (ATTENTION: perte de données)
|
|
if [ "$ENVIRONMENT" = "dev" ]; then
|
|
docker volume prune -f
|
|
docker system prune -f
|
|
log "Nettoyage terminé (données supprimées)"
|
|
else
|
|
log "Nettoyage ignoré en environnement $ENVIRONMENT"
|
|
fi
|
|
}
|
|
|
|
# Fonction principale
|
|
main() {
|
|
case $ACTION in
|
|
install)
|
|
check_prerequisites
|
|
install
|
|
health_check
|
|
;;
|
|
update)
|
|
check_prerequisites
|
|
update
|
|
health_check
|
|
;;
|
|
restart)
|
|
restart
|
|
health_check
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
backup)
|
|
backup
|
|
;;
|
|
cleanup)
|
|
cleanup
|
|
;;
|
|
health)
|
|
health_check
|
|
;;
|
|
*)
|
|
echo "Usage: $0 [dev|staging|prod] [install|update|restart|stop|backup|cleanup|health]"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Exécution
|
|
main "$@"
|