
- Création du répertoire scripts/ avec tous les scripts d'installation et de test - Scripts d'installation automatique (install.sh, quick-start.sh) - Scripts de maintenance complète (maintenance.sh) - Scripts de test (test-installation.sh, test-api.sh, test-services.sh, test-integration.sh) - Amélioration du Dockerfile avec healthchecks et sécurité - Mise à jour du docker-compose.yml avec healthchecks et dépendances - Makefile étendu avec nouvelles commandes - Documentation complète mise à jour - Fichier de configuration d'exemple (env.example) - app.py corrigé et fonctionnel
160 lines
4.6 KiB
Bash
Executable File
160 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script de test pour vérifier l'installation
|
|
# Usage: ./test-installation.sh
|
|
|
|
set -e
|
|
|
|
# Couleurs pour les messages
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Fonction pour afficher les messages
|
|
log_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
log_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Compteur de tests
|
|
TESTS_PASSED=0
|
|
TESTS_FAILED=0
|
|
|
|
# Fonction pour exécuter un test
|
|
run_test() {
|
|
local test_name="$1"
|
|
local test_command="$2"
|
|
|
|
log_info "Test: $test_name"
|
|
|
|
if eval "$test_command" > /dev/null 2>&1; then
|
|
log_success "✅ $test_name"
|
|
((TESTS_PASSED++))
|
|
else
|
|
log_error "❌ $test_name"
|
|
((TESTS_FAILED++))
|
|
fi
|
|
}
|
|
|
|
# Fonction pour vérifier les prérequis
|
|
test_prerequisites() {
|
|
log_info "=== Test des prérequis ==="
|
|
|
|
run_test "Docker installé" "command -v docker"
|
|
run_test "Docker Compose installé" "command -v docker-compose || docker compose version"
|
|
run_test "Python 3 installé" "command -v python3"
|
|
run_test "Make installé" "command -v make"
|
|
run_test "Curl installé" "command -v curl"
|
|
}
|
|
|
|
# Fonction pour vérifier les fichiers
|
|
test_files() {
|
|
log_info "=== Test des fichiers ==="
|
|
|
|
run_test "Fichier .env existe" "test -f .env"
|
|
run_test "Script install.sh existe" "test -f install.sh"
|
|
run_test "Script quick-start.sh existe" "test -f quick-start.sh"
|
|
run_test "Script maintenance.sh existe" "test -f maintenance.sh"
|
|
run_test "Makefile existe" "test -f Makefile"
|
|
run_test "Docker-compose.yml existe" "test -f infra/docker-compose.yml"
|
|
run_test "Dockerfile host-api existe" "test -f docker/host-api/Dockerfile"
|
|
run_test "Requirements.txt existe" "test -f services/host_api/requirements.txt"
|
|
run_test "App.py existe" "test -f services/host_api/app.py"
|
|
}
|
|
|
|
# Fonction pour vérifier les permissions
|
|
test_permissions() {
|
|
log_info "=== Test des permissions ==="
|
|
|
|
run_test "install.sh exécutable" "test -x install.sh"
|
|
run_test "quick-start.sh exécutable" "test -x quick-start.sh"
|
|
run_test "maintenance.sh exécutable" "test -x maintenance.sh"
|
|
}
|
|
|
|
# Fonction pour vérifier la configuration
|
|
test_configuration() {
|
|
log_info "=== Test de la configuration ==="
|
|
|
|
run_test "Variables d'environnement chargées" "source .env && echo \$POSTGRES_USER"
|
|
run_test "Makefile fonctionne" "make help > /dev/null"
|
|
run_test "Scripts d'aide fonctionnent" "./install.sh help > /dev/null"
|
|
}
|
|
|
|
# Fonction pour vérifier Docker
|
|
test_docker() {
|
|
log_info "=== Test de Docker ==="
|
|
|
|
run_test "Docker fonctionne" "docker ps"
|
|
run_test "Docker Compose fonctionne" "docker-compose version || docker compose version"
|
|
run_test "Images Docker peuvent être construites" "docker build -t test-build -f docker/host-api/Dockerfile . > /dev/null"
|
|
}
|
|
|
|
# Fonction pour vérifier les services (si démarrés)
|
|
test_services() {
|
|
log_info "=== Test des services ==="
|
|
|
|
# Vérifier si les services sont démarrés
|
|
if docker-compose -f infra/docker-compose.yml ps | grep -q "Up"; then
|
|
run_test "API accessible" "curl -f http://localhost:8000/api/health"
|
|
run_test "MinIO accessible" "curl -f http://localhost:9000/minio/health/live"
|
|
else
|
|
log_warning "Services non démarrés, test des services ignoré"
|
|
fi
|
|
}
|
|
|
|
# Fonction pour afficher le résumé
|
|
show_summary() {
|
|
echo ""
|
|
log_info "=== Résumé des tests ==="
|
|
echo ""
|
|
echo "Tests réussis: $TESTS_PASSED"
|
|
echo "Tests échoués: $TESTS_FAILED"
|
|
echo "Total: $((TESTS_PASSED + TESTS_FAILED))"
|
|
echo ""
|
|
|
|
if [ $TESTS_FAILED -eq 0 ]; then
|
|
log_success "🎉 Tous les tests sont passés ! L'installation est prête."
|
|
echo ""
|
|
echo "Prochaines étapes:"
|
|
echo " 1. Démarrer les services: ./quick-start.sh"
|
|
echo " 2. Vérifier la santé: ./maintenance.sh health"
|
|
echo " 3. Consulter la documentation: http://localhost:8000/api-docs"
|
|
else
|
|
log_error "❌ Certains tests ont échoué. Vérifiez les erreurs ci-dessus."
|
|
echo ""
|
|
echo "Solutions possibles:"
|
|
echo " 1. Installer les prérequis manquants"
|
|
echo " 2. Vérifier les permissions des fichiers"
|
|
echo " 3. Corriger la configuration"
|
|
fi
|
|
}
|
|
|
|
# Fonction principale
|
|
main() {
|
|
echo "🧪 Test d'installation de 4NK IA Backend"
|
|
echo ""
|
|
|
|
test_prerequisites
|
|
test_files
|
|
test_permissions
|
|
test_configuration
|
|
test_docker
|
|
test_services
|
|
show_summary
|
|
}
|
|
|
|
# Exécution
|
|
main "$@"
|