Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 15, 2022 05:53 am GMT

CI/CD Tutorial For Developers

DevOps continues to grow in popularity among software development teams. Its not surprising, given the benefitss: a streamlined workflow leads to faster release frequency and deployment cycles, quicker bug detection, efficient rollback in case of any error, and a more productive team overall. DevOps engineers ensure that the processes and practices of code development, testing, and release are streamlined to reduce inefficiency, risk, and time to market. Coupled with continuous integration (CI) and continuous delivery (CD), DevOps helps IT organizations streamline their development process by automating manual tasks related to code deployment. Lets explore how you can adopt CI/CD to improve your organizations efficiency and delivery pipeline.

Continuous Integration

First, lets take a look at what CI/CD is and what its benefits are. Although these two concepts are often discussed together, each has its own role in the software development process.

Continuous integration is the process of automating the build and testing of code. It requires a SaaS build service (like Harness Hosted Builds) or an on-premise build server responsible for taking code from a source control system (such as Git), compiling it, and testing it to ensure its error-free. This helps to keep software projects on track by ensuring that errors/mistakes/bugs get spotted as soon as they occur. If a build is broken, it halts the rest of the process until its been fixed. As a result, the build process is much more streamlined.

Continuous Delivery & Deployment

Continuous delivery automates the release process. It ensures that code is always in a releasable state. This process includes taking the code from the build system and routing it through a staging environment to ensure its suitable for release. The outcome is a fully automated deployment process, which can be controlled by the team or triggered by triggers outside the team (such as when a developer pushes or commits a code to the main branch). The key difference between CI and CD is that the former is focused on building code, while the latter focuses on releasing the final product.

The below diagram depicts the difference between CI, CD, and continuous deployment.
ci and cd image

Continuous deployment is the final and most desired stage of the CI/CD process. Its the point at which the team can deploy the code with zero-touch automation. This is the difference between continuous delivery and deployment. When the deployment of the code is done via manual intervention, it is delivery. However, if the code is deployed in an automated fashion without any manual intervention, it is called continuous deployment.

How to Implement CI/CD in Your Organization

Before implementing CI/CD in your organization, you should know why you are implementing it, the goal, and which metric you would like to focus on. For example, DevOps teams usually focus on four key (DORA) metrics:

  • Lead time for changes
  • Change failure rate
  • Deployment frequency
  • Mean time to recovery

Your goal with CI/CD can also be as simple as moving away from traditional software delivery practices to cloud-native ones. This way, understanding the basics of DevOps concepts becomes very important.

If you haven't already, you may need to adopt a version control system, implement a build system, and introduce staging environments. Once these basics are in place, you can begin the CI/CD process:

  1. First, youll start with CI. This process ensures the code is tested and is clean and ready to deploy.
  2. You can then move on to the CD part, where youll be able to deploy code to staging and ready for review by the team.
  3. You can deploy the code to the production environment once everything is approved.

Next, you need to evaluate different CI/CD tools to understand which best suits your organization. Unfortunately, there are a plethora of tools that can be overwhelming to some of you. In this article, we will use a prominent CI/CD tool, Harness, to explain how CI/CD works through a simple hello world application. A well-established CI/CD pipeline also makes it easier for your team to identify areas for improvement and take action to mitigate risks that may exist in your system. It also makes it easier to implement process changes as your team grows and changes over time.

Harness CI/CD Tutorial

We will only be focusing on creating CI/CD pipelines with Harness in this tutorial. We are also a big fan of GitOps, and we have GitOps-as-a-service available at Harness to speed up your deployments.

Software development teams that adopt a CI/CD pipeline see faster software deployments with more negligible risk and quicker bug identification and remediation. If you are new to CI/CD, it can seem like an overwhelming amount of new terms and processes to learn. But setting up a CI/CD pipeline is easier than you think.

A CI/CD pipeline helps your team pinpoint where problems in your software are likely to occur before they reach end users. Additionally, it allows you to release updates more frequently and spend less time testing individual components or modules before releasing them to users. Harness is a leader in CI/CD with impeccable features. Today, we will show you how to implement CI/CD in minutes with a simple setup.
CI/CD flowchart

Pre-Requisites

  • Free Harness account to do CI/CD (on-premise)
  • Kubernetes cluster access from any cloud provider to deploy our application (you can also use Minikube or Kind to create a single node cluster).
  • Docker, preferably Docker Desktop
  • Download and install Node.js

First, we will create a simple Hello World! application in Node.js with a simple test case. I have already created this simple Hello World! application to make it easier and pushed it to GitHub. You can fork this repo to start working on it.

The Dockerfile you see in the repo will be used to build and push our application as an image to the Docker Hub. The next thing is we will build the image and push it to the Docker Hub using the command,

docker buildx build --platform=linux/arm64 --platform=linux/amd64 -t docker.io/<docker hub username>/<image name>:<tag> --push -f ./Dockerfile .

Once the build and push are successful, you can confirm it by going to your Docker Hub account.
DockerHub image

You can see the deployment.yaml file in the forked repo, which defines the deployment yaml file to help us deploy the application to our Kubernetes cluster. At this point, make sure your Kubernetes cluster is up and running.

Once everything is set, it is time to set up a Harness account to do CI/CD. Create a free Harness account and your first project. Once you sign-up at Harness, you will be presented with the new CI/CD experience and capabilities.

Add the required connectors, GitHub repo, Docker Hub and secrets, if any. Delegate in Harness is a service/software you need to install/run on the target cluster [Kubernetes cluster in our case] to connect your artifacts, infrastructure, collaboration, verification and other providers with the Harness Manager. When you set up Harness for the first time, you install a Harness Delegate.
Harness Connectors

Select the Continuous Integration module and add the necessary stages and steps, as shown below.
cicd with harness images

Test step set-up is done as below,
npm test

The Push to Docker Registry step is as below,
build and push image

Next, set up a deployment pipeline.
CD overview

Add the required details in the Service tab.
deploy service

Define the environment type in the Environment tab.
environment

Strategise the execution by selecting which deployment you prefer.
execution

Save everything and run the pipeline.
run pipeline

You can see both CI and CD getting executed one by one with all the steps specified.
CI/CD execution

Congratulations! We successfully built, and tested the application code and deployed it onto our Kubernetes cluster using the Harness platform.

You can confirm this deployment by using the command kubectl get pods
kubernetes deployments

You can see two replicas running as per our specifications on the deployment.yaml file. Also, confirm the same by going to your Kubernetes dashboard. Since I am using Google cloud (GCP), I can see and confirm that there are two pods running.
kubernetes pods

Harness platform makes it easy for developers to streamline their SDLC by leveraging the different modules available. Today we saw CI and CD modules, and Harness has a total of seven modules as of now.
Harness CI/CD modules

CI/CD and DevOps

CI/CD is an essential part of any DevOps strategy. It helps to automate the code review and testing process, making it easier for teams to test and deploy software. Its also a crucial part of creating a culture of continuous improvement. It is also important to remember that CI/CD is not a magic bullet. Laying the DevOps culture and methodologies are the initial steps. It is also important to remember that these processes and methodologies under DevOps are not static; they are ever-evolving and should be tweaked as needed to meet the teams needs.


Original Link: https://dev.to/pavanbelagatti/cicd-tutorial-for-developers-3l0

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To