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
40 changes: 17 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
#----------------------------------
# Stage 1
# Stage 1 - Build Environment
#----------------------------------

# Import docker image with maven installed
FROM maven:3.8.3-openjdk-17 as builder
# Use Maven with OpenJDK 17 to compile the application
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>
# Set the working directory in the container
WORKDIR /app

# Add labels to the image to filter out if we have multiple application running
LABEL app=bankapp
# Copy all project files to the working directory
COPY . /app

# Set working directory
WORKDIR /src

# Copy source code from local to container
COPY . /src

# Build application and skip test cases
# Build the project and skip tests for a faster build process
RUN mvn clean install -DskipTests=true

#--------------------------------------
# Stage 2
# Stage 2 - Production Environment
#--------------------------------------

# Import small size java image
FROM openjdk:17-alpine as deployer
# Use a lightweight OpenJDK 17 image to run the application
FROM openjdk:17-jdk-alpine

# Copy build from stage 1 (builder)
COPY --from=builder /src/target/*.jar /src/target/bankapp.jar
# Copy the application JAR from the builder stage to the target location
COPY --from=builder /app/target/*.jar /app/target/bankapp.jar

# Expose application port
EXPOSE 8080
# Expose the application port (updated to 8000)
EXPOSE 8000

# Start the application
ENTRYPOINT ["java", "-jar", "/src/target/bankapp.jar"]
# Define the command to run the application
ENTRYPOINT ["java", "-jar", "/app/target/bankapp.jar"]
Comment on lines +21 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance production stage security and reliability

Several improvements can be made to the production stage:

  1. Use JRE instead of JDK for a smaller attack surface
  2. Add a non-root user for security
  3. Add HEALTHCHECK instruction
  4. Configure JVM memory limits

Apply these security and reliability improvements:

- FROM openjdk:17-jdk-alpine
+ FROM eclipse-temurin:17-jre-alpine
+
+ # Create a non-root user
+ RUN addgroup -S spring && adduser -S spring -G spring
+ USER spring:spring
+
COPY --from=builder /app/target/*.jar /app/target/bankapp.jar

EXPOSE 8000

- ENTRYPOINT ["java", "-jar", "/app/target/bankapp.jar"]
+ # Configure JVM memory limits and add health check
+ HEALTHCHECK --interval=30s --timeout=3s \
+   CMD wget -q --spider http://localhost:8000/actuator/health || exit 1
+ 
+ ENTRYPOINT ["java", \
+   "-XX:MaxRAMPercentage=75.0", \
+   "-jar", "/app/target/bankapp.jar"]

Committable suggestion skipped: line range outside the PR's diff.

32 changes: 32 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@Library('Shared')_

pipeline{
agent {label 'dev-server'}

stages{
stage("Code"){
steps{
clone("https://github.com/Amitabh-DevOps/banking-app-project.git","dev")
echo "Code clonning done."
}
}
Comment on lines +7 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security concern: Hardcoded repository URL

The repository URL should not be hardcoded in the pipeline. Consider:

  1. Using environment variables or Jenkins credentials
  2. Verifying the repository ownership as it points to a personal account
-                clone("https://github.com/Amitabh-DevOps/banking-app-project.git","dev")
+                clone(env.REPO_URL, "dev")

Committable suggestion skipped: line range outside the PR's diff.

stage("Build"){
steps{
dockerbuild("bankapp-mini","latest")
echo "Code build bhi hogaya."
}
}
Comment on lines +13 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve build stage with version control and documentation

The build stage could be enhanced:

  1. Use semantic versioning instead of 'latest'
  2. Add build arguments and documentation
  3. Replace informal echo message with professional logging
-                dockerbuild("bankapp-mini","latest")
-                echo "Code build bhi hogaya."
+                def version = env.BUILD_NUMBER
+                dockerbuild("bankapp-mini", version)
+                echo "Successfully built Docker image bankapp-mini:${version}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stage("Build"){
steps{
dockerbuild("bankapp-mini","latest")
echo "Code build bhi hogaya."
}
}
stage("Build"){
steps{
def version = env.BUILD_NUMBER
dockerbuild("bankapp-mini", version)
echo "Successfully built Docker image bankapp-mini:${version}"
}
}

stage("Push to DockerHub"){
steps{
dockerpush("dockerHub","bankapp-mini","latest")
echo "Push to dockerHub is also done."
}
}
Comment on lines +19 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Security and versioning improvements needed for Docker push

The Docker push stage needs enhancements:

  1. Use Jenkins credentials for DockerHub authentication
  2. Implement proper versioning
  3. Replace informal echo with proper logging
-                dockerpush("dockerHub","bankapp-mini","latest")
-                echo "Push to dockerHub is also done."
+                withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
+                    def version = env.BUILD_NUMBER
+                    dockerpush(env.DOCKER_USER, "bankapp-mini", version)
+                    echo "Successfully pushed bankapp-mini:${version} to DockerHub"
+                }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stage("Push to DockerHub"){
steps{
dockerpush("dockerHub","bankapp-mini","latest")
echo "Push to dockerHub is also done."
}
}
stage("Push to DockerHub"){
steps{
withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
def version = env.BUILD_NUMBER
dockerpush(env.DOCKER_USER, "bankapp-mini", version)
echo "Successfully pushed bankapp-mini:${version} to DockerHub"
}
}
}

stage("Deplying"){
steps{
deploy()
echo "Deployment bhi done."
}
}
Comment on lines +25 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance deployment stage with environment and rollback support

The deployment stage lacks:

  1. Environment specification
  2. Health checks
  3. Rollback mechanism
  4. Professional logging
-                deploy()
-                echo "Deployment bhi done."
+                script {
+                    def version = env.BUILD_NUMBER
+                    def environment = env.DEPLOY_ENV ?: 'development'
+                    deploy(environment: environment, version: version)
+                    echo "Successfully deployed bankapp-mini:${version} to ${environment}"
+                }

Committable suggestion skipped: line range outside the PR's diff.

}
}
Loading