This repository contains an End-to-End Multi-Tier Bank Application built using Java (Spring Boot). The application is containerized, enabling seamless deployment on AWS EC2 instances using tools like Docker, Docker Compose, Jenkins, and more.
- Technology Stack: Java, Spring Boot, MySQL, Docker, Jenkins, AWS
- Deployment Options:
- Docker Networking
- Docker Compose
- Jenkins-based CI/CD
Ensure you have the following:
- AWS Account
- Ubuntu EC2 Instance (Recommended:
t2.medium
) - Installed Tools:
- Docker
ssh -i "your pem- key" ubuntu@ec2-44-244-168-242.us-west
Create a new Directory:
mkdir dir_name
Go into cd dir_name
git clone -b DevOps https://github.com/nkantamani2023/Springboot-BankApp.git
cd Springboot-BankApp
Install Docker
sudo apt update -y
sudo apt install docker.io && docker-compose-v2 -y
sudo usermod -aG docker $USER && newgrp docker
Build the Docker Image
docker build -t bankapp .
Create Docker Network
docker network create bankapp
Run MySQL Container
docker run -itd --name mysql \
-e MYSQL_ROOT_PASSWORD=${DB_PASSWORD} \
-e MYSQL_DATABASE=${DB_NAME} \
--network=bankapp mysql
Run Application Container
docker run -itd --name BankApp \
-e SPRING_DATASOURCE_USERNAME=${DB_USER} \
-e SPRING_DATASOURCE_URL="jdbc:mysql://mysql:3306/BankDB?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC" \
-e SPRING_DATASOURCE_PASSWORD=${DB_PASSWORD} \
--network=bankapp \
--health-cmd="curl -f http://localhost:8080/actuator/health || exit 1" \
--health-interval=30s \
--restart=unless-stopped \
--memory="512m" \
--memory-swap="1g" \
-p 8080:8080 bankapp
Access the Application Open Port 8080 of your AWS EC2 instance. Navigate to: http://:8080 🎉 Congratulations! Your application is live.
🌐 Future Enhancements CI/CD pipeline with Jenkins (Guide).
Step 1: Go to the AWS EC2 instance and copy your master-node public ip address and paste it in the browser address-bar with port 8080
.
Step 2: Go to AWS your master-node instaces and select security groups and go to add rule 8080
save this.
Step 3: Configure your pipeline.
pipeline{
agent { label 'agent-slave' }
stages{
stage("Code Clone"){
steps{
echo "Code Clone Stage"
git url: "https://github.com/nkantamani2023/Springboot-BankApp.git", branch: "DevOps"
}
}
stage("Code Build & Test"){
steps{
echo "Code Build Stage"
sh "docker system prune -f"
sh "docker build -t bankapp ."
}
}
stage("Push To DockerHub"){
steps{
withCredentials([usernamePassword(
credentialsId:"dockerhub-creds",
usernameVariable:"dockerHubUser",
passwordVariable:"dockerHubPass")]){
sh 'echo $dockerHubPass | docker login -u $dockerHubUser --password-stdin'
sh "docker image tag bankapp:latest ${env.dockerHubUser}/bankapp:latest"
sh "docker push ${env.dockerHubUser}/bankapp:latest"
}
}
}
stage("Deploy"){
steps{
script {
try {
sh "docker compose -f docker-compose.yml down"
sh "docker compose -f docker-compose.yml up -d --build"
sh "timeout 300 bash -c 'while ! curl -s http://localhost:8080/actuator/health; do sleep 5; done'"
} catch (Exception e) {
sh "docker compose -f docker-compose.yml down"
sh "docker compose -f docker-compose.yml up -d --build --force-recreate previous-version"
error "Deployment failed: ${e.message}"
}
}
}
}
}
}
Step 4: Navigate to bank app dashboard and click on Build Now
button.
Step 5: Your Pipeline has been created
👨💻 Author: Kantamani