Projet Spring Boot de gestion des produits avec interface web, base de données, tests automatisés et pipeline CI/CD.
Fonctionnalités :
- CRUD complet (Créer, Lire, Modifier, Supprimer)
- Interface web avec Thymeleaf
- API REST documentée (Swagger)
- Tests automatisés (Unitaires, Intégration, Selenium)
- Containerisation Docker
- Pipeline CI/CD avec Jenkins
- Déploiement Kubernetes
- Monitoring avec Prometheus et Grafana
Technologies :
- Java 17, Spring Boot 3.x, Spring Data JPA
- MySQL (production) / H2 (tests)
- Thymeleaf, Bootstrap
- JUnit 5, Mockito, Selenium WebDriver
- Docker, Kubernetes, Jenkins
- Prometheus, Grafana, Actuator
- Swagger (springdoc-openapi)
- Java 17
- Maven 3.8+
- Docker Desktop (avec Kubernetes activé)
- kubectl (pour déploiement)
git clone https://github.com/SalmaElFathi/gestion-produits-spring.git
cd gestion-produitscp .env.example .env
# Éditer .env avec vos valeursdocker-compose up --buildL'application sera accessible sur : http://localhost:5000
Le projet contient 3 types de tests :
| Type | Description | Commande |
|---|---|---|
| Unitaires | Logique métier (Mockito) | mvn test -Dgroups=Unitaire |
| Intégration | Couches applicatives (H2) | mvn test -Dgroups=Integration |
| Selenium | Tests end-to-end (Chrome) | mvn verify -Dgroups=selenium |
Lancer tous les tests :
mvn verifySwagger UI : http://localhost:5000/swagger-ui.html
Endpoints Actuator :
- Health : http://localhost:5000/actuator/health
- Prometheus : http://localhost:5000/actuator/prometheus
# Lancer Jenkins avec toutes les configurations nécessaires
docker run -d --name jenkins --restart unless-stopped -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /c/Users/HP/.kube:/root/.kube -u root jenkins/jenkins:ltsdocker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword# Accéder au conteneur Jenkins en tant que root
docker exec -it -u root jenkins bash
# Mettre à jour les packages
apt-get update
# Installer Google Chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y google-chrome-stable
# Installer Docker CLI
apt-get install -y docker.io
usermod -aG docker jenkins
# Installer Git
apt-get install -y git
# Installer Maven
apt-get install -y maven
# Installer JDK 17
apt-get install -y openjdk-17-jdk
# Vérifier les installations
google-chrome --version
docker --version
git --version
mvn --version
java --version
echo "✅ Toutes les installations sont terminées !"
# Quitter le conteneur
exit
# Redémarrer Jenkins pour appliquer les changements
docker restart jenkinsAller dans : Manage Jenkins → Global Tool Configuration
| Outil | Configuration | Notes |
|---|---|---|
| Maven | Nom : Maven |
Installation automatique activée |
| JDK | Nom : JDK17 |
Installation automatique activée |
| Git | Nom : Git |
Installation par défaut |
Aller dans : Manage Jenkins → Credentials → System → Global credentials
| Credential | Type | ID | Description |
|---|---|---|---|
| GitHub | Username/Password | github-credentials |
Token GitHub personnel |
| Docker Hub | Username/Password | dockerhub-credentials |
Identifiants Docker Hub |
- Créer un nouveau job : New Item → Pipeline
- Dans Pipeline → Definition : choisir
Pipeline script from SCM - SCM : Git
- Repository URL :
https://github.com/SalmaElFathi/gestion-produits-spring.git - Credentials : Sélectionner
github-credentials - Script Path :
Jenkinsfile
Une fois le pipeline configuré, cliquez simplement sur "Build Now" !
Le pipeline Jenkins s'occupera automatiquement de :
- ✅ Compiler le code
- ✅ Exécuter tous les tests
- ✅ Construire l'image Docker
- ✅ Pousser l'image sur Docker Hub
- ✅ Déployer sur Kubernetes
- ✅ Configurer Prometheus et Grafana
Résultat : Votre application sera accessible via :
- 🌐 Application : http://localhost/
- 📊 Prometheus : http://localhost/prometheus
- 📈 Grafana : http://localhost/grafana
- Ouvrir Docker Desktop
- Aller dans Settings → Kubernetes
- Cocher Enable Kubernetes
- Cliquer sur Apply & Restart
# Installer l'Ingress Controller pour Docker Desktop
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml
# Vérifier l'installation
kubectl get pods -n ingress-nginxAttendez que tous les pods soient en statut Running avant de lancer le pipeline Jenkins.
# Vérifier que tout est déployé correctement
kubectl get deployments
kubectl get services
kubectl get pods
kubectl get ingressLe pipeline Jenkins automatise tout le processus :
- Checkout Code - Récupère le code depuis GitHub
- Build Maven - Compile le projet
- Tests - Exécute les tests (Unitaires, Intégration, Selenium)
- Package - Crée le fichier JAR
- Build Image - Construit l'image Docker
- ⬆ Push Docker Hub - Envoie l'image sur Docker Hub
- Deploy Kubernetes - Déploie sur Kubernetes (MySQL, App, Prometheus, Grafana, Ingress)
- Health Check - Vérifie que tout fonctionne
Prometheus + Grafana pour surveiller :
- Métriques JVM (mémoire, threads, GC)
- Performances applicatives (requêtes HTTP, latence)
- Santé des services (health checks)
- Métriques métier (nombre de produits, opérations CRUD)
Accès via Ingress :
- Prometheus : http://localhost/prometheus
- Grafana : http://localhost/grafana
gestion-produits/
├── src/
│ ├── main/java/ # Code source
│ ├── main/resources/ # Configuration, templates
│ └── test/java/ # Tests
├── k8s/ # Manifests Kubernetes
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── mysql-deployment.yaml
│ ├── prometheus-config.yaml
│ └── grafana.yaml
├── Dockerfile # Image Docker
├── docker-compose.yml # Orchestration locale
├── Jenkinsfile # Pipeline CI/CD (automatisation complète)
├── .env.example # Template variables
└── pom.xml # Dépendances Maven
- Ingress Controller : À installer une seule fois avant le premier déploiement
- Port par défaut : 5000
- H2 utilisé pour les tests
- Chrome et ChromeDriver gérés automatiquement par WebDriverManager
- Docker Desktop : Kubernetes doit être activé
- Ingress : Tous les services sont accessibles via
localhostavec différents chemins - Docker Compose : Pour tests locaux uniquement