What is CI/CD?
CI or Continuous Integration is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently into the central code repository (Github or Stash). Then there are automated tools that build the newly committed code and do a code review, etc as required upon integration. The key goals of Continuous Integration are to find and address bugs quicker, make the process of integrating code across a team of developers easier, improve software quality and reduce the time it takes to release new feature updates.
CD or Continuous Delivery is carried out after Continuous Integration to make sure that we can release new changes to our customers quickly in an error-free way. This includes running integration and regression tests in the staging area (similar to the production environment) so that the final release is not broken in production. It ensures to automate the release process so that we have a release-ready product at all times and we can deploy our application at any point in time.
What Is a Build Job?
A Jenkins build job contains the configuration for automating a specific task or step in the application building process. These tasks include gathering dependencies, compiling, archiving, or transforming code, and testing and deploying code in different environments.
Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.
What is Freestyle Projects ?? ๐ค
A freestyle project in Jenkins is a type of project that allows you to build, test, and deploy software using a variety of different options and configurations. Here are a few tasks that you could complete when working with a freestyle project in Jenkins:
Task-01
Step : 1 Create an agent for your app. ( which you deployed from docker in the earlier task)
Open the AWS Ec2 instance where we previously installed Jenkins and start installing docker, so that we can run docker commands in Jenkins
$ sudo apt-get docker.io -y
$ docker --version
Note: It is important to add our Jenkins to the docker group so that docker commands can be executable on Jenkins
$ sudo usermod -aG docker jenkins
$ sudo reboot
$ sudo cat /etc/group --View all the groups
Step 2: Create a new Jenkins freestyle project for your app.
Get back to Jenkins.
Enter a name for the project in the "Enter an item name" field, for example, "Django-todo".
Select "Freestyle project" and click "OK".
Configure the Jenkins Freestyle Project by adding a description
In the "Source Code Management" tab, select "Git" and enter the URL of your Git repository.
Repo link : https://github.com/rjthapaa/django-todo-cicd.git
As it is public repository, we don't need provide any credentials and all my Django application files are in develop branch, so changed the branch specifier session
In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.
Enter the following commands in the Execute shell
docker build . -t djangoimage:latest
Creates an image named djangoimage
Add a second step to run the "docker run" command to start a container using the image created. Always check the ports exposed in dockerfile in Gitrepo before using docker run command to create a container to use the right port.
docker run --name=dj -d -p 8000:8000 djangoimage:latest
creates a container named and runs it.
Click on apply and save
Click on "Build Now" to start the build process.
Once the build is complete and successfull, you can access your django-todo app by navigating to http://<Jenkins-server-IP-address>:8000 with security ports enabled.
Task-02
Step 1 : Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file)
Install docker-compose in your Jenkins instance, the command is
sudo apt install docker-compose -y
docker-compose -version
Log in to your Jenkins server and create a new freestyle project.
Give your project a name ("node-todo) and click "OK".
In the "General" section of the project configuration, check the "GitHub project" box and enter the URL of your GitHub repository.
Scroll down to the same page and add git repository code url.
Go to Build steps section and select Execute shell
Provide the Docker-compose commands here and click on apply & save
Dockerfile for reference https://github.com/rjthapaa/node-todo-cicd/blob/master/docker-compose.yaml
Click on Build now
Build is Sucess
Access the node-todo application EC2publicip:8000
Step 3: Set up a cleanup step in the Jenkins project to run "docker-compose down" command to stop and remove the containers defined in the compose file.
Go to configure session and edit the build steps session
Click on apply and save
Come back to the node-to app and click build now
Now all the containers are stopped and removed.
For Refference jenkins Freestyle Project visit here
You can Post on LinkedIn and let us know what you have learned from this task by #90DaysOfDevOps Challange.
Happy Learning:)