Automatic Deployment of a simple webhook application using Jenkins and Docker

Automatic Deployment of a simple webhook application using Jenkins and Docker

ยท

3 min read

Table of contents

No heading

No headings in the article.

In this post we have successfully deployed a simple web application using Jenkins and Docker.

Step 1: Launch an AWS EC2 Instance (Jenkins-server) ๐Ÿš€

To start, we need to set up an EC2 instance on AWS. This instance will serve as our Jenkins server. Launch the instance and ensure you have the necessary access credentials to log in.

Step 2: Install Java Development Kit (JDK) and Jenkins ๐Ÿ“ฆโ˜•

Log in to your AWS EC2 instance using any ssh client such as putty and follow these commands to install the required dependencies:

sudo apt update
sudo apt install openjdk-11-jre
java -version

You will get the output as

Now, let's install Jenkins by running the following commands:

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt-get update
sudo apt-get install jenkins

You will get the output as

Once the installation is complete, Jenkins will be active and running.

Step 3: Expose Jenkins on Port 8080 ๐Ÿ”“

By default, Jenkins runs on port 8080. To access it from your web browser, we need to expose port 8080. Follow these steps:

  1. Click on "Security Groups" and edit the inbound rules.

    1. Access Jenkins using the IP address and port 8080.

Paste this above string in Administrator password

  1. Create a new item and select "GitHub project."

Enter the URL of your GitHub project and configure the source code management by selecting Git and entering the Git URL.

Set the branch as "main"

Step 5: Dockerizing the Application ๐Ÿณ

  1. Install Docker on your system:

     sudo apt-get update
     sudo apt install docker.io
     sudo usermod -aG docker jenkins
     sudo systemctl restart jenkins
    
    1. Configure the Jenkins job to use Git as the source code management.

    2. Add the following build steps in the "Execute shell":

       docker build -t my-web-app .
       docker run -d -p 80:80 my-web-app
      

  2. Your application will be running on port 80

    GitHub Link to the Project ๐Ÿ”—

    To explore the code and delve deeper into the project, you can access the GitHub repository below:

    Link to my GitHub Project

    Feel free to explore the codebase, collaborate, and contribute to this exciting project!

    Conclusion ๐ŸŒŸ

    With the added steps to stop the previous container and update the Docker image, Jenkins job is now equipped to handle continuous deployments seamlessly. Each code change will trigger Jenkins to stop the previous container, build a new image, and run the updated container, ensuring your web application always reflects the latest changes. Enjoy the automated and up-to-date deployments! ๐Ÿš€๐ŸŽ‰

ย