React Django To-do app using Jenkins

React Django To-do app using Jenkins

1. Jenkins Installation on Ubuntu

Jenkins requires Java to run.

sudo apt update
sudo apt install openjdk-11-jdk -y

First, add the repository key to your system:

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian/jenkins.io-2023.key

Next, let’s append the Debian package repository address to the server’s sources.list:

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

After both commands have been entered, run apt update so that apt will use the new repository.

sudo apt update

Finally, install Jenkins and its dependencies:

sudo apt-get install jenkins
sudo systemctl start jenkins.service
sudo systemctl status jenkins

Jenkins runs on port 8080, make sure the port 8080 is open from AWS EC2 instance.

Check Jenkins service by systemctl command

Hit url ->instance_ip:8080

use password in location- /var/lib/jenkins/secrets/initialAdminPassword

Install suggested plugins...

Create First Admin User

Jenkins is Ready!

Difference between CI and CD?

CI can be considered as the first stage in producing and delivering code, and CD as the second.

CI focuses on preparing code for release (build/test) whereas CD involves the actual release of code (release/deploy)

Continuous Delivery vs Continuous Deployment

Continuous delivery

Continuous delivery is an extension of continuous integration. since it automatically deploys all code changes to a testing and/or production environment after the build stage. This means that on top of automated testing, you have an automated release process and you can deploy your application at any time by clicking a button.

Continuous Deployment

Continuous Deployment (CD) is a software development and DevOps practice where every code change that passes automated tests and quality checks is automatically deployed to production without any manual intervention. In other words, when code changes are ready and meet the predetermined criteria, they are released to end-users or customers automatically and immediately.

Let's begin with Django app delivery using Jenkins...

Log in to Jenkins and select 'Create a job'.

Enter a name for your project and select the option - Freestyle project

Select the GitHub project and provide the GitHub project URL

Next...in the build step, select execute shell

Firstly, we will check whether our code is getting cloned or not

To check delivery, we need to click on the play button..

Jenkins uses '/var/lib/jenkins/workspace/Django-app' location as a workspace

All code gets copied to /var/lib/jenkins/workspace/Django-app

Now move to the next step...

Before deploying your code make sure of the following points:

  1. Docker and docker-compose should be installed on your machine.

  2. Your Jenkins user should be added to the docker group.

  3. port 8001 should be open from the ec2 instance.

in the 'Execute bash' portion add below code:

echo "code cloned successflly"

docker build . -t django-app
echo "code build successfully"

docker run -d -p 8001:8001 django-app:latest
echo "code deployed successfully"

click on the Django-app Delivery button...

check console output...

On the machine, we will check for the docker image and docker container...

Here we GO...!!!!

Django Todo-app using Jenkins Delivery is done successfully!

To make code more efficient, use below:

echo "code cloned successflly"

docker -compose down
docker compose up -d --no-deps --build web
echo "code deployed successfully"
docker compose up -d --no-deps --build <service_name>

--no-deps - Don't start linked services.

--build - Build images before starting containers.

Happy Learning...!!!