Build and Package Manager Tools

Build and package manager tools

  • The app needs to be deployed on a production server.
  • The application is packaged into a single movable file
    • Then you can get that file to a server and run it there
    • The file is called an application artifact
  • Packaging:
    • Building the code or application into a single artifact
  • Building
    • Compiling
    • Compressing
  • After the artifact is built, we keep it in storage
    • May need to deploy it multiple times (staging, production)
    • Need backups, etc
  • The artifact storage is called the Artifact Repository
  • e.g. Nexus, JFrog Artifactory
  • What kind of file is an artifact?
    • Artifact file looks different depending on the language
      • Java: JAR or WAR file
        • Java Archive
      • Can be a Dockerfile as well.

Build artifacts

  • How to build artifacts?
  • Using a Build Tool
  • Specific to the language
    • Java: Maven and Gradle
      • Maven: XML
      • Gradle: Groovy
  • They install dependencies
  • Compile and compress your code

Example build commands

Gradle

./gradlew build
  • gradlew - Gradle wrapper
  • Results in build folder
  • There may be Java-Gradle compatibility issues

Maven

mvn package
  • Need to configure maven to build in pom.xml
  • A target folder is created after building

Managing dependencies

  • You need build tools also locally when developing the app
  • Need to run app locally
  • Maven and Gradle have their dependencies file
  • Dependencies file: for managing dependencies
  • Maven: pom.xml
  • Gradle: build.gradle
  • The dependencies come from remote repositories.

Run the artifact

  • e.g. with Java
java -jar <name of jar file>

What about JS applications?

  • JS doesn't have a special artifact file type, so it can be made into a ZIP or TAR file
  • npm or yarn can be used to manage dependencies
  • Both use package.json file for dependencies
  • They are not build tools
  • They install dependencies but not used for transpiling JS code
  • What does the zip/tar file include?
    • It includes application code, but NOT dependencies
  • To run app on the server:
    • you must install dependencies
    • unpack zip/tar
    • run the App
  • Need to copy artifact and package.json
  • To create artifact file,
npm pack
  • Can configure what gets packed

  • Different ways to package frontend and backend code

  • Can package frontend and backend code separately

  • Or you can have a common artifact for both

  • E.g. if both frontend and backend are JS

    • Can have a separate package.json file for frontend and backend
    • Can have common package.json file
  • Frontend framework code needs to be transpiled and compressed

  • We use Build tools/ bundlers for that

    • Webpack, grunt
  • If React frontend + Java backend

    • Build frontend with webpack
    • Manage dependencies with npm or yarn
    • When package whole app, package everything into a WAR file where the frontend and backend code is all in one.

Other languages and build tools

  • Python: pip
  • Patterns
    • All have dependencies files
    • All have repositories
    • Each has CLI tools
    • Have package managers

Push/Publish Artifact into Artifactory

  • Build tools have commands for that
  • Then you can download (curl, wget) it anywhere
  • But we won't pull or download like that because of Docker

Build Tools and Docker

  • Building and distributing artifacts were made easier with Docker
  • Just 1 artifact type - Docker Image
  • We build those Docker Images from the applications
  • No need for a repository for each file type
    • Just 1 for Docker Images
  • Just copy everything to Docker image and run on server
  • No need to install dependencies on server
  • Docker Image is also an artifact
  • Don't need npm or java on server
    • Execute everything in the image
  • You still need to build the apps

Build tools for DevOps Engineers

  • Why you should know build tools
  • You should help devs with commands for building and configuring the artifact
  • You will know where it will run
  • Developers install dependencies locally and run the app, but don't build it locally
  • You need to configure the build automation tool / CI/CD pipeline to
    • Install dependencies
    • run tests
    • build/bundle app
    • push to repository
  • Need to test on build servers
  • Need to build and package into Docker Image