Automatic Deployment of a simple webhook application using Jenkins and Docker
Table of contents
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:
Click on "Security Groups" and edit the inbound rules.
- Access Jenkins using the IP address and port 8080.
Paste this above string in Administrator password
- 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 ๐ณ
Install Docker on your system:
sudo apt-get update sudo apt install docker.io sudo usermod -aG docker jenkins sudo systemctl restart jenkins
Configure the Jenkins job to use Git as the source code management.
Add the following build steps in the "Execute shell":
docker build -t my-web-app . docker run -d -p 80:80 my-web-app
-
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:
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! ๐๐