DAY-5: Build Tools and Package Managers
Table of contents
- WHAT ARE BUILD AND PACKAGE MANAGER TOOLSโ๐ค
- WHAT IS AN ARTIFACT AND ARTIFACT REPOSITORYโ๐ค
- ARTIFACTS ๐ฆ
- BUILD TOOLS FOR PROGRAMMING LANGUAGES ๐ ๏ธ
- JAVA PROJECT USING MAVEN AS BUILD TOOLS
- JAVA PROJECT USING GRADLE AS BUILD TOOLS
- JAVASCRIPT PROJECT USING NPM
- PUBLISH THE ARTIFACT ๐
- CHANGE IN HOW WE USE ARTIFACTS ๐
- BUILD TOOLS AND DOCKER ๐
- WHY DEVOPS ENGINEERS SHOULD KNOW ABOUT BUILD TOOLS โ๐ค
- ๐๐ญ๐๐ฒ ๐ญ๐ฎ๐ง๐๐! ๐๐๐ฑ๐ญ ๐ฐ๐ข๐ฅ๐ฅ ๐ฌ๐๐ Artifact Repository manager using Nexus or JFrog.
WHAT ARE BUILD AND PACKAGE MANAGER TOOLSโ๐ค
The application needs to be deployed on a production server
For that, we want to package the application into a single movable file (artifact), also called "building the code"
This is what a build tool or package manager tool does
Build tool installs all the dependencies, compiles and compresses the code
WHAT IS AN ARTIFACT AND ARTIFACT REPOSITORYโ๐ค
Artifact: Includes application code and all its dependencies
Artifact Repository: Storage for artifacts
We need Artifact Repository: To deploy artifacts multiple times, have backup etc
Examples: Nexus, Jfrog Artifactory
ARTIFACTS ๐ฆ
โArtifact files look different for each programming languageโ
Examples:
1. Java -> Jar OR War
2. JavaScript -> Zip or Tar
BUILD TOOLS FOR PROGRAMMING LANGUAGES ๐ ๏ธ
Java -> Maven & Gradle
JavaScript -> npm, yarn & webpack
Python -> pip
C/C++ -> conan
C# -> NuGet
Golang -> dep
Ruby -> RubyGems
Note: Each build tool has a file to manage dependencies
Letโs take Java and JavaScript and their build tools and package manager as an example to understand better!๐ก
JAVA PROJECT USING MAVEN AS BUILD TOOLS
Initialize a Maven project using any IDE such as intelliJ for example
You will get a lot of files
Now pom.xml file is used in Maven to manage dependencies
Add all the dependencies your project requires in the pom.xml file
Use the command โmvn installโ to build the project
Now look into the newly created target folder
Your artifact must be there with the extension โ.jarโ
Run the application using โjava -jar <name_of_jar>โ
JAVA PROJECT USING GRADLE AS BUILD TOOLS
Initialize a Gradle project using any IDE such as intelliJ for example
You will get a lot of files
Now build.gradle file is used in Gradle to manage dependencies
Add all the dependencies your project requires in build.gradle file
Use the command โ./gradlew buildโ to build the project
Now look into the newly created build/libs folder
Your artifact must be there with the extension โ.jarโ
Run the application using โjava -jar <name_of_jar>โ
JAVASCRIPT PROJECT USING NPM
An artifact of JavaScript is a tar or zip file
There is no special artifact type defined
Note that in JavaScript we have package managers and not build tools, those are npm and yarn
So initialize a Node.js project
Here package.json file is used to manage dependencies
Use the "npm install" command to install all the dependencies
Note that npm just installs the dependencies but doesnโt transpile the code
So you can copy the zip or tar file created using npm to the server then unpack or unzip it and then install all the dependencies there using npm
PUBLISH THE ARTIFACT ๐
Build a jar or zip file
Push to an artifact repository to save those packages for later use or for downloading on a remote server
Build Tools have commands for that as well!
Then you can download (curl, wget) it anywhere
CHANGE IN HOW WE USE ARTIFACTS ๐
We don't keep jar or zip files, because we have Docker
We don't build them locally, because we have Jenkins and other Build Automation Tools
BUILD TOOLS AND DOCKER ๐
No need to build and move different artifact types (e.g. Jar, War, Zip)
โจJust 1 artifact type: Docker Imageโจ We build those Docker images from the applicationsNo need for a repository for each file type
โจJust 1 Docker ImageNo need to install dependencies on the server!โจ Execute the install command inside Docker Image
Docker Image is an alternative for all other artifact types
WHY DEVOPS ENGINEERS SHOULD KNOW ABOUT BUILD TOOLS โ๐ค
You help developers build the application because you know where and how it will run on deployment servers
You need to configure the build automation tool or CI/CD Pipeline, like execute tests on the build servers, build and package into Docker Image, run the application on the server
Download the notes here: Build-tools-and-package-managers
๐๐ญ๐๐ฒ ๐ญ๐ฎ๐ง๐๐! ๐๐๐ฑ๐ญ ๐ฐ๐ข๐ฅ๐ฅ ๐ฌ๐๐ Artifact Repository manager using Nexus or JFrog.
Subscribe to my newsletter
Read articles from Mohammed Ismail directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mohammed Ismail
Mohammed Ismail
Highly motivated and enthusiastic individual with a passion for technology, particularly in the fields of DevOps and Cloud computing. As a recent B.Tech graduate, I possess a strong educational foundation that has equipped me with the skills and knowledge necessary to excel in these dynamic and rapidly evolving domains. Throughout my academic journey, I have actively pursued opportunities to expand my expertise and gain practical experience in implementing DevOps practices and leveraging Cloud services. My curiosity and dedication drive me to explore innovative solutions and stay up-to-date with the latest industry trends. I am eager to contribute my technical acumen and collaborative spirit to the success of forward-thinking organizations, and I look forward to connecting with like-minded professionals in the tech community. Let's connect and embark on a journey of continuous learning and growth together!