Make Development Easy with CI/CD
Working on Engineering projects and real-life projects is a different experience that involves different parameters. How people belonging to the same team from different locations work together, what makes them work effectively? is something that will be in every fresher’s mind. This blog gives a brief description of one of the aspects that make working more efficient i.e CI/CD.
What is CI/CD?
CI/CD is a way of software development where we can release software in production environments at any time in a sustainable way.CI/CD is a combined practice of CI(Continuous Integration) and CD(Continuous Delivery).
The “CI” in CI/CD always refers to continuous integration, which is an automation process for developers. A good CI system means new code changes to an app are regularly built, tested, integrated, and merged to a shared repository.
The “CD” in CI/CD refers to continuous delivery. In the practice of continuous delivery, code changes are also continuously deployed, although the deployments to production could be triggered manually. If the entire process of moving code from source repository to production is fully automated, the process is called Continuous Deployment.
CI is the prerequisite for CI/CD which requires:
1. Developers push their code to the main branch.
2. Each code push triggers an automated code build and test sequence.
The objective of CI is to produce an artifact that can be deployed.
When the developer integrates their code into the main branch, automated tests make sure, their added code hasn’t created any problems indicating the CI/CD pipeline green. ( We will have a detailed look ahead on CI/CD pipeline)
I read this in some article as a litmus test for doing CI/CD that even explains “ Why CI/CD?”
“If any developer in your team can stop what they’re doing right now and ship the current development version of code to production in 20 minutes or less without anyone stressing about what could happen — congratulations, you’re doing CI/CD!”
What is CI/CD Pipeline?
A CI/CD pipeline helps you automate steps in your software delivery process such as initiating code build, running automated tests, deploying to various environments like QA, staging, or production environments. Automated pipelines provide standard feedback loops and enable fast product iteration. We can say it as a set of steps that need to be performed to deliver a new version of a software product. In the absence of automation, engineers need to do it manually, thus affecting productivity.
Continuous Integration(CI), is a software development practice in which all developers merge code changes in a central repository multiple times a day. Continuous Delivery(CD), which on top of Continuous Integration adds the practice of automating the entire software release process. With CI, each change in code triggers an automated build and test sequence for the given project, providing feedback to the developer(s) who made the change. The entire CI feedback loop should run in less than 10 minutes.
Continuous Delivery includes infrastructure provisioning and deployment, which may be manual and consist of multiple stages. The important part is that all these processes are fully automated, with each run fully logged and visible to the complete development team.
Components Of CI/CD Pipeline:
Failure in each stage typically triggers a notification — via email, Slack, etc. — to let the developers know about the cause.
1. Source Stage:
In most cases, a pipeline run is triggered by a source code repository. A change in code triggers a notification to the CI/CD tool, which runs the corresponding pipeline.
2. Build stage
We combine the source code and its dependencies to build a runnable instance of our product that we can potentially ship to our end users. Programs are written in languages such as Java, C/C++, or Go need to be compiled, whereas Ruby, Python, and JavaScript programs work without this step.
Regardless of the language, cloud-native software is typically deployed with Docker, in which case this stage of the CI/CD pipeline builds the Docker containers.
Failure to pass the build stage is an indicator of a fundamental problem in the configuration of our project
3. Test stage
In this phase, we run automated tests(unit/integration) to validate the correctness of our code and the behavior of our product. The test stage acts as a safety net that prevents easily reproducible bugs from reaching the end-users.
The responsibility of writing tests falls on the developers and is best done while we write new code in the process of TDD or BDD. Failure during the test stage exposes problems in code integration scenarios that developers didn’t foresee when writing the code.
4. Deploy Stage
Once we have built a runnable instance of our code that has passed all tests, we’re ready to deploy it. There are usually multiple deploy environments, for example, a QA environment that is used internally by the product team, and a production environment for end-users of the product.
What are the Benefits of CI/CD?
Along with the automation of tasks that avoids human errors, there are many more benefits of CI/CD?
- Release new features more frequently: With CI/CD the pipeline is being divided into multiple stages right from a single commit to production. We can even navigate across stages and remove the roadblocks if any.
- Deliver software with fewer risks: There are defined stages in a CI/CD pipeline. If one of the stages fails, the code changes won’t be deployed. This can help deliver software with fewer risks.
- Improve developer productivity: If the development team is not using CI/CD, they work under stress. There are bad deployments done and some errors whose root cause is hard to find. Developers systematically deploy to production.