Build Pipeline Best Practices
This list distills a production-grade image build pipeline into concrete, enforceable practices. It targets tech leads standardizing CI across services on Docker Engine 29.6.1 and Kubernetes 1.36.2.
Busque em todas as páginas da documentação
This list distills a production-grade image build pipeline into concrete, enforceable practices. It targets tech leads standardizing CI across services on Docker Engine 29.6.1 and Kubernetes 1.36.2.
Treat each practice as a gate you can enforce, not advice you can ignore. Wire the ones marked as failures into CI so drift cannot creep back in.
Adopt them incrementally. Start with reproducibility and non-root images, then layer in scanning, caching, and provenance.
Review the list per service during onboarding. A new repo should inherit these defaults from a shared workflow, not reinvent them.
FROM node:22-slim@sha256:... so a floating tag cannot silently change your build. Renovate or Dependabot can bump the digest deliberately.npm ci, pip install -r with hashes, or Go modules so installs are deterministic.image@sha256:...; tags are human aliases. Digests guarantee exact bytes and clean rollback.hadolint and fail CI on warnings you have decided are errors for your org, not just on its defaults.USER and a numeric UID so the image satisfies restricted Pod Security Standards without a securityContext override.slim, alpine, or distroless runtimes to shrink attack surface and speed node pulls..dockerignore. Exclude .git, node_modules, and secrets so build context stays small and nothing sensitive leaks into a layer.docker/metadata-action to stamp source, revision, and version so images are self-describing in the registry.push: false; publish only from protected refs.github.event_name == 'push' so untrusted forks cannot publish or leak secrets.GITHUB_TOKEN, cloud OIDC) over long-lived stored registry passwords.docker push to production repos so every image is traceable to a commit and workflow.mode=max. Ephemeral runners then restore intermediate layers instead of rebuilding from cold.amd64/arm64 matrix plus a manifest merge is faster for compilation.You should be able to trace any running pod's digest back to a signed image, a commit, and a workflow run. If you cannot, tighten gating until you can.
Every practice above should be a check that fails CI or blocks admission - not a wiki page. Enforcement is what keeps standards alive across a growing fleet of services.
Re-audit quarterly. Base image digests, scanner databases, and SLSA tooling all move, so the pipeline needs periodic maintenance.
Which practice should I adopt first? Pin bases by digest and deploy by digest. Reproducibility underpins every other guarantee, including rollback and provenance.
Is failing on all hadolint warnings too strict? Classify them. Promote the rules that matter to your org to errors and demote the noisy ones, then enforce that curated set.
Do small services need signing and provenance? Adopt them before the image crosses a trust boundary. Internal throwaway images can wait; anything a consumer verifies should be signed.
How do I stop humans pushing to prod repos? Restrict registry write permission to the CI identity and remove human write access, so the pipeline is the only publisher.
Should scanning block the build or just warn? Block on HIGH and CRITICAL that are actionable; warn on lower severities so the gate stays credible and unignored.
How often should I re-scan published images? On a schedule - daily or weekly - because new CVEs land after build. Pair it with SBOMs to target which images are affected.
Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Revisado por Chris St. John·Última atualização: 16 de jul. de 2026