Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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<madhuppandey2908@gmail.com>
Expand All @@ -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
Expand Down
164 changes: 164 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions migration-scripts/auto-rollback.sh
Original file line number Diff line number Diff line change
@@ -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"
37 changes: 37 additions & 0 deletions migration-scripts/backup-Dockerfile
Original file line number Diff line number Diff line change
@@ -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<madhuppandey2908@gmail.com>

# 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"]
90 changes: 90 additions & 0 deletions migration-scripts/backup-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>bankapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bankapp</name>
<description>Banking Web Application</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
5 changes: 5 additions & 0 deletions migration-scripts/java-versions.properties
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions migration-scripts/rollback-java17.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading