← Back
SIGNAL SERIES · BUILD

PIPELINES, BUILD,

TEST & ARTIFACTS

Trigger to build to test to versioned artifact — one flow.
Pipelines
Artifacts
V4 · 2026 · BUILD · verified 2026-09-18
Contents

Table of Contents

15 sheets
How to use this book legend
NOTE · context
KEY · must retain
WATCH OUT · gotcha
VERIFIED · check
NOTERead cover to cover once, then use the Contents to jump. Every chapter ends with a 🎓 EXAM box — if you can answer it cold, move on.
📘 Build & Artifacts · By Nabawy— 2 —▤ TOC Next
BUILD

Pipelines

03

Picking up from Source Control, where a merge fired the trigger — we now examine the pipeline that the trigger starts: stages of jobs of steps, executed by runners.

01 / Vocabulary

TermMeaningExample
PipelineWhole automated workflowci.yml
StageLogical phasebuild → test → scan
JobUnit of work (often parallel)unit-tests
StepSingle operation in a jobnpm test
RunnerMachine executing jobsubuntu-latest
📘 Build & Artifacts · By Nabawy— 3 —▤ TOC ◀ Prev Next
BUILD

Execution

04

02 / How a Run Executes

TRIGGERSTARTPR · push
→
JOBBUILDcompile
→
JOBS × NTESTparallel
→
GATEARTIFACTpackage + push

Runner checks out the commit, sets up a cached toolchain, runs build → test → scan (independent jobs in parallel, needs: for gates), and returns results as PR feedback. Fail-fast by default; advisory checks ride continue-on-error.

03 / Canonical Workflow

# ci.yml — build, then test + scan in parallel
jobs:
  build: # npm ci + build
  test:  needs: build # npm test --coverage
  scan:  needs: build # npm audit + gitleaks
BUILD VS BUY RUNNERSHosted runners win when maintenance costs more than minutes — start there. Self-host when compliance, GPUs, or private networks demand it; cache by lockfile either way.
📘 Build & Artifacts · By Nabawy— 4 —▤ TOC ◀ Prev Next
BUILD

Stages & Builders

05

04 / The Three Verification Stages

  • Build — hermetic: pinned deps, clean env, no hidden host tools. Same commit → byte-identical output anywhere.
  • Test — unit (fast, per-PR) → integration → E2E/smoke (staging). PR suites stay under 10 min.
  • Security scan — npm audit, gitleaks, Trivy on every PR. Shifting left beats incident response.
COMPONENT & INTEGRATION PIPELINES multi-binary systems: each component pipeline publishes tested versioned binaries · one integration pipeline assembles them and runs full acceptance. Trigger downstream on fresh upstream binaries; only jointly-green combinations ship.

05 / Without a Daemon: BuildKit & Kaniko

BuildKit (buildx)Kaniko
Needs daemonYes (local or remote)No — userspace build
Best inDocker agents, dev machinesLocked-down K8s
Secrets--secret mountsShort-lived tokens
RULE BuildKit everywhere a daemon exists; Kaniko exactly where daemons are banned.
RUNNERS managed = zero ops, cold caches (use registry/remote cache); self-hosted = warm cache, you own patches + scaling. Cache key must include lockfiles.

DAG — fan out independent jobs, gate fan-in; cap matrix axes; fail-fast for PR signal, advisory for experiments; retry idempotent steps only; quarantine flakes with owner + deadline.
📘 Build & Artifacts · By Nabawy— 5 —▤ TOC ◀ Prev Next
BUILD

Discipline

06

06 / Failure Modes

FlakyFLAKY TESTSshared state → quarantine, fix, or delete
↓
SlowSLOW PIPELINEno cache → cache, split, parallelize
↓
DriftWORKS LOCALLYunpinned deps → lockfiles, containerized runners
RULES PR pipeline under 10 min · pin action/tool versions · never bake secrets into logs/images · same steps locally and in CI.
Q1 What belongs in the PR pipeline vs post-merge?

Fast unit/integration + scans in PR; slow E2E and staging gates post-merge.
📘 Build & Artifacts · By Nabawy— 6 —▤ TOC ◀ Prev Next
BUILD

Handoff

07

07 / Handoff

This pipeline produces one thing that outlives it — the artifact. Continue in Artifact Management, where the versioned output is stored, promoted, and traced.

📘 Build & Artifacts · By Nabawy— 7 —▤ TOC ◀ Prev Next
BUILD

Build Systems

08

A build system turns source into runnable output deterministically: dependency resolution, compilation, bundling — the same inputs must always produce the same outputs.

1. What Is It?

Picking up from CI/CD Pipelines, where the build stage was defined — here is what actually runs inside it: Maven/Gradle (JVM), npm (JS), Go modules, Cargo — each resolving declared dependencies into a compiled/bundled artifact.

2. Hermetic Builds

Hermetic = sealed from the ambient machine (see glossary). Concretely: pinned dependency versions (lockfiles: package-lock.json, pom.xml versions, go.sum), clean container per build, no latest tags, no host-installed toolchains. Violation symptom: "works in CI, fails locally" in reverse — the build drank something from its environment.

3. Caching Done Right

Cache layers, fastest first: dependency cache keyed on lockfiles → remote build cache (Gradle remote, BuildKit registry cache) → artifact reuse (skip rebuild when inputs unchanged). Golden rule: the cache key must include every input; a stale key ships stale code silently.

4. Tool Notes

  • Maven/Gradle: standard layouts, wrapper scripts (mvnw, gradlew) pin the toolchain itself — commit them.
  • npm: npm ci (lockfile-exact) in CI, never npm install; cache ~/.npm.
  • Docker builds: BuildKit with --secret mounts and registry cache (see pipelines BuildKit section); multi-stage so SDKs never ship in runtime images.

5. Failure Modes

  • Unpinned deps → "it built yesterday"; fix with lockfiles + dependabot-style updates as PRs.
  • Bloated images (SDK in prod) → slow pulls, huge attack surface; fix with multi-stage builds.
  • Cache poisoning (stale key) → phantom green; fix by keying on lockfiles + periodic cache-bust verification.

6. Interview Notes

  • Hermetic vs reproducible: sealed environment vs byte-identical output (reproducible is stricter).
  • Why npm ci over npm install in CI.
  • Multi-stage Docker: what ships vs what builds.

Related Topics

  • CI/CD Pipelines
  • Artifact Management
  • Continuous Integration

Deterministic builds produce trustworthy artifacts. Continue in Artifact Management.

📘 Build & Artifacts · By Nabawy— 8 —▤ TOC ◀ Prev Next
BUILD

Testing Strategy

09

Testing strategy decides which tests run where: fast unit tests gate every PR, slow E2E proves staging — the pyramid keeps feedback fast without losing coverage.

1. What Is It?

Picking up from Build Systems, where output became deterministic — now prove it's correct, at the right stage, at the right cost.

2. The Pyramid in Pipelines

LayerSpeedRuns inGuards
Unitms each, minutes totalEvery PRLogic correctness
ContractsecondsEvery PR (provider + consumer)API compatibility between services
IntegrationminutesPost-merge / stagingWiring, DBs, queues
E2E / smokeminutes–tens of minutesStaging, post-deployReal user journeys

Many unit, fewer E2E: an inverted pyramid (all Selenium, no units) is slow, flaky, and tells you nothing a unit test couldn't in milliseconds.

Test doubles, cheapest first: stub (canned answers) → fake (working shortcut, e.g. in-memory store) → mock (verifies interactions). Mock roles and boundaries, never implementation trivia — over-mocked suites shatter on every refactor while missing real regressions.

3. Placement Rules

  • PR pipeline: unit + contract + fast integration (< 10 min total). Anything slower moves post-merge.
  • Staging: full integration + E2E + smoke after deploy; failures block promotion, not merges.
  • Post-deploy: synthetic smoke probes continuously — the pipeline's last test never ends.
  • Acceptance criteria as executable specs: analyst + tester + developer agree the criteria before coding, written so the pipeline can run them (Given-When-Then). Docs that can't fail the build drift from behavior.

4. Flaky Policy

Flaky test protocol: quarantine to a non-blocking suite immediately (same day), assign an owner, fix-or-delete deadline of one sprint. A flaky gate teaches developers that red is meaningless — the most expensive test debt there is.

📘 Build & Artifacts · By Nabawy— 9 —▤ TOC ◀ Prev Next
BUILD

Testing Strategy · continued

10

5. Capacity & Performance Placement

Functional tests prove correctness; capacity tests prove survival. Treat performance as a requirement with a number, not a wish:

  • Quantify first: convert expected load into thresholds (p99 latency, sustained throughput, concurrent users) — unquantified goals justify unbounded effort.
  • Placement: short performance smoke sentinels in the PR pipeline; full load scenarios post-merge/staging on isolated, production-like hosts (shared or noisy hosts produce phantom regressions).
  • Derive load from reality: adapt acceptance flows into composable load scenarios; warm up caches/JIT before measuring.
  • Ratchet thresholds: start at minimum viable target, raise as headroom proves stable; investigate before lowering.
  • Vocabulary: latency (one transaction's time) vs throughput (transactions per interval) vs capacity (max sustainable throughput within latency budget).

6. Failure Modes

  • Testing pyramid inverted → 40-minute PR suites developers ignore; rebalance toward units.
  • E2E in PR → queue pileups; move to staging.
  • No contract tests in microservices → integration surprises at deploy; add consumer-driven contracts.
  • Coverage % as a target → gaming (assert-free tests); treat coverage as smoke signal, not goal.

7. Interview Notes

  • Why contract tests exist (microservice API drift).
  • Flaky quarantine protocol, step by step.
  • What runs in PR vs staging vs post-deploy, and why.

Related Topics

  • CI/CD Pipelines
  • Build Systems
  • Continuous Delivery

Proven correct — now ship it releasably. Continue in Continuous Delivery.

🎓 EXAMPipelines in one breath: a merge fires stages of jobs of steps on runners; build hermetic (pinned lockfiles, clean env), test by pyramid (fast units per PR, slow E2E post-merge, flakes quarantined same-day), scan every PR; BuildKit where daemons exist, Kaniko where banned; PR suites stay under 10 min.

⏭️ Next: Artifacts

📘 Build & Artifacts · By Nabawy— 10 —▤ TOC ◀ Prev Next
BUILD

Artifacts

11

Picking up from Pipelines, where the build succeeded — we now follow the one thing that outlives the pipeline: the versioned, immutable artifact.

01 / Vocabulary

TermMeaning
ArtifactBuilt output + version (app:1.4.2, app:sha-9f3a)
RegistryStorage + distribution (Hub, GHCR, ECR, Nexus)
PromotionSame artifact approved staging → production (never rebuild)
DigestContent hash — the image's fingerprint

02 / Why Immutability

Rebuilding per environment means testing one binary and shipping another. Immutable artifacts guarantee what passed staging is what runs in production.

📘 Build & Artifacts · By Nabawy— 11 —▤ TOC ◀ Prev Next
BUILD

Lifecycle

12

03 / Producer, Consumer, Lifecycle

PRODUCER build job → STORAGE registry → CONSUMER CD pipeline · Lifecycle: build → store → promote → deploy → retire.

04 / Commands

$ docker build -t ghcr.io/acme/app:sha-9f3a .

$ docker push ghcr.io/acme/app:sha-9f3a

$ docker tag ghcr.io/acme/app:sha-9f3a ghcr.io/acme/app:1.4.2 # promote: same digest, human tag

$ docker push ghcr.io/acme/app:1.4.2

05 / Versioning

  • Immutable primary tag: commit SHA — traceable, never overwritten.
  • Human tags: semver (MAJOR.MINOR.PATCH) applied at promotion, never rebuilt.
  • Never deploy :latest — it is unrepeatable.
  • Also valid: build numbers (build-1042) for ordering, date tags for nightlies. SHA always = truth.
📘 Build & Artifacts · By Nabawy— 12 —▤ TOC ◀ Prev Next
BUILD

Trust & Handoff

13

06 / Failure Modes

  • Mutable tags overwritten → unreproducible deploys; fix with SHA digests + tag immutability.
  • Registry bloat/slow pulls; fix with retention + layer caching + regional mirrors.
  • Secrets baked into images; fix with multi-stage builds + secret mounts, scan with Trivy.
SUPPLY-CHAIN TRUST

Sign artifacts (cosign proves who built the image) and keep SBOMs (the machine-readable ingredient list) so a future CVE traces to exactly the affected images. Provenance attestations (SLSA-style) let consumers verify builder + commit before promoting.

Q2 Why must the same digest flow through all environments?

Otherwise you tested one binary and shipped another — verification is void.

07 / Handoff

The artifact is frozen — now it must travel. Continue in Continuous Delivery, where this exact digest moves through staging to production.

🎓 EXAMArtifacts in one breath: the build publishes one immutable SHA digest to the registry; staging and production deploy the same digest, promotion only adds human tags (never :latest, never rebuild); sign with cosign, keep SBOMs and provenance — what passed staging is what runs in production.
📘 Build & Artifacts · By Nabawy— 13 —▤ TOC ◀ Prev Next
BUILD

📇 Quick Revision — Terms Table

14
PipelineWhole automated workflow from trigger to artifact (ci.yml).
StageLogical phase: build, test, scan.
JobUnit of work inside a stage, often parallel.
StepSingle operation inside a job (npm test).
RunnerMachine executing jobs (ubuntu-latest).
Hermetic buildSealed from the host: pinned deps, clean env, no latest tags.
LockfilePinned dependency manifest (package-lock.json, go.sum).
BuildKitDaemon-based builder; --secret mounts, registry cache.
KanikoDaemonless userspace image builder for locked-down clusters.
Test pyramidMany fast units per PR, fewer slow E2E in staging.
Contract testGuards API compatibility between services.
Flaky testNon-deterministic test; quarantine same-day, fix or delete.
ArtifactBuilt output plus version (app:sha-9f3a).
RegistryArtifact storage and distribution (GHCR, ECR, Nexus).
DigestContent hash fingerprinting the exact image.
PromotionApproving the same digest onward; never rebuild.
SemverHuman MAJOR.MINOR.PATCH tags applied at promotion.
SBOMMachine-readable ingredient list tracing CVEs to images.
KEY IDEACover the right column and define each term aloud. Any stumble goes back to its chapter.
📘 Build & Artifacts · By Nabawy— 14 —▤ TOC ◀ Prev Next
BUILD

🎤 Concept Questions — Distilled Answers

15
Q1 What belongs in the PR pipeline vs post-merge?

Fast unit, contract, integration plus scans in PR; slow E2E and staging gates post-merge.
Q2 Why must the same digest flow through every environment?

Otherwise you tested one binary and shipped another — verification is void.
Q3 Hermetic vs reproducible?

Hermetic seals the environment; reproducible additionally guarantees byte-identical output.
Q4 Why npm ci over npm install in CI?

ci installs lockfile-exact; install can drift to newer versions.
Q5 BuildKit vs Kaniko rule?

BuildKit everywhere a daemon exists; Kaniko exactly where daemons are banned.
Q6 Flaky test protocol, step by step?

Quarantine to a non-blocking suite same-day, assign an owner, fix-or-delete within one sprint.
Q7 Why do contract tests exist?

Consumer-driven checks catch microservice API drift before deploy.
Q8 Multi-stage Docker: what ships vs what builds?

SDKs and toolchains build in early stages; only the runtime lands in the final image.
📘 Build & Artifacts · By Nabawy— 15 —▤ TOC ◀ Prev Next
BUILD

📌 Command Cheat Sheet

16
Docker
docker build -t ghcr.io/acme/app:sha-9f3a .versioned image from SHA
docker push ghcr.io/acme/app:sha-9f3apublish immutable digest
docker tag ghcr.io/acme/app:sha-9f3a ghcr.io/acme/app:1.4.2promote: same digest, human tag
JS build & verify
npm cilockfile-exact install for CI
npm test --coveragegated unit suite after build
npm audit + gitleaksdependency and secret scan per PR
jobs:
  build: # npm ci + build
  test:  needs: build # npm test --coverage
  scan:  needs: build # npm audit + gitleaks
NOTEDiagnostic order: red gate first — read the failing check, reproduce locally, fix, re-verify. Never bypass.
📘 Build & Artifacts · By Nabawy— 16 —▤ TOC ◀ Prev Next
BUILD

🧪 Self-Quiz + Answer Key

17
Q1 Name the pipeline hierarchy top to bottom.
Q2 What makes a build hermetic?
Q3 When is Kaniko the right builder?
Q4 What runs in the PR pipeline?
Q5 First action on a flaky gate?
Q6 What primarily tags an artifact?
Q7 Why never deploy :latest?
Q8 What proves who built an image?
Answer key
  1. Pipeline, stage, job, step.
  2. Pinned lockfiles, clean container, no latest tags or host toolchains.
  3. Where daemons are banned, e.g. locked-down Kubernetes.
  4. Unit, contract, fast integration plus scans — under 10 minutes.
  5. Quarantine it same-day so red stays meaningful.
  6. Immutable commit SHA; semver is added at promotion.
  7. It is unrepeatable — you cannot trace or reproduce it.
  8. cosign signature plus SBOM and provenance attestation.
FINAL CHECKEight for eight from memory, twice in a row — the build arc is yours. Open Delivery, Deployment & Operations next.
📘 Build & Artifacts · By Nabawy— 17 —▤ TOC ◀ Prev ▲ Top

Related books