Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 2Name in the course: Build and packages

Build code with make, npm, pip, Maven and Go

Before an app can run in a container, it must be built: packages installed, code compiled, tests run. A DevOps engineer does not need to write the app, but must build it the same way on every laptop and in every pipeline. These 5 tools cover most projects.

  • 6 Lessons
  • 7 Commands

$ run as a normal user# run as root (or with sudo)

Skills in this chapter

  • Build tools and package managers — 5 tools

2.1

make — one task runner for every project

make gives every project the same short commands: make build, make test, make deploy.

  • Used for: a task runner around docker, go, npm or terraform; the same steps locally and in CI.
make help
make build TAG=v1.4.0
make -n deploy
make -C services/api test

Good practice:

  • Mark task targets .PHONY; recipe lines start with a Tab.
  • Keep long logic in scripts; the Makefile only calls them.
  • CI runs the same targets as developers (make lint test).

Commands in this lesson

2.2

npm — Node.js packages and scripts

npm installs the dependencies of a JavaScript project and runs its scripts.

  • Used for: frontends and Node.js services; npm ci in Dockerfiles and pipelines.
npm ci
npm test
npm run build
npm audit --audit-level=high

Good practice:

  • Commit package-lock.json; use npm ci, not npm install, in CI.
  • --omit=dev in production images; cache ~/.npm in CI.

Commands in this lesson

2.3

pip — Python packages

pip installs Python packages, best inside a virtual environment.

  • Used for: Python services, scripts, and tools like Ansible.
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
pip freeze > requirements.txt
pip install --no-cache-dir -r requirements.txt

Good practice:

  • Never sudo pip install on the system Python.
  • Pin versions (==) or use a lock file with hashes.

2.4

Maven — Java builds

mvn builds, tests and packages Java apps from pom.xml and pushes the JAR to an artifact repository.

  • Used for: company Java services in Jenkins and GitLab pipelines.
mvn -B clean verify
mvn -B -DskipTests package
mvn -B -s ci-settings.xml deploy
mvn dependency:tree

Good practice:

  • -B -ntp for short CI logs; cache ~/.m2/repository.
  • Credentials in settings.xml from CI secrets, never in pom.xml.

Commands in this lesson

2.5

Go — the language of cloud-native tools

go builds one static binary — perfect for tiny container images and internal tools.

  • Used for: CLIs, exporters, Kubernetes operators; reading the code of Docker, Kubernetes and Terraform.
go mod tidy
go test -race ./...
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o bin/app .
GOOS=linux GOARCH=arm64 go build -o bin/app-arm64 .

Good practice:

  • Commit go.mod and go.sum; run go vet and govulncheck in CI.
  • Build static binaries and use a distroless or scratch base image.

Commands in this lesson

2.6

Use the same build in every place

"It works on my machine" ends when the build runs in a container with pinned versions.

  1. Pin the tool versions (Node 22, Go 1.23, Java 21) in the Dockerfile or CI file.
  2. Use the lock file of the language (package-lock.json, go.sum, requirements.txt with ==).
  3. Build in a multi-stage Dockerfile: big build image, small run image.
  4. Cache the package folders in CI (~/.npm, ~/.m2, ~/go/pkg/mod).
  5. Push the result to an artifact or image registry, never rebuild the same version twice.

Remember

Build once, deploy the same artifact to dev, staging and production.

All commands in this chapter