What Is CI/CD and How Does It Work?
Continuous integration is the practice of merging all code changes into a shared mainline several times a day during the build or integration stage of development. As developers merge their code changes, they can run automated tests to detect and fix errors more quickly. This enables them to improve software quality and minimize the time it takes to verify and deliver updates. CI primarily prevents integration challenges that can occur when developers do not merge code changes for long periods.
Continuous delivery is an expansion of CI in which developers automatically deploy code changes into a testing or staging environment post-build. This process ensures development and operations teams have software artifacts that have passed through standardized, continuous testing and are ready for deployment after the build stage. With CD, teams can automatically test and deploy code changes quickly and always ensure a production-ready codebase.
What Are the Principles of CI/CD?
In every CI/CD campaign, there are four main principles:
Automate everything: The more you can automate, the less manual work is necessary and the faster your team can deliver new features and bug fixes.
Build-in quality: Developers should build quality into the software from the start, rather than as an afterthought. This means writing automated tests and performing code reviews as part of the development process.
Test early and often: By testing early and often, development and operations teams can source errors quickly and prevent them from integrating into the codebase.
Deploy frequently: The more regularly you deploy, the less risk there is with each deployment. This also enables customers to receive new features and bug fixes faster.
How Does CI/CD Work?
There are four main steps in building a CI/CD pipeline:
Build: Store and package source code into an executable artifact.
Test: Insert artifact into an automated testing environment to validate code accuracy and behavior.
Deploy: Deploy artifact into a testing or staging environment (for development and operations teams) and a production environment (for end-users).
Monitor: Monitor application for errors and performance issues in deployment environments before an official release.
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
create a agent for your app. ( which you deployed from docker in earlier task)
Create a new Jenkins freestyle project for your app.
In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.
Add a second step to run the "docker run" command to start a container using the image created in step 3.
1.Created dev-agent.
2.Created Master and Jen-agent server in EC2.
3.Connect to the Master by using private key.
4.1st generate key-SSH-KEYGEN in terminal.
5.then goto cd .ssh/-->ls-->take rsa_pub key from Master server go to agent server-add it to authorized file-->come back to master server and make sure if both are connected or not -->ssh ubuntu@ip of agent.
6.Once above step is completed go to Jenkins and create credentials take private key from master and put it under SSH key so that Master will get sync with Jenkins and add Host IP as well while creating key.
7.To get conected with GITHUB nd Jenkins./Create webhook put master ip/github-webhook/
Agent created as below and added credentials in same agent.
8.Project description as below:
9.We can add build step and execute shell.
10.Add a second step to run the "docker run" command to start a container using the image created in step 3.
11.ran the image created in above step exposed port to 8000 edited security group and add port 8000.
And here is the output.
Task-02
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)
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.
Thank you for reading!! Hope you find this helpful.
#day23#90daysofdevops#devopscommunity#
Always open for suggestions..!!