unit 04 devops updated
unit 04 devops updated
• We will also explore the different build systems and how they affect our DevOps work.
•
• Why do we build code?
• Most developers are familiar with the process of building code. When we work in the field of DevOps, however,
we might face issues that developers who specializein programming a particular component type won't
necessarily experience.
• For the purposes of this book, we define software building as the process of molding
• code from one form to another. During this process, several things might happen:
• The compilation of source code to native code or virtual machine bytecode,depending on our production
platform.
• Linting of the code: checking the code for errors and generating code quality measures by means of static code
analysis. The term "Linting" originated with a program called Lint, which started shipping with early versions
of the Unix operating system. The purpose of the program was to find bugs
• in programs that were syntactically correct, but contained suspicious codepatterns that could be
identified with a different process than compiling.
• Unit testing, by running the code in a controlled manner.
• The generation of artifacts suitable for deployment.It's a tall order!
Dependency Management: The build system ensures that all required dependencies are
available and properly integrated into the build artifact. This can include external libraries,
components, and other resources needed to run the application.
Testing: The build system runs automated tests to ensure that the code is functioning as
intended, and to catch any issues early in the development process.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
•Packaging: The build system packages the compiled code and its dependencies into a single,
deployable artifact, such as a Docker image or a tar archive.
• Version Control: The build system integrates with version control systems, such as Git, to
track changes to the code and manage releases.
•Continuous Integration: The build system can be configured to run builds automatically
whenever changes are made to the code, allowing for fast feedback and continuous integration
of new code into the main branch.
•Deployment: The build system can be integrated with deployment tools and processes to
automate the deployment of the build artifact to production environments.
• In DevOps, it's important to have a build system that is fast, reliable, and scalable, and that
can integrate with other tools and processes in the software development and delivery
pipeline. There are many build systems available, each with its own set of features and
capabilities, and choosing the right one will depend on the specific needs of the project and
team.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
4.1 The many faces of build systems
• There are many build systems that have evolved over the history of
software development. Sometimes, it might feel as if there are more
build systems than there are programming languages.
• Here is a brief list, just to get a feeling for how many there are:
• For Java, there is Maven, Gradle, and Ant
• For C and C++, there is Make in many different flavors
• For Clojure, a language on the JVM, there is Leiningen and Boot
apart from Maven
• For JavaScript, there is Grunt
• For Scala, there is sbt
• For Ruby, we have Rake
• Finally, of course, we have shell scripts of all kinds
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• Depending on the size of your organization and the type of product you are building, you
might encounter any number of these tools. To make life even moreinteresting, it's not
uncommon for organizations to invent their own build tools.
• As a reaction to the complexity of the many build tools, there is also often the idea of
standardizing a particular tool. If you are building complex heterogeneous systems, this is
rarely efficient. For example, building JavaScript software is just easier with Grunt than it
is with Maven or Make, building C code is not very efficient with Maven, and so on. Often,
the tool exists for a reason.
• Normally, organizations standardize on a single ecosystem, such as Java and Maven or
Ruby and Rake. Other build systems besides those that are used for the primary code
base are encountered mainly for native components and third-party components.
• At any rate, we cannot assume that we will encounter only one build system within our
organization's code base, nor can we assume only one programming language.
• I have found this rule useful in practice: it should be possible for a developer to check out the
code and build it with minimal surprises on his or her local developer machine.
• This implies that we should standardize the revision control system and have a single
interface to start builds locally. B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• If you have more than one build system to support, this basically means that you
need to wrap one build system in another. The complexities of the build are thus
hidden and more than one build system at the same time are allowed. Developers
not familiar with a particular build can still expect to check it out and build it with
reasonable ease.
• Maven, for example, is good for declarative Java builds. Maven is also capable of
starting other builds from within Maven builds.
• This way, the developer in a Java-centric organization can expect the following
command line to always build one of the organization's components:
• mvn clean install
• One concrete example is creating a Java desktop application installer with the
Nullsoft NSIS Windows installation system. The Java components are built with
Maven. When the Java artifacts are ready, Maven calls the NSIS installer script to
produce a self-contained executable that will install the application on Windows.
• While Java desktop applications are not fashionable these days, they continue to be
popular in some domains.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
4.2 The Jenkins build server
• Jenkins is an open-source automation server widely used for continuous integration,
continuous delivery, and continuous deployment (CI/CD) processes. It helps automate
the building, testing, and deployment of software applications. Jenkins is written in Java
and provides a web-based interface for configuring and managing various automation
tasks.
• Here are some key features and components of Jenkins:
• Jobs: Jenkins uses jobs as the building blocks for automation. A job represents a task or
a set of tasks to be executed. Jobs can be configured to perform actions like compiling
source code, running tests, deploying applications, or triggering other jobs.
• Plugins: Jenkins has a vast ecosystem of plugins that extend its functionality. Plugins
can be installed to add support for different programming languages, version control
systems, build tools, testing frameworks, deployment targets, and more.
• Build Steps: Jobs in Jenkins are composed of build steps. Build steps define the actions
that Jenkins should perform during the build process, such as executing shell
commands, running scripts, invoking build tools, or executing tests.
• Pipelines: Jenkins supports the concept of pipelines, which allows the definition of entire
build processes as code. Jenkins pipelines provide a way to express the build, test, and
deployment stages in a declarative
B.MAHESH or scripted
(YOUTUBE CHANNELmanner, enabling
:: SV TECH KNOWLEDGE ) better visibility,
reusability, and versioning of the build process.
• Distributed Builds: Jenkins can distribute build workloads across multiple nodes to
improve performance and scalability. It supports the setup of distributed build
environments where different nodes handle different parts of the build process.
• Integration and Extensibility: Jenkins integrates with various tools, version control
systems, and services. It can be easily integrated with popular platforms like Git, SVN,
Docker, JIRA, Slack, and many others. Additionally, Jenkins provides APIs and hooks for
extending its functionality and integrating with custom tools and services.
• Monitoring and Reporting: Jenkins offers comprehensive monitoring and reporting
capabilities. It provides real-time build logs, test results, and trend analysis, allowing
developers and teams to track the progress and health of their builds.
• Security and Authentication: Jenkins provides features for authentication, authorization,
and access control. It supports various security mechanisms, including user
authentication, role-based access control (RBAC), and integration with external
authentication providers like LDAP or Active Directory.
• By leveraging Jenkins, development teams can automate repetitive tasks, ensure code
quality through continuous integration and testing, and streamline the deployment
process, resulting in faster and more reliable software development cycles.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• For example: If any organization is developing a project,
then Jenkins will continuously test your project builds and
show you the errors in early stages of your development.
2.Artifact Repositories:
3.Build Pipelines:
5.Release Management:
4. Building Software:
1. The RPM system utilizes the spec file to build software packages.
2. The spec file specifies the build commands, such as compiling, linking, and packaging the software.
3. The RPM system follows the instructions in the spec file to generate the final binary package.
• By using the RPM system, you can create RPM packages for your software with well-defined build dependencies
and build instructions. The spec file allows for adaptability
B.MAHESH by ::patching
(YOUTUBE CHANNEL the source
SV TECH KNOWLEDGE ) code, ensuring that the build
process is customizable while maintaining the ability to reproduce pristine build sources.
4.4 Jenkins plugins
• Plugins are the primary means of enhancing the functionality of a Jenkins environment to suit
organization- or user-specific needs. There are over a thousand different plugins which can be
installed on a Jenkins controller and to integrate various build tools, cloud providers, analysis
tools, and much more.
• Jenkins, as an extensible automation server, offers a wide range of plugins that extend its
functionality and enable integration with various tools and technologies. Here's an overview of
Jenkins plugins:
• Source Code Management (SCM) Plugins:
• SCM plugins provide integration with different version control systems like Git, Subversion (SVN),
Mercurial, etc.
• These plugins enable Jenkins to fetch source code from repositories and trigger builds based on
changes.
• Build Tool Plugins:
• Build tool plugins integrate Jenkins with popular build tools like Apache Maven, Gradle, Ant, and
MSBuild.
• They provide build steps and configurations specific to these tools, allowing seamless integration
within Jenkins pipelines or job configurations.
• Testing Framework Plugins:
• Testing framework plugins enable integration
B.MAHESH with::various
(YOUTUBE CHANNEL testing) frameworks like JUnit, NUnit,
SV TECH KNOWLEDGE
TestNG, etc.
• Deployment Plugins:
• Deployment plugins help automate the deployment of applications to different
environments, such as application servers, cloud platforms, or containers.
• Plugins like Kubernetes, Docker, AWS Elastic Beanstalk, or Azure App Service
enable seamless deployment workflows.
• Notification Plugins:
• Notification plugins facilitate sending notifications or alerts based on build
status, test results, or other events.
• Plugins such as Email Notification, Slack Notification, or Microsoft Teams
Integration enable communication and collaboration among team members.
• Monitoring and Reporting Plugins:
• Monitoring and reporting plugins integrate Jenkins with monitoring and
reporting tools like SonarQube, JIRA, Grafana, etc.
• They provide insights into code quality, performance metrics, and project
management, enhancingB.MAHESH
the visibility and management of software projects.
(YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
Top Jenkins Plugins
• Git Plugin.
• Kubernetes Plugin
• Jira Plugin. ...
• Docker Plugin. ...
• Maven Integration Plugin. ...
• Blue Ocean Plugin. ...
• Amazon EC2 Plugin. ...
• Pipeline Plugin.
• Most development teams understand the importance of version control to coordinate code commits, and
build servers to compile and package their software, but Continuous Integration (CI) is a big topic.
•Without a build server you're slowed down by complicated, manual processes and the needless time
constraints they introduce. For example, without a build server:
● Your team will likely need to commit code before a daily deadline or during change windows
● After that deadline passes, no one can commit again until someone manually creates and tests a build
● If there are problems with the code, the deadlines and manual processes further delay the fixes
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• Building servers in DevOps involves several steps:
• Requirements gathering: Determine the requirements for the server, such as hardware specifications, operating system,
and software components needed.
• Server provisioning: Choose a method for provisioning the server, such as physical installation, virtualization, or cloud
computing.
• Operating System installation: Install the chosen operating system on the server.
•Software configuration: Install and configure the necessary software components, such as web servers, databases, and
middleware.
• Network configuration: Set up network connectivity, such as IP addresses, hostnames, and firewall rules.
• Security configuration: Configure security measures, such as user authentication, access control, and encryption.
• Monitoring and maintenance: Implement monitoring and maintenance processes, such as logging, backup, and disaster
recovery.
• Deployment: Deploy the application to the server and test it to ensure it is functioning as expected.
• Throughout the process, it is important to automate as much as possible using tools such as Ansible, Chef, or Puppet to
ensure consistency and efficiency in building servers.
• Infrastructure as code (IaC) uses DevOps methodology and versioning with a descriptive model to define and deploy
infrastructure, such as networks, virtual machines, load balancers, and connection topologies. Just as the same source code
always generates the same binary, an IaC model generates the same environment every time it deploys.
• IaC evolved to solve the problem of environment drift in release pipelines. Without IaC, teams must maintain deployment
environment settings individually. Over time, each environment becomes a "snowflake," a unique configuration that can't be
reproduced automatically. Inconsistency among environments can cause deployment issues. Infrastructure administration and
maintenance involve manual processes that are error prone and hard to track.
• IaC avoids manual configuration and enforces consistency by representing desired environment states via well-documented
code in formats such as JSON. Infrastructure deployments with IaC are repeatable and prevent runtime issues caused by
configuration drift or missing dependencies. Release pipelines execute the environment descriptions and version
configuration models to configure target environments. To make changes, the team edits the source, not the target.
• Idempotence, the ability of a given operation to always produce the same result, is an important IaC principle. A
deployment command always sets the target environment into the same configuration, regardless of the environment's
starting state. Idempotency is achieved by either automatically configuring the existing target, or by discarding the existing
target and recreating a fresh environment.
• IAC can be achieved by using tools such as Terraform, CloudFormation, or Ansible to define infrastructure components in
a file that can be versioned, tested, and deployed in a consistent and automated manner.
• Benefits of IAC include:
• Speed: IAC enables quick and efficient provisioning and deployment of infrastructure.
•Consistency: By using code to define and manage infrastructure, it is easier to ensure
consistency across multiple environments.
•Repeatability: IAC allows for easy replication of infrastructure components in different
environments, such as development, testing, and production.
•Scalability: IAC makes it easier to scale infrastructure as needed by simply modifying the
code.
•Version control: Infrastructure components can be versioned, allowing for rollback to
previous versions if necessary.
•Overall, IAC is a key component of modern DevOps practices, enabling organizations to
manage their infrastructure in a more efficient, reliable, and scalable way.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
Building by dependency order
• Many build tools have the concept of a build tree where dependencies are
built in the order required for the build to complete, since parts of the build
might depend on other parts.
• In Make-like tools, this is described explicitly; for instance, like this:
• a.out : b.o c.o
• b.o : b.c
• c.o : c.c
• So ,in order to build a.out, b.o and c.o must be built first.
• In tools such as Maven, the build graph is derived from the dependencies we
set for an artifact. Gradle, another Java build tool, also creates a build graph
before building.
• Jenkins has support for visualizing the build order for Maven builds, which
is called the reactor in Maven parlance, in the web user interface.
• This view is not available for Make-style builds, however.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• Many build tools, like Make, Maven, and Gradle, employ a build tree concept to
handle dependencies between different parts of a build. The build tree ensures
that the necessary components are built in the required order for the entire build to
successfully complete.
• In Make-like tools, such as Make itself, dependencies are explicitly described in
the build script. For example, in the code snippet provided:
• a.out : b.o c.o
• b.o : b.c
• c.o : c.c
• To build a.out, b.o and c.o must be built first, as indicated by the
dependencies specified.
• In tools like Maven and Gradle, the build graph is derived from the declared
dependencies of artifacts. These tools analyze the dependencies specified in the
build configuration and automatically construct a build graph that represents the
correct order for building the components.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
• Building by dependency order
• Building by dependency order in DevOps is the process of ensuring that the components of a system are built and deployed
in the correct sequence, based on their dependencies. This is necessary to ensure that the system functions as intended, and
that components are deployed in the right order so that they can interact correctly with each other.
• The steps involved in building by dependency order in DevOps include:
• Define dependencies: Identify all the components of the system and the dependencies between them. This can be
represented in a diagram or as a list.
• Determine the build order: Based on the dependencies, determine the correct order in which components should be built
and deployed.
• Automate the build process: Use tools such as Jenkins, TravisCI, or CircleCI to automate the build and deployment
process. This allows for consistency and repeatability in the build process.
• Monitor progress: Monitor the progress of the build and deployment process to ensure that components are deployed in
the correct order and that the system is functioning as expected.
• Test and validate: Test the system after deployment to ensure that all components are functioning as intended and that
dependencies are resolved correctly.
• Rollback: If necessary, have a rollback plan in place to revert to a previous version of the system if the build or
deployment process fails.
• In conclusion, building by dependency order in DevOps is a critical step in ensuring the success of a system deployment, as
it ensures that components are deployed in the correct order and that dependencies are resolved correctly. This results in a
more stable, reliable, and consistent system.
• Jenkins, being a versatile build system, offers support for
visualizing the build order of Maven builds in its web user
interface. This visualization, referred to as the "reactor" in
Maven terminology, helps developers understand the order
in which Maven modules or artifacts will be built within the
build tree.
• However, it's important to note that Jenkins does not provide
the same built-in visualization for Make-style builds. The
focus on visualizing the build order is primarily tailored
towards Maven builds, where the reactor structure plays a
significant role.
• In continuous integration (CI), this is where we build the application for the first time. The build stage is the first stretch of a CI/CD
pipeline, and it automates steps like downloading dependencies, installing tools, and compiling.
• Besides building code, build automation includes using tools to check that the code is safe and follows best practices. The build stage
usually ends in the artifact generation step, where we create a production-ready package. Once this is done, the testing stage can begin.
B.MAHESH (YOUTUBE CHANNEL :: SV TECH KNOWLEDGE )
The build stage starts from code commit and runs from the beginning up to the test stage
We’ll be covering testing in-depth in future articles (subscribe to the newsletter so you don’t
miss them)..
Build automation verifies that the application, at a given code commit, can qualify for further
testing. We can divide it into three parts: