mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-12-27 19:07:28 +00:00
4.2 KiB
4.2 KiB
DevOps Pipeline Setup Guide
Complete guide for setting up the DevOps pipeline with Jenkins, SonarQube, Prometheus, Grafana, and OWASP ZAP.
Prerequisites
- Docker and Docker Compose installed
- Git installed
- GitHub account
- Java 25 installed locally (for local testing)
All services run on custom Docker network: devops-net
Step-by-Step Setup
1. Fork and Clone Repository
# Fork the repository on GitHub
# Then clone your fork
git clone https://github.com/YOUR_USERNAME/spring-petclinic.git
cd spring-petclinic
2. Build Custom Maven-Java25 Image
docker compose build maven-java25
3. Start All Services
docker compose up -d
This starts:
- Jenkins on
http://localhost:8082/jenkins - SonarQube on
http://localhost:9000 - Prometheus on
http://localhost:9090 - Grafana on
http://localhost:3030 - OWASP ZAP on
http://localhost:8081
4. Configure SonarQube
# Wait for SonarQube to start (check logs)
docker logs -f sonarqube
# Once ready, open http://localhost:9000
# Login: admin / admin (change password on first login)
Generate Token:
- Click on your avatar → My Account
- Security tab → Generate Tokens
- Name:
jenkins-token - Type: Global Analysis Token
- Copy the generated token
5. Configure Jenkins
# Get initial admin password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
# Open http://localhost:8082/jenkins
# Paste the password and click Continue
# Select "Install suggested plugins"
# Create admin user
Add SonarQube Server:
- Manage Jenkins → Configure System
- Scroll to "SonarQube servers"
- Click "Add SonarQube"
- Name:
SonarQubeServer - Server URL:
http://sonarqube:9000 - Server authentication token: Add → Jenkins → Secret text
- Secret: (paste your SonarQube token)
- ID:
sonar-token - Description:
SonarQube Token
- Name:
- Save
6. Create Jenkins Pipeline
Option A: Multibranch Pipeline (Recommended)
- New Item → Multibranch Pipeline
- Name:
petclinic-spring - Branch Sources → Add source → Git
- Project Repository:
https://github.com/YOUR_USERNAME/spring-petclinic
- Project Repository:
- Build Configuration → Mode: by Jenkinsfile
- Scan Multibranch Pipeline Triggers:
- ✓ Periodically if not otherwise run
- Interval: 1 minute
- Save
Option B: Pipeline
- New Item → Pipeline
- Name:
petclinic-spring - Build Triggers:
- ✓ Poll SCM
- Schedule:
* * * * *(every minute)
- Pipeline:
- Definition: Pipeline script from SCM
- SCM: Git
- Repository URL:
https://github.com/YOUR_USERNAME/spring-petclinic - Branch:
*/main(or your branch)
- Save
7. View in Blue Ocean
- Click "Open Blue Ocean" in Jenkins sidebar
- Select your pipeline
- Click "Run" to trigger a build
- Watch the visual pipeline execution
8. Configure Prometheus Monitoring
Verify Prometheus is scraping Jenkins:
# Open http://localhost:9090
# Go to Status → Targets
# Verify jenkins endpoint is UP
Prometheus Configuration (monitoring/prometheus.yml):
scrape_configs:
- job_name: "jenkins"
metrics_path: "/jenkins/prometheus"
static_configs:
- targets: ["jenkins:8080"]
9. Configure Grafana Dashboards
# Open http://localhost:3030
# Login: admin / admin
Add Prometheus Data Source:
- Configuration → Data Sources
- Add data source → Prometheus
- URL:
http://prometheus:9090 - Save & Test
Import Jenkins Dashboard:
- Create → Import
- Dashboard ID:
9964(Jenkins: Performance and Health Overview) - Select Prometheus data source
- Import
Service URLs
| Service | URL | Credentials |
|---|---|---|
| Jenkins | http://localhost:8082/jenkins | admin/admin |
| SonarQube | http://localhost:9000 | admin/admin |
| Prometheus | http://localhost:9090 | - |
| Grafana | http://localhost:3030 | admin/admin |
| ZAP | http://localhost:8081 | - |
Clean Up
# Stop all services
docker compose down
# Remove volumes (WARNING: deletes all data)
docker compose down -v