DAY-5: Build Tools and Package Managers

Mohammed IsmailMohammed Ismail
4 min read

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 ๐Ÿ› ๏ธ

  1. Java -> Maven & Gradle

  2. JavaScript -> npm, yarn & webpack

  3. Python -> pip

  4. C/C++ -> conan

  5. C# -> NuGet

  6. Golang -> dep

  7. 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

  1. Initialize a Maven project using any IDE such as intelliJ for example

  2. You will get a lot of files

  3. Now pom.xml file is used in Maven to manage dependencies

  4. Add all the dependencies your project requires in the pom.xml file

  5. Use the command โ€œmvn installโ€ to build the project

  6. Now look into the newly created target folder

  7. Your artifact must be there with the extension โ€œ.jarโ€

  8. Run the application using โ€œjava -jar <name_of_jar>โ€

JAVA PROJECT USING GRADLE AS BUILD TOOLS

  1. Initialize a Gradle project using any IDE such as intelliJ for example

  2. You will get a lot of files

  3. Now build.gradle file is used in Gradle to manage dependencies

  4. Add all the dependencies your project requires in build.gradle file

  5. Use the command โ€œ./gradlew buildโ€ to build the project

  6. Now look into the newly created build/libs folder

  7. Your artifact must be there with the extension โ€œ.jarโ€

  8. Run the application using โ€œjava -jar <name_of_jar>โ€

JAVASCRIPT PROJECT USING NPM

  1. An artifact of JavaScript is a tar or zip file

  2. There is no special artifact type defined

  3. Note that in JavaScript we have package managers and not build tools, those are npm and yarn

  4. So initialize a Node.js project

  5. Here package.json file is used to manage dependencies

  6. Use the "npm install" command to install all the dependencies

  7. Note that npm just installs the dependencies but doesnโ€™t transpile the code

  8. 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 ๐Ÿš€

  1. Build a jar or zip file

  2. Push to an artifact repository to save those packages for later use or for downloading on a remote server

  3. Build Tools have commands for that as well!

  4. Then you can download (curl, wget) it anywhere

CHANGE IN HOW WE USE ARTIFACTS ๐Ÿ”€

  1. We don't keep jar or zip files, because we have Docker

  2. We don't build them locally, because we have Jenkins and other Build Automation Tools

BUILD TOOLS AND DOCKER ๐Ÿš€

  1. 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 applications

  2. No need for a repository for each file type
    โ€จJust 1 Docker Image

  3. No need to install dependencies on the server!โ€จ Execute the install command inside Docker Image

  4. Docker Image is an alternative for all other artifact types

WHY DEVOPS ENGINEERS SHOULD KNOW ABOUT BUILD TOOLS โ“๐Ÿค”

  1. You help developers build the application because you know where and how it will run on deployment servers

  2. 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.

0
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!