PIPELINES, BUILD,
TEST & ARTIFACTS
Table of Contents
Pipelines
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
| Term | Meaning | Example |
|---|---|---|
| Pipeline | Whole automated workflow | ci.yml |
| Stage | Logical phase | build → test → scan |
| Job | Unit of work (often parallel) | unit-tests |
| Step | Single operation in a job | npm test |
| Runner | Machine executing jobs | ubuntu-latest |
Execution
02 / How a Run Executes
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
Stages & Builders
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.
05 / Without a Daemon: BuildKit & Kaniko
| BuildKit (buildx) | Kaniko | |
|---|---|---|
| Needs daemon | Yes (local or remote) | No — userspace build |
| Best in | Docker agents, dev machines | Locked-down K8s |
| Secrets | --secret mounts | Short-lived tokens |
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.
Discipline
06 / Failure Modes
Fast unit/integration + scans in PR; slow E2E and staging gates post-merge.
Handoff
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 Systems
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, nevernpm install; cache~/.npm. - Docker builds: BuildKit with
--secretmounts 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 ciovernpm installin 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.
Testing Strategy
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
| Layer | Speed | Runs in | Guards |
|---|---|---|---|
| Unit | ms each, minutes total | Every PR | Logic correctness |
| Contract | seconds | Every PR (provider + consumer) | API compatibility between services |
| Integration | minutes | Post-merge / staging | Wiring, DBs, queues |
| E2E / smoke | minutes–tens of minutes | Staging, post-deploy | Real 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.
Testing Strategy · continued
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.
Artifacts
Picking up from Pipelines, where the build succeeded — we now follow the one thing that outlives the pipeline: the versioned, immutable artifact.
01 / Vocabulary
| Term | Meaning |
|---|---|
| Artifact | Built output + version (app:1.4.2, app:sha-9f3a) |
| Registry | Storage + distribution (Hub, GHCR, ECR, Nexus) |
| Promotion | Same artifact approved staging → production (never rebuild) |
| Digest | Content 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.
Lifecycle
03 / Producer, Consumer, Lifecycle
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.
Trust & Handoff
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.
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.
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.
📇 Quick Revision — Terms Table
| Pipeline | Whole automated workflow from trigger to artifact (ci.yml). |
| Stage | Logical phase: build, test, scan. |
| Job | Unit of work inside a stage, often parallel. |
| Step | Single operation inside a job (npm test). |
| Runner | Machine executing jobs (ubuntu-latest). |
| Hermetic build | Sealed from the host: pinned deps, clean env, no latest tags. |
| Lockfile | Pinned dependency manifest (package-lock.json, go.sum). |
| BuildKit | Daemon-based builder; --secret mounts, registry cache. |
| Kaniko | Daemonless userspace image builder for locked-down clusters. |
| Test pyramid | Many fast units per PR, fewer slow E2E in staging. |
| Contract test | Guards API compatibility between services. |
| Flaky test | Non-deterministic test; quarantine same-day, fix or delete. |
| Artifact | Built output plus version (app:sha-9f3a). |
| Registry | Artifact storage and distribution (GHCR, ECR, Nexus). |
| Digest | Content hash fingerprinting the exact image. |
| Promotion | Approving the same digest onward; never rebuild. |
| Semver | Human MAJOR.MINOR.PATCH tags applied at promotion. |
| SBOM | Machine-readable ingredient list tracing CVEs to images. |
🎤 Concept Questions — Distilled Answers
Fast unit, contract, integration plus scans in PR; slow E2E and staging gates post-merge.
Otherwise you tested one binary and shipped another — verification is void.
Hermetic seals the environment; reproducible additionally guarantees byte-identical output.
ci installs lockfile-exact; install can drift to newer versions.
BuildKit everywhere a daemon exists; Kaniko exactly where daemons are banned.
Quarantine to a non-blocking suite same-day, assign an owner, fix-or-delete within one sprint.
Consumer-driven checks catch microservice API drift before deploy.
SDKs and toolchains build in early stages; only the runtime lands in the final image.
📌 Command Cheat Sheet
docker build -t ghcr.io/acme/app:sha-9f3a . | versioned image from SHA |
docker push ghcr.io/acme/app:sha-9f3a | publish immutable digest |
docker tag ghcr.io/acme/app:sha-9f3a ghcr.io/acme/app:1.4.2 | promote: same digest, human tag |
npm ci | lockfile-exact install for CI |
npm test --coverage | gated unit suite after build |
npm audit + gitleaks | dependency and secret scan per PR |
jobs: build: # npm ci + build test: needs: build # npm test --coverage scan: needs: build # npm audit + gitleaks
🧪 Self-Quiz + Answer Key
- Pipeline, stage, job, step.
- Pinned lockfiles, clean container, no latest tags or host toolchains.
- Where daemons are banned, e.g. locked-down Kubernetes.
- Unit, contract, fast integration plus scans — under 10 minutes.
- Quarantine it same-day so red stays meaningful.
- Immutable commit SHA; semver is added at promotion.
- It is unrepeatable — you cannot trace or reproduce it.
- cosign signature plus SBOM and provenance attestation.