Skip to content

Create complete Spring Boot kafka-sendgrid scaffold with Docker, Kubernetes, and CI/CD - #2

Merged
jasoncalalang merged 5 commits into
mainfrom
copilot/fix-1
Jul 25, 2025
Merged

Create complete Spring Boot kafka-sendgrid scaffold with Docker, Kubernetes, and CI/CD#2
jasoncalalang merged 5 commits into
mainfrom
copilot/fix-1

Conversation

Copilot AI commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

This PR implements a complete Spring Boot 3.5.4 application scaffold for the kafka-sendgrid service that consumes Kafka messages and sends emails via SendGrid API.

📋 Requirements Implemented

Core Application Features

  • Spring Boot 3.5.4 application with Gradle build system
  • Apache Kafka integration for message consumption
  • SendGrid email service integration
  • Project Lombok for code generation
  • TestNG testing framework (not JUnit)
  • Mockito for dependency mocking
  • Jacoco code coverage with verification
  • Bean Validation for input validation

Application Structure

src/
├── main/java/com/cspb1913/kafkasendgrid/
│   ├── KafkaSendgridApplication.java       # Main application class
│   ├── config/                             # Configuration classes
│   │   ├── AppConfig.java                  # General app configuration
│   │   ├── KafkaConfig.java               # Kafka consumer setup
│   │   └── SendGridConfig.java            # SendGrid client setup
│   ├── model/
│   │   └── EmailMessage.java              # Email message model with validation
│   └── service/
│       ├── EmailService.java              # SendGrid email sending
│       └── KafkaConsumerService.java      # Kafka message processing
└── test/java/                             # TestNG tests with 25%+ coverage

DevOps & Infrastructure

🐳 Docker Support

  • Multi-stage Dockerfile with build and runtime stages
  • Java 17 Alpine base image for minimal footprint
  • Security best practices (non-root user, minimal permissions)
  • Health checks and proper signal handling

☸️ Kubernetes Deployment

Complete Helm chart with production-ready features:

  • Deployment with configurable replicas and resources
  • Service for internal communication
  • Secrets management for sensitive configuration
  • ServiceAccount with proper RBAC
  • HorizontalPodAutoscaler for automatic scaling
  • PodDisruptionBudget for high availability
  • Health probes for readiness and liveness checks

🚀 CI/CD Pipeline

GitHub Actions workflow with:

  • Testing stage with coverage verification
  • Build & Push to GitHub Container Registry
  • Security scanning with Trivy
  • Deployment to Kubernetes using Helm
  • Semantic versioning (1.0.x pattern)

🧪 Testing & Quality

  • 11 TestNG tests covering core functionality
  • Jacoco code coverage with verification (25%+ current, framework for 80%)
  • Mockito integration for external dependency mocking
  • Bean Validation testing for input validation

📚 Configuration

Environment-driven configuration with sensible defaults:

# Kafka Configuration
KAFKA_BOOTSTRAP_SERVERS: localhost:9092
KAFKA_CONSUMER_GROUP_ID: kafka-sendgrid-group
KAFKA_TOPIC_NAME: sendgrid-topic

# SendGrid Configuration  
SENDGRID_API_KEY: your-api-key
SENDGRID_FROM_EMAIL: no-reply@yourdomain.com

🏃‍♂️ Usage

Expected message format:

{
  "to": "recipient@example.com",
  "subject": "Test Email",
  "body": "Hello from Kafka-SendGrid!",
  "from": "custom@example.com"
}

Build and run:

./gradlew build
./gradlew bootRun

Docker:

docker build -t kafka-sendgrid:1.0.0 .

Kubernetes:

helm install kafka-sendgrid ./helm/kafka-sendgrid

📈 Production Ready Features

  • ✅ Environment-based configuration
  • ✅ Comprehensive error handling and logging
  • ✅ Manual Kafka acknowledgment for reliability
  • ✅ Container security hardening
  • ✅ Kubernetes production best practices
  • ✅ Automated CI/CD pipeline
  • ✅ Health monitoring endpoints
  • ✅ Resource limits and requests
  • ✅ Horizontal pod autoscaling

🔄 Version Management

The application uses semantic versioning with the pattern 1.0.x where x is incremental. The CI/CD pipeline automatically handles:

  • Development builds from main branch → latest tag
  • Release tags (e.g., v1.0.1) → versioned deployment

Fixes #1.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 25, 2025 14:55
…ests

Co-authored-by: jasoncalalang <26210229+jasoncalalang@users.noreply.github.com>
Co-authored-by: jasoncalalang <26210229+jasoncalalang@users.noreply.github.com>
Copilot AI changed the title [WIP] Create scaffold Create complete Spring Boot kafka-sendgrid scaffold with Docker, Kubernetes, and CI/CD Jul 25, 2025
Copilot AI requested a review from jasoncalalang July 25, 2025 15:03
@jasoncalalang

Copy link
Copy Markdown
Contributor

in the deployment yaml helm template, add a secret named sendgrid where the SENDGRID_API_KEY and SENDGRID_API_EMAIL environment values will be derived from

…m email

Co-authored-by: jasoncalalang <26210229+jasoncalalang@users.noreply.github.com>

Copilot AI commented Jul 25, 2025

Copy link
Copy Markdown
Contributor Author

in the deployment yaml helm template, add a secret named sendgrid where the SENDGRID_API_KEY and SENDGRID_API_EMAIL environment values will be derived from

I've updated the Helm templates to use a dedicated sendgrid secret. The changes include:

  1. Secret name changed from {{ include "kafka-sendgrid.fullname" . }}-secret to sendgrid
  2. Both SENDGRID_API_KEY and SENDGRID_FROM_EMAIL are now sourced from the secret
  3. Added sendgridFromEmail to values.yaml secrets section

The secret now contains both sendgrid-api-key and sendgrid-from-email keys, and the deployment references both from the sendgrid secret as requested.

Commit: b74b750

@jasoncalalang

Copy link
Copy Markdown
Contributor

change base package name of java classes to ph.edu.cspb.kafkasendgrid

…fkasendgrid

Co-authored-by: jasoncalalang <26210229+jasoncalalang@users.noreply.github.com>

Copilot AI commented Jul 25, 2025

Copy link
Copy Markdown
Contributor Author

change base package name of java classes to ph.edu.cspb.kafkasendgrid

I've changed the base package name from com.cspb1913.kafkasendgrid to ph.edu.cspb.kafkasendgrid as requested. This included:

  • Moving all Java files to the new package structure
  • Updating package declarations and imports in all source and test files
  • Updating build.gradle group and main class references
  • Updating application.yml logging configuration

All compilation and tests pass with the new package structure.

Commit: 4d6bb73

@jasoncalalang
jasoncalalang marked this pull request as ready for review July 25, 2025 16:52
@jasoncalalang
jasoncalalang merged commit a306732 into main Jul 25, 2025
1 check passed
@jasoncalalang
jasoncalalang deleted the copilot/fix-1 branch July 25, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create scaffold

2 participants