- Aditya Maurya
- Rituj Singh
- Ishan Khanduja
- Kaumudi Tyagi
- Mosin Sheikh
Car Parking Application is built using Spring Boot and Deployed in AWS using Docker and Kubernetes.
Car Parking Application have 4 Modules
- Admin Module
- Customer Module
- Manager Module
- Security Module
-
Clone the Repository and open in SpringToolSuite
-
Refresh the Project to fetch and download Dependencies
-
Install pgAdmin and create database and username-password.
-
Goto application.properties file and check port is available, ddl-auto mode to "create" and modify postgres database username and password with your credentials.
-
Now, run the SpringBoot application.
-
copy localhost url from application.properties file and open in browser. Note: for Swagger interface use : LOCALHOST_URL/swagger-ui.html
-
To run web services in Postman. Note : Install Postman and run by using url with method name which you will get in controller classes.
-
Default Credentials for Admin is
username: [email protected] password: aditya
- The project uses port 9117.
- Also the default port for postgres is used 5432.
- Change the properties file if requirement arise.
NOTE: For further Information Refer to presentation.pptx in repository and webservices URL with Json data refer to .config/Tasks.txt File.
-
Create SpringBoot App
-
Create DockerFile and Add Below Content as per App
-
Generate Jar File of Application
a. Add Dependency into build.gradle File to generate Jar
task fatJar(type: Jar){
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.cg.CarParkingSytstemApplication'
}
baseName = project.name + '-all'
from { configuration.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
tasks.named('bootJar') {
launchScript()
}
b. Save and Refresh GradleFile
c. Goto Project Root Directory and open cmd
d. Run : gradle build
Or building Jar without Test Case :
gradle build -x test
-
Now, Create Github Repository of Spring Boot Application
Note: Make sure to remove build/ from gitignore file Otherwise your build Jar file wont be uploaded on github.
-
Create EC2 Instance
a. In Security Group set Type to All Traffic and Source to Anywhere
-
Install/Run Docker using below Command
sudo yum update -y sudo yum install docker -y sudo systemctl start docker sudo usermod -a -G docker ec2-user sudo systemctl enable docker sudo systemctl status docker docker info : to check it is working or not
-
Install Git
sudo yum install git
-
Re-login your Session
-
Now Copy Repository code HTTP URL from Github
-
Run Command instance :
git clone https://github.com/mossheik/CarParkingApplication.git
-
Goto Application Directory Folder
cd CarParkingApplication
-
Locate and goto Dockerfile
-
Then in CarParkingApplication directory and Run
docker build -t app . docker image ls : to check images
-
Install docker-compose
wget https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 ls -lrt sudo chmod +x docker-compose-linux-x86_64 ls -lrt sudo mv docker-compose-linux-x86_64 docker-compose sudo mv docker-compose /usr/local/bin/docker-compose docker compose --version
-
Relogin Session and Create docker-compose.yml file in project root directory
vi docker-compose.yml
version: '3.9' services: api: build: context: . ports: - "8080:9117" depends_on: db: condition: service_healthy environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres - SPRING_DATASOURCE_USERNAME=postgres - SPRING_DATASOURCE_PASSWORD=1 db: image: postgres volumes: - db_data:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD=1 - POSTGRES_USER=postgres healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s timeout: 5s retries: 5 volumes: db_data: {}
-
Run yaml file
docker-compose up -d docker-compose ps
-
Copy Public Address from AWS ec2 instance and view application in browser. Port is 8080.
-
View Database
docker exec -it postgrescontainerid Su -l postgres psql
-
Create EC2 instance with t2.medium, storage 30GB and Security group all traffic anywhere
-
Install Kubernate
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo chmod +x kubectl sudo mv kubectl /usr/bin/ sudo su –
-
Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
-
Install Docker
sudo yum update -y;sudo yum install docker -y;sudo systemctl start docker;sudo usermod -a -G docker ec2-user;sudo systemctl enable docker;sudo systemctl status docker
-
Start minkube
yum install conntrack minikube start --vm-driver=none
-
Install git and clone your project repository
yum install git git clone https://github.com/mossheik/CarParkingApplication.git cd CarParkingApplication
-
Build Docker Image and Upload to dockerHub Signup on dockerhub platform Come back to project directory
cd CarParkingApplication docker build -t YOURUSERID/carparking . docker login #type userid and password docker image ls docker push mohsin12435/carparking
Note : Now, checkout DockerHub.
-
Locate your Deployment files directory
cd CarParkingApplication cd .config
-
Apply Deployment files
kubectl apply -f db_deployment.yml kubectl apply -f service_db.yml #Copy postgress service ip address by running below command kubectl get svc #replace jdbc ipaddress in below file with above copied address vim app_deployement.yml kubectl apply -f app_deployment.yml kubectl get pod kubectl get pod --show-labels #copy label from here ex: app=server vim service_app.yml #paste here in this file at selector: app: server kubectl apply -f service_app.yml kubectl get all #to check everything which is deployed and now copy port from service/myapp ex: 8080:31650/TCP here port is 31650
-
Now its time run your application in browser
-
Access Database
kubectl exec -it postgrespodid bash su -l postgres psql