0% found this document useful (0 votes)
2 views5 pages

Project Report of docker

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Project Report: CI/CD Pipeline for Django Notes App

using docker compose and Declarative Pipeline

1. Introduction
This project focuses on building a continuous integration and continuous delivery (CI/CD)
pipeline for a Django-based Notes application. The pipeline was designed to automate the
process of building, testing, and deploying the application using Jenkins for CI, Docker for
containerization, DockerHub for image storage and push the image, and AWS EC2 for
deployment.

2. Objectives
 Automate the build and deployment process to reduce manual intervention.
 Ensure consistent testing and deployment through a well-defined CI/CD pipeline.
 Use containerization (Docker) for maintaining consistency across environments.
 Store and manage Docker images using DockerHub.
 Deploy the Django application on AWS EC2 instances.

3. Technologies and Tools Used


 Django Framework: Python-based web framework used for the Notes app.
 Jenkins: CI/CD tool used to automate the build and deployment process.
 Docker: Containerization platform to package the application into containers.
 DockerHub: Repository to store Docker images.
 AWS EC2: Cloud platform used for hosting the application.
 GitHub: Version control system to host the source code.
 Git: Version control is used for clone the source code.

4. Project Workflow
4.1 Source Code Management

The source code for the Notes application is hosted on GitHub. The repository is connected to
Jenkins for automation, and the Django application code is structured according to the following:
 Dockerfile: Defines the environment for the Django application.
 docker-compose.yml: Manages multiple services (Django, database).
 Jenkinsfile: Declarative Jenkins pipeline configuration.

4.2 Pipeline Stages

The CI/CD pipeline was implemented using Jenkins' Declarative Pipeline syntax and follows
these main stages:

1. Checkout Stage:
o Jenkins pulls the latest code from the GitHub repository.
o Triggers when a new commit is pushed to the repository (using a webhook).
2. Build Stage:
o Docker is used to build the application image by reading the Dockerfile.
o The image is tagged with the current build number or commit ID for traceability.
3. Test Stage:
o Automated tests are run within the Docker container to ensure that the application
functions correctly.
o Tests include unit tests for the Django application.
4. Docker Image Push Stage:
o If the tests pass, Jenkins pushes the Docker image to DockerHub.
o This ensures that the image is available for deployment.
5. Deploy Stage:
o The deployment is done on an AWS EC2 instance using Docker.
o Jenkins connects to the EC2 instance and pulls the latest image from DockerHub.
o The image is run in a container, making the application accessible via the public IP of the
EC2 instance.

4.3 Error Handling & Notifications

 Jenkins is configured to send email or Slack notifications in case of build failure or success.
 Build logs are retained for debugging purposes.

5. Docker Configuration
Docker Compose

In case multiple services such as a database are needed, docker-compose.yml helps


manage them.
6. Jenkins Pipeline (Declarative)
The Jenkinsfile is the core of the CI/CD pipeline and defines the stages

pipeline {

agent any

stages{

stage('cloning code'){

steps{

echo"cloning the source code"

git branch: 'main', url: 'https://github.com/Vishal2827/django-notes-app.git'

stage('building the image'){

steps{

echo"building the code"

sh "docker build -t django_app ."

stage('push'){

steps{
echo"pushing the code to the docker hub"

withCredentials([usernamePassword(credentialsId: "dockerhub_django", passwordVariable:


"dockerhubpass", usernameVariable: "dockerhubuser")]) {

sh "docker tag django_app ${env.dockerhubuser}/django_app:latest"

sh "docker login -u ${env.dockerhubuser} -p ${env.dockerhubpass}"

sh"docker push ${env.dockerhubuser}/django_app:latest "

stage('deploy'){

steps{

echo"deploy the code"

sh"docker run -d -p 8000:8000 vishal2728/django_app:latest"

7. AWS EC2 Setup


An EC2 instance running Ubuntu is set up for the deployment.

Docker is installed and configured on the instance.

Jenkins connects to the EC2 instance using SSH to deploy the Docker container.
8. Challenges Faced
 Managing Environment Variables: Sensitive information like database credentials and
API keys were securely managed using Jenkins credentials.

 Automating Tests: Some initial challenges were faced in running the tests inside
Docker, which were resolved by adjusting the Dockerfile.

9. Conclusion
The CI/CD pipeline created for the Django Notes application successfully automated the process
of building, testing, and deploying the application. This pipeline ensures fast delivery, maintains
consistent application versions, and provides a reliable mechanism to scale and update the
application on AWS.

You might also like