Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Docker Pipeline Project

This project demonstrates a Java application built and deployed using a Docker pipeline within a Jenkins environment. The final Docker image is hosted on Docker Hub: Java App Pipeline Image.

Prerequisites

  • Docker: Install and run Docker from here.
  • Java 11 or later: Required JDK for the project.
  • Maven: Install Maven from here.
  • Jenkins: A Jenkins server is required to execute the CI/CD pipeline.

Getting Started

  1. Set Up Your Virtual Machines:

    • Install Ubuntu on Both VMs:
      • Download the Ubuntu ISO and create two VMs in VMware Workstation.
      • Install Ubuntu on both VMs.
    • Install Required Software:
      • On both VMs, update the package list and install the necessary packages:
      sudo apt update
      sudo apt install openjdk-17-jdk git docker.io
  2. Set Up Jenkins on VM1 (Jenkins Master):

    • Add the Jenkins repository and install Jenkins:
      wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
      sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
      sudo apt update
      sudo apt install jenkins
    • Start Jenkins:
      • Start Jenkins and enable it to start on boot:
      sudo systemctl start jenkins
      sudo systemctl enable jenkins
    • Access Jenkins:
      • Open a web browser and go to http://<VM1_IP>:8080.
      • Follow the setup instructions to unlock Jenkins and install suggested plugins. Screenshot 2024-10-05 014828
  3. Configure Jenkins Agent on VM2:

    • Create a Jenkins User:

      • On VM2, create a user for Jenkins:
      sudo useradd -m -s /bin/bash
      sudo passwd jenkins
    • Install Java and Docker.

    • Set Up SSH Key:

      • Generate an SSH key on VM1 and copy it to VM2:
      ssh-keygen
      ssh-copy-id jenkins@<VM2_IP>

      2

    • Configure Jenkins Agent:

      • In Jenkins (VM1), add VM2 as a new node and configure it to connect via SSH using the Jenkins user. 3
  4. Clone the Repository on VM1:

    • Clone the Repository:
      • On VM1, clone the repository:
      https://github.com/omarMohamedo-o/depi_final_project.git
  5. Modify the Front Page:

    • Navigate to the Views Directory:
      • Go to the views directory of the cloned repository:
      cd depi_final_project/views
    • Modify home.pug:
      • Edit home.pug to display your group code:
      vim home.pug
      4 5
  6. Jenkins Setup

    • In the root directory of the cloned repository, create a Jenkinsfile: 6 7
    • Configure Jenkins with necessary plugins (e.g., Pipeline, Docker). 9
    • Create a new Jenkins pipeline job. 10
    • Point the job to the Jenkinsfile in this repository. 11 12
    • Set up credentials for Docker Hub if you plan to push the image. 8
  7. Run the Jenkins Pipeline:

    • Manually trigger a build in Jenkins. 13
    • The pipeline will execute the steps defined in the Jenkinsfile. 14 15
    • Monitor the stages to ensure everything runs smoothly. 16

Project Structure

  • src/main/java/com/example: Java source code.
  • src/main/resources: Configuration files.
  • Dockerfile: Instructions for Docker image creation.
  • Jenkinsfile: Defines pipeline stages for Jenkins.

Pipeline Stages

  • Build: Compile the Java code into a JAR file.
  • Test: Optionally run unit or integration tests.
  • Docker Build: Build the Docker image using the Dockerfile.
  • Docker Push: Push the built image to Docker Hub.
  • Deploy: Optionally define deployment steps (currently omitted).

Customization

  • Application Code: Modify Java files in src to change app functionality.
  • Dockerfile: Adjust base image, dependencies, or installation steps as needed.
  • Jenkinsfile: Tailor pipeline stages to fit your specific CI/CD workflow.

Challenges and Resolutions

  • JAVA_HOME Issue on Jenkins Agent:

    • Issue: UnsupportedClassVersionError due to incorrect JAVA_HOME setting on the Jenkins agent.
    • Solution: Correct JAVA_HOME in Jenkins agent configuration to point to the JDK 11+ directory.
  • Docker Hub Credentials in Jenkins:

    • Issue: Pipeline failed to push the image due to missing credentials.
    • Solution: Add Docker Hub credentials to Jenkins and configure the job to use them via the withCredentials block.

Docker Hub Image

You can find the final Docker image on Docker Hub: Java App Pipeline.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages