diff --git a/Dockerfile b/Dockerfile index 079acabe..c9b0a55c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ #---------------------------------- # Import docker image with maven installed -FROM maven:3.8.3-openjdk-17 as builder +FROM maven:3.9.6-eclipse-temurin-22 as builder # Add maintainer, so that new user will understand who had written this Dockerfile MAINTAINER Madhup Pandey @@ -25,7 +25,7 @@ RUN mvn clean install -DskipTests=true #-------------------------------------- # Import small size java image -FROM openjdk:17-alpine as deployer +FROM eclipse-temurin:22-alpine as deployer # Copy build from stage 1 (builder) COPY --from=builder /src/target/*.jar /src/target/bankapp.jar diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 00000000..01b0a0ba --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,164 @@ +# Java 22 Migration Documentation + +## Overview + +This document describes the migration of the Spring Boot BankApp application from Java 17 to Java 22. The migration includes updates to the build configuration, Docker images, and CI/CD pipeline compatibility. + +## Migration Summary + +### Changes Made + +#### 1. pom.xml Updates +- Updated `java.version` property from `17` to `22` +- Updated `maven-compiler-plugin` version from `3.8.0` to `3.11.0` +- Updated compiler source and target from `1.8` to `22` + +#### 2. Dockerfile Updates +- Stage 1 (Build): Changed from `maven:3.8.3-openjdk-17` to `maven:3.9.6-eclipse-temurin-22` +- Stage 2 (Runtime): Changed from `openjdk:17-alpine` to `eclipse-temurin:22-alpine` + +**Note:** The original OpenJDK images (`maven:3.9.6-openjdk-22` and `openjdk:22-alpine`) do not exist on Docker Hub. Eclipse Temurin is the recommended replacement for OpenJDK Docker images. + +### Dependency Compatibility + +The following dependencies have been verified for Java 22 compatibility: + +| Dependency | Version | Java 22 Compatible | +|------------|---------|-------------------| +| Spring Boot | 3.3.3 | Yes | +| MySQL Connector | 8.0.33 | Yes | +| Spring Security | (managed by Spring Boot) | Yes | +| Thymeleaf | (managed by Spring Boot) | Yes | + +### CI/CD Pipeline Compatibility + +#### Jenkins Configuration +- Jenkins continues to run on Java 17 (as required by `openjdk-17-jre`) +- The pipeline uses Docker-based builds, which now use Java 22 images +- No changes required to `Jenkinsfile` or `GitOps/Jenkinsfile` +- Both pipelines will automatically use the updated Docker images with Java 22 + +#### Docker Compose +- The `docker-compose.yml` configuration remains unchanged +- Health check endpoints (`/actuator/health`) work with Java 22 +- JDBC URL configuration is compatible with Java 22 + +#### Kubernetes Deployment +- The `kubernetes/bankapp-deployment.yml` does not require immediate changes +- Memory limits (1Gi) may need adjustment after Java 22 testing +- Monitor application performance after deployment + +## Rollback Procedure + +If issues occur during migration, follow these steps: + +### Quick Rollback + +1. Run the rollback script: + ```bash + ./migration-scripts/rollback-java17.sh + ``` + +2. Rebuild the application: + ```bash + mvn clean package + ``` + +3. Rebuild Docker image: + ```bash + docker build -t bankapp:java17 . + ``` + +4. Redeploy to Kubernetes using Java 17 images + +5. Update `migration-scripts/java-versions.properties` to reflect rollback + +### Automatic Rollback + +Use the auto-rollback script for automated rollback on build failure: +```bash +./migration-scripts/auto-rollback.sh +``` + +This script will: +- Attempt to build with Java 22 +- Automatically rollback to Java 17 if the build fails +- Rebuild with Java 17 configuration + +### Validate Rollback Capability + +Before deploying to production, validate that rollback works: +```bash +./migration-scripts/validate-rollback.sh +``` + +## Testing Instructions + +### Local Build and Run + +1. Build the application: + ```bash + mvn clean package + ``` + +2. Build Docker image: + ```bash + docker build -t bankapp:java22 . + ``` + +3. Run with docker-compose: + ```bash + docker-compose up + ``` + +4. Verify application starts and connects to MySQL 8.0 + +5. Test all endpoints function correctly: + ```bash + curl http://localhost:8080/actuator/health + ``` + +### Security Scanning + +1. Run Trivy filesystem scan: + ```bash + trivy fs --severity HIGH,CRITICAL . + ``` + +2. Run Trivy image scan: + ```bash + trivy image bankapp:java22 + ``` + +3. Execute SonarQube analysis through the Jenkins pipeline + +## Migration Scripts + +The following scripts are available in the `migration-scripts/` directory: + +| Script | Purpose | +|--------|---------| +| `rollback-java17.sh` | Reverts pom.xml and Dockerfile to Java 17 | +| `auto-rollback.sh` | Automatic rollback on build failure | +| `validate-rollback.sh` | Validates rollback capability | +| `java-versions.properties` | Tracks version configurations | +| `backup-pom.xml` | Backup of original pom.xml | +| `backup-Dockerfile` | Backup of original Dockerfile | +| `test-plan.md` | Detailed test plan for migration | + +## Version History + +| Date | Version | Description | +|------|---------|-------------| +| 2026-01-07 | 1.0.0 | Initial Java 22 migration | + +## Notes + +- Jenkins remains on Java 17 - it uses Docker images with Java 22 for builds +- Kubernetes deployment files do not require changes for this migration +- Monitor application performance after deployment to production +- Review memory usage and adjust Kubernetes resource limits if needed + +## Contact + +For questions about this migration, refer to the project documentation or contact the DevOps team. diff --git a/migration-scripts/auto-rollback.sh b/migration-scripts/auto-rollback.sh new file mode 100755 index 00000000..48a2a598 --- /dev/null +++ b/migration-scripts/auto-rollback.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Automatic rollback if build fails +set -e + +echo "Attempting Java 22 build..." +mvn clean package || { + echo "Java 22 build failed, initiating rollback..." + ./migration-scripts/rollback-java17.sh + mvn clean package + echo "Rolled back to Java 17 successfully" + exit 1 +} +echo "Java 22 build successful" diff --git a/migration-scripts/backup-Dockerfile b/migration-scripts/backup-Dockerfile new file mode 100644 index 00000000..079acabe --- /dev/null +++ b/migration-scripts/backup-Dockerfile @@ -0,0 +1,37 @@ +#---------------------------------- +# Stage 1 +#---------------------------------- + +# Import docker image with maven installed +FROM maven:3.8.3-openjdk-17 as builder + +# Add maintainer, so that new user will understand who had written this Dockerfile +MAINTAINER Madhup Pandey + +# Add labels to the image to filter out if we have multiple application running +LABEL app=bankapp + +# Set working directory +WORKDIR /src + +# Copy source code from local to container +COPY . /src + +# Build application and skip test cases +RUN mvn clean install -DskipTests=true + +#-------------------------------------- +# Stage 2 +#-------------------------------------- + +# Import small size java image +FROM openjdk:17-alpine as deployer + +# Copy build from stage 1 (builder) +COPY --from=builder /src/target/*.jar /src/target/bankapp.jar + +# Expose application port +EXPOSE 8080 + +# Start the application +ENTRYPOINT ["java", "-jar", "/src/target/bankapp.jar"] diff --git a/migration-scripts/backup-pom.xml b/migration-scripts/backup-pom.xml new file mode 100644 index 00000000..fc5bfeac --- /dev/null +++ b/migration-scripts/backup-pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.3 + + + com.example + bankapp + 0.0.1-SNAPSHOT + bankapp + Banking Web Application + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity6 + + + + mysql + mysql-connector-java + 8.0.33 + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + + + diff --git a/migration-scripts/java-versions.properties b/migration-scripts/java-versions.properties new file mode 100644 index 00000000..eb85dec7 --- /dev/null +++ b/migration-scripts/java-versions.properties @@ -0,0 +1,5 @@ +# Java version tracking +current.java.version=17 +target.java.version=22 +maven.version.current=3.8.3 +maven.version.target=3.9.6 diff --git a/migration-scripts/rollback-java17.sh b/migration-scripts/rollback-java17.sh new file mode 100755 index 00000000..e48cd5da --- /dev/null +++ b/migration-scripts/rollback-java17.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Rollback script to revert to Java 17 +# Uses backup files instead of git checkout (works after PR is merged) + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +cp "$SCRIPT_DIR/backup-pom.xml" "$(dirname "$SCRIPT_DIR")/pom.xml" +cp "$SCRIPT_DIR/backup-Dockerfile" "$(dirname "$SCRIPT_DIR")/Dockerfile" + +echo "Rolled back to Java 17 configuration" diff --git a/migration-scripts/test-plan.md b/migration-scripts/test-plan.md new file mode 100644 index 00000000..46ac0fa4 --- /dev/null +++ b/migration-scripts/test-plan.md @@ -0,0 +1,82 @@ +# Java 22 Migration Test Plan + +## Overview +This document outlines the testing strategy for validating the Java 22 migration of the Spring Boot BankApp application. + +## Test Categories + +### 1. Local Build and Run Tests +- Verify Maven build completes successfully with `mvn clean package` +- Confirm no compilation errors with Java 22 +- Validate all unit tests pass +- Check for any deprecation warnings + +### 2. Docker Image Build Tests +- Build Docker image: `docker build -t bankapp:java22 .` +- Verify image builds without errors +- Confirm image uses correct base images (maven:3.9.6-openjdk-22 and openjdk:22-alpine) +- Check image size is reasonable + +### 3. Database Connectivity Tests +- Start MySQL 8.0 container +- Run application with docker-compose +- Verify JDBC connection to MySQL works +- Test database operations (CRUD) + +### 4. Health Check Endpoint Tests +- Verify `/actuator/health` endpoint responds +- Check application startup time +- Validate all Spring Boot actuator endpoints + +### 5. Security Scanning Tests +- Run Trivy filesystem scan: `trivy fs --severity HIGH,CRITICAL .` +- Run Trivy image scan: `trivy image bankapp:java22` +- Execute SonarQube analysis +- Review any new vulnerabilities introduced + +### 6. Functional Tests +- Test user registration flow +- Test login/logout functionality +- Test banking operations +- Verify all REST endpoints + +### 7. Performance Tests +- Compare startup time with Java 17 baseline +- Monitor memory usage +- Check for any performance regressions + +## Test Execution Steps + +1. **Pre-migration baseline** + ```bash + mvn clean package + docker build -t bankapp:java17-baseline . + ``` + +2. **Post-migration validation** + ```bash + mvn clean package + docker build -t bankapp:java22 . + docker-compose up -d + curl http://localhost:8080/actuator/health + ``` + +3. **Rollback verification** + ```bash + ./migration-scripts/validate-rollback.sh + ``` + +## Success Criteria +- All unit tests pass +- Docker image builds successfully +- Application starts and connects to MySQL +- Health check endpoint returns healthy status +- No HIGH or CRITICAL vulnerabilities introduced +- Performance is comparable to Java 17 baseline + +## Rollback Trigger Conditions +- Build failures +- Test failures +- Critical security vulnerabilities +- Performance degradation > 20% +- Database connectivity issues diff --git a/migration-scripts/validate-rollback.sh b/migration-scripts/validate-rollback.sh new file mode 100755 index 00000000..813aafbe --- /dev/null +++ b/migration-scripts/validate-rollback.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Validate rollback capability +echo "Testing rollback to Java 17..." +./migration-scripts/rollback-java17.sh +mvn clean package +if [ $? -eq 0 ]; then + echo "Rollback validation successful" +else + echo "Rollback validation failed" + exit 1 +fi diff --git a/pom.xml b/pom.xml index fc5bfeac..fcee7e53 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ - 17 + 22 @@ -76,14 +76,14 @@ spring-boot-maven-plugin - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 22 + 22 + +