Skip to content

chrisgroks/fraud-detection-legacy

Repository files navigation

Fraud Detection Legacy System - Demo Job #4

Purpose: Demonstrate migration of a complex, real-world Jenkins pipeline with shared libraries, approval gates, and multi-stage deployments to GitHub Actions.


🎯 The "Customer's Nightmare" Demo

This is a deliberately complex legacy system showcasing the typical migration challenges customers face:

  • 448-line Jenkinsfile with 17 stages
  • 3 custom shared library functions
  • Manual approval gates for production
  • Docker-in-Docker for integration tests
  • Scattered credentials across multiple stages
  • Platform-specific logic (isUnix() checks)
  • Complex conditionals and nested parallel stages
  • Hard-coded environment URLs and configuration

The Application (Intentionally Simple)

The application code is minimal by design - just enough to justify the complex pipeline:

  • Rule Engine: Spring Boot service (~100 lines) - evaluates fraud risk
  • Model Service: Flask service (~50 lines) - fake ML predictions

The Pipeline (Intentionally Complex)

The Jenkins pipeline is the star of the show - 448 lines of deliberate complexity that represents real-world legacy systems.


🏗️ Architecture

fraud-detection-legacy/
├── Jenkinsfile                          # 448 lines - THE NIGHTMARE
├── vars/                                # Jenkins shared library
│   ├── deployModel.groovy               # Custom deployment logic
│   ├── notifyTeam.groovy                # Slack/email notifications
│   └── runComplianceCheck.groovy        # PCI/compliance validation
├── jenkins-demo/
│   ├── docker-compose.yml               # Local Jenkins setup
│   └── plugins.txt                      # Required Jenkins plugins
├── rule-engine/                         # Java Spring Boot service
│   ├── pom.xml
│   ├── Dockerfile
│   └── src/
├── model-service/                       # Python Flask ML service
│   ├── requirements.txt
│   ├── Dockerfile
│   ├── app.py
│   └── test_model.py
├── integration-tests/
│   ├── docker-compose.test.yml          # Kafka + Redis for tests
│   └── run_integration_tests.sh
└── deployment/
    ├── dev-config.properties
    ├── staging-config.properties
    └── prod-config.properties

🚀 Quick Start

Prerequisites

  • Docker & Docker Compose
  • Java 11+ (for local development)
  • Python 3.9+ (for local development)
  • Maven 3.6+ (for local development)

Option 1: Run Services Locally

Rule Engine (Java Spring Boot):

cd rule-engine
mvn clean test
mvn spring-boot:run

Model Service (Python Flask):

cd model-service
pip install -r requirements.txt
pytest test_model.py
python app.py

Option 2: Run with Docker

# Build images
docker build -t fraud-rule-engine rule-engine/
docker build -t fraud-model-service model-service/

# Run containers
docker run -p 8080:8080 fraud-rule-engine
docker run -p 5000:5000 fraud-model-service

Option 3: Run Jenkins Pipeline

cd jenkins-demo
docker-compose up -d

# Access Jenkins at http://localhost:8080
# Default credentials: admin/admin (configure on first run)

🧪 Testing

Unit Tests

Java:

cd rule-engine
mvn test

Python:

cd model-service
pytest test_model.py

Integration Tests

cd integration-tests
docker-compose -f docker-compose.test.yml up -d
sleep 30
./run_integration_tests.sh
docker-compose -f docker-compose.test.yml down

Manual API Testing

Rule Engine:

# Health check
curl http://localhost:8080/health

# Low risk transaction
curl -X POST http://localhost:8080/api/check-transaction \
  -H 'Content-Type: application/json' \
  -d '{"transactionId":"test-001","amount":100,"country":"US","hour":14,"merchantNew":false}'

# High risk transaction
curl -X POST http://localhost:8080/api/check-transaction \
  -H 'Content-Type: application/json' \
  -d '{"transactionId":"test-002","amount":15000,"country":"RU","hour":3,"merchantNew":true}'

Model Service:

# Health check
curl http://localhost:5000/health

# ML prediction
curl -X POST http://localhost:5000/predict \
  -H 'Content-Type: application/json' \
  -d '{"amount":5000,"merchant":"Test Store"}'

📋 Pipeline Stages

The Jenkinsfile contains 17 stages showcasing real-world complexity:

  1. Checkout - SCM checkout
  2. Parallel Build - Java (Maven) + Python (pip)
  3. Unit Tests - JUnit + pytest
  4. Code Quality - Checkstyle + PMD
  5. Security Scans - OWASP + Safety + Custom compliance
  6. Build Docker Images - Multi-platform builds
  7. Integration Tests - Docker-in-Docker with Kafka/Redis
  8. Deploy to Dev - Using shared library
  9. Smoke Tests Dev - Health checks
  10. Deploy to Staging - Conditional on main branch
  11. Integration Tests Staging - Full API tests
  12. Manual Approval Gate ⭐ - 2-hour timeout
  13. Production Compliance Check ⭐ - Shared library
  14. Deploy to Production ⭐ - Conditional deployment
  15. Smoke Tests Prod - With retries
  16. Archive Artifacts - JARs and test reports
  17. Notify Team - Slack/email via shared library

🔥 Migration Pain Points

These are the challenges that make this demo realistic:

1. Shared Libraries

@Library('fraud-detection-lib@v1.0') _
  • Custom functions: deployModel(), notifyTeam(), runComplianceCheck()
  • Challenge: Convert to reusable workflows or composite actions

2. Manual Approval Gates

input(
    message: 'Deploy to Production?',
    ok: 'Deploy',
    submitter: 'deploy-team,managers'
)
  • Challenge: GitHub environments with required reviewers

3. Scattered Credentials

withCredentials([
    string(credentialsId: 'dev-db-password', variable: 'DB_PASS'),
    usernamePassword(credentialsId: 'kafka-creds', ...)
])
  • Challenge: Migrate to GitHub secrets with proper scoping

4. Docker-in-Docker

agent {
    docker {
        image 'docker:dind'
        args '--privileged'
    }
}
  • Challenge: Service containers or setup-docker action

5. Platform-Specific Logic

if (isUnix()) {
    sh './gradlew test'
} else {
    bat 'gradlew.bat test'
}
  • Challenge: Remove (GHA Linux by default) or use runner.os

6. Complex Conditionals

when {
    allOf {
        branch 'main'
        not { changelog '.*\\[skip-ci\\].*' }
        expression { env.DEPLOY_ENABLED == 'true' }
    }
}
  • Challenge: Translate to if: conditions in GHA

7. Hard-coded URLs & Paths

  • Environment URLs scattered throughout
  • Challenge: Environment variables and GitHub environments

🎬 Demo Narrative

"This is our fraud detection system - a legacy monster.

448 lines of Jenkins pipeline. 17 stages. 3 custom shared libraries. Manual approval gates. Docker-in-Docker. Platform-specific logic everywhere.

Traditional migration? 5+ days of manual work. Breaks on edge cases. Error-prone. Expensive.

Watch Devin migrate this in 3 minutes.

It handles the shared libraries. Converts approval gates to GitHub environments. Migrates credentials properly. Removes platform logic. Simplifies conditionals.

Complete, tested, ready to run."


📊 Success Metrics

  • 448-line Jenkinsfile successfully created
  • 3 shared library functions implemented
  • 17 pipeline stages with realistic complexity
  • 2 services (Java + Python) with tests
  • Integration tests with Docker Compose
  • Manual approval gates demonstrated
  • Docker-in-Docker setup
  • Multiple environments (dev/staging/prod)

🐛 Known Issues (By Design)

These are intentional anti-patterns to make the demo realistic:

  1. Magic sleep statements - No explanation for delays
  2. No error handling - Scripts can fail silently
  3. Hard-coded secrets - Commented out but visible
  4. Copy-paste code - Repeated logic instead of DRY
  5. Unclear naming - Generic stage names
  6. Missing cleanup - Containers not removed on failure
  7. No timeouts - Stages could hang forever
  8. Environment coupling - Dev/staging/prod logic intertwined

📚 Additional Documentation


🤝 Contributing

This is a demo project - not accepting contributions. Use it as a reference for your own migration demos.


📝 License

MIT License - Use this for demos and workshops.


🎓 Learning Resources


Demo Status: ✅ Complete and ready for presentation

About

Jenkins to GitHub Actions Migration Demo - Job #4: Customer's Nightmare. 448-line Jenkinsfile with shared libraries, approval gates, and multi-stage deployments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors