惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
V
V2EX
Vercel News
Vercel News
U
Unit 42
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
J
Java Code Geeks
WordPress大学
WordPress大学
罗磊的独立博客
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
CI/CD Build Systems for Cloud-Native Applications
Safdar Wahid · 2026-04-23 · via DEV Community

TLDR ;

  • Multi-stage Docker builds with BuildKit caching reduce image sizes by 80% and build times by 60%
  • Remote build caching shares artifacts across developers and CI, eliminating redundant work
  • Parallel pipeline execution runs independent stages simultaneously for faster feedback
  • SBOM generation and container signing are now required for European regulated industries

Build systems are the foundation of every CI/CD pipeline. They transform source code into deployable artifacts: container images, binaries, or bundled assets. Slow builds directly impact developer productivity and deployment frequency.

Team Type Build Time Impact
Elite-performing teams ( DORA State of DevOps Report 2024) Under 10 minutes Enables rapid feedback loops for multiple daily deployments
Many teams 20-30 minutes Tolerated because optimization feels complex

The reality is simpler. Three techniques cover most optimization: multi-stage Docker builds with layer caching, remote build caches shared across CI infrastructure, and parallel pipeline execution.

For European B2B organizations building cloud-native applications, build systems also need to produce signed artifacts with Software Bill of Materials (SBOM) documentation to satisfy supply chain security requirements. This article covers practical build optimization and security patterns for Kubernetes-targeted applications.

Multi-Stage Docker Builds

[Source Code] --> [Builder Stage] --> [Runtime Stage] --> [Minimal Image]
                     |                                        |
                [Dependencies]                          [Binary Only]
                [Build Tools]                           [No Shell]
                [Test Frameworks]                       [Non-root User]

Enter fullscreen mode Exit fullscreen mode

Multi-stage builds separate build-time dependencies from runtime artifacts. The builder stage includes compilers, package managers, and test tools. The runtime stage contains only the final binary and its runtime dependencies.

Docker

# Builder stage
FROM golang:1.21 AS builder
WORKDIR /app
go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
    go mod download
. .
RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o /app/server

# Runtime stage
FROM gcr.io/distroless/static-debian11
--from=builder /app/server /usr/local/bin/
USER nonroot:nonroot
ENTRYPOINT ["/usr/local/bin/server"]

Enter fullscreen mode Exit fullscreen mode

This produces a minimal image with just the Go binary. According to Google's distroless documentation, distroless images contain no shell, no package manager, and no utilities that attackers could exploit. The resulting image is typically under 20MB compared to 800MB+ for a full Ubuntu-based image.

Multi-stage Docker build: builder stage with compiler, runtime stage with distroless binary only. Final image under 20MB.

BuildKit cache mounts (--mount=type=cache) persist package manager caches between builds without bloating the final image. Dependency downloads happen once and are reused on subsequent builds.

For Node.js applications, the same pattern applies:

Docker

FROM node:20-alpine AS builder
WORKDIR /app
package*.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm install --frozen-lockfile
. .
RUN pnpm run build

FROM node:20-alpine
WORKDIR /app
--from=builder /app/dist ./dist
--from=builder /app/node_modules ./node_modules
USER node
CMD ["node", "dist/index.js"]

Enter fullscreen mode Exit fullscreen mode

Build Caching Strategies

Caching is the single most impactful build optimization. According to Docker's BuildKit documentation, proper layer ordering and caching can reduce build times by 60-80% on subsequent runs.

Layer ordering matters. Place instructions that change rarely (dependency installation) before instructions that change often (source code copy):

Docker

# Dependencies first (changes rarely)
package.json package-lock.json ./
RUN npm ci

# Source code second (changes often)
. .
RUN npm run build

Enter fullscreen mode Exit fullscreen mode

Remote registry caching shares build cache across your team and CI:

Bash

docker buildx build \
  --cache-from type=registry,ref=registry.example.com/cache \
  --cache-to type=registry,ref=registry.example.com/cache \
  -t registry.example.com/app:v1.2.3 .

Enter fullscreen mode Exit fullscreen mode

First builds populate the cache. Subsequent builds pull cached layers from the registry. This eliminates redundant dependency downloads across CI runners and developer machines.

Monorepo build tools like Turborepo and Nx provide content-addressable caching:

Bash

turbo run build --api="https://cache.example.com" --token="$CACHE_TOKEN"

Enter fullscreen mode Exit fullscreen mode

Changed packages rebuild; unchanged packages use cached outputs. For large monorepos, this transforms 20-minute builds into 2-minute incremental builds.


Remote caching + monorepo tooling = 20-min builds → 2-min builds.

The techniques above work. But configuring remote caches across CI runners and setting up monorepo tooling requires expertise.

We help you:

  • Set up remote registry caching – Share build layers across your team and CI
  • Implement Turborepo/Nx – Content-addressable caching for monorepos
  • Optimize layer ordering – Dependencies first, code last
  • Reduce build times by 60-80% – Measurable results

Get Build Optimization Expertise →


Parallel Pipeline Execution

Run independent stages simultaneously instead of sequentially. Build, unit tests, and linting have no dependencies on each other and should run in parallel.

YAML

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build container
        run: docker build -t app:${{ github.sha }} .

  unit-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run tests
        run: npm test

  security-scan:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Scan image
        run: trivy image app:${{ github.sha }}

  integration-tests:
    needs: build
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
    steps:
      - name: Run integration tests
        run: ./run-integration-tests.sh

Enter fullscreen mode Exit fullscreen mode

Build and unit-tests run in parallel. Security scanning and integration tests run after build completes but parallel to each other. According to GitHub Actions documentation, this job dependency model is the standard approach for optimizing workflow execution time.

CI/CD parallel pipeline: build, unit tests, linting, security scan, integration tests run concurrently. Total time = max parallel + sequential.

Build machine sizing impacts cost more than most teams realize

  • A machine that costs 4x more per hour but finishes in one-quarter the time costs the same
  • Factor in developer wait time → faster machines win decisively
  • Most teams underestimate the impact of machine sizing on total cost

Alternative Container Builders

Docker is not the only option for building container images.

Builder Best For Requires Docker Daemon
Docker BuildKit General purpose, widest compatibility Yes
Kaniko Kubernetes-native builds, no daemon needed No
Buildah Scriptable, fine-grained control No
ko Go applications, no Dockerfile needed No
Jib Java applications, no Dockerfile needed No

Kaniko runs inside Kubernetes pods, making it ideal for GitOps-driven build pipelines:

YAML

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: kaniko
      image: gcr.io/kaniko-project/executor:latest
      args:
        - "--dockerfile=Dockerfile"
        - "--context=git://github.com/example/app"
        - "--destination=registry.example.com/app:v1.2.3"
        - "--cache=true"

Enter fullscreen mode Exit fullscreen mode

Multi-architecture builds produce images for both amd64 and arm64 platforms:

Bash

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.com/app:v1.2.3 \
  --push .

Enter fullscreen mode Exit fullscreen mode

Build Security and Supply Chain

Build systems are high-value attack targets. According to Sonatype's State of the Software Supply Chain 2024, supply chain attacks continue to accelerate, making build-time security controls a necessity.

Dependency scanning fails builds on high-severity vulnerabilities:

YAML

- name: Scan dependencies
  run: |
    npm audit --audit-level=high
    snyk test --severity-threshold=high

Enter fullscreen mode Exit fullscreen mode

SBOM generation creates an inventory of all software components:

Bash

syft packages registry.example.com/app:v1.2.3 -o spdx-json > sbom.json
grype sbom.json

Enter fullscreen mode Exit fullscreen mode

Container signing with Sigstore Cosign proves images have not been tampered with:

Bash

cosign sign --yes registry.example.com/app:v1.2.3

Enter fullscreen mode Exit fullscreen mode

For European regulated industries, SBOM documentation and artifact signing satisfy supply chain transparency requirements. Integrate these steps into your pipeline security workflow and enforce signature verification during progressive delivery rollouts.

Optimization Techniques Summary

Technique Impact Implementation
Multi-stage Docker builds Minimal image size (20MB vs 800MB+) Separate builder + runtime stages
BuildKit cache mounts Reduce build times 60-80% --mount=type=cache
Remote registry caching Share cache across team/CI --cache-from / --cache-to
Layer ordering Maximize cache reuse Dependencies first, code last
Parallel pipeline execution Reduce total workflow time Independent jobs run simultaneously
Monorepo tooling 20-min → 2-min incremental builds Turborepo or Nx
Alternative builders Kubernetes-native, no Docker daemon Kaniko, Buildah, ko, Jib

Conclusion

Fast, secure builds are the foundation of a productive CI/CD pipeline. Start with multi-stage Docker builds and BuildKit caching to reduce image sizes and build times. Add remote registry caching to share artifacts across your team. Structure pipeline jobs for parallel execution to minimize total workflow duration.

Layer in supply chain security: dependency scanning, SBOM generation, and container signing. These controls integrate with multi-environment deployment and GitOps workflows to maintain security from build through production.


Frequently Asked Questions

How do I reduce Docker build times?

Three techniques have the most impact: order Dockerfile instructions from least to most frequently changed for better layer caching, use BuildKit cache mounts to persist package manager caches, and implement remote registry caching to share build layers across CI runners.

Should I use distroless images in production?

Distroless Images - Pros and Cons

Aspect Assessment
Attack surface Reduced (no shell, no package manager)
Image size Much smaller
Debugging Requires remote debugging tools (no shell)
Recommendation Yes for most workloads. Use debug-tagged distroless images in non-production environments

What is an SBOM and when do I need one?

SBOM Definition and Requirements:

  • SBOM = Software Bill of Materials - a machine-readable inventory of all software components in your artifact
  • Required for: Government contracts and regulated industries
  • Tools: Generate with Syft during builds; scan with Grype for vulnerabilities