Kahibaro
Discord Login Register

6.2.1 CI/CD principles

What CI/CD Solves

Traditional software delivery often suffers from:

CI/CD (Continuous Integration / Continuous Delivery / Continuous Deployment) addresses these by standardizing and automating how changes move from developer machines to production, typically using Linux servers as runners, build agents, or deployment targets.

Key Concepts and Terminology

Continuous Integration (CI)

Continuous Integration is about frequently merging code changes into a shared main branch and automatically validating them.

Core ideas:

Goals:

Continuous Delivery (CD)

Continuous Delivery extends CI: after code is built and tested, it is always in a releasable state, and a deployment to production is:

The final push to production is often triggered manually (e.g., pressing a button, approving a job).

Key idea: release any version at any time with low risk and low effort.

Continuous Deployment

Continuous Deployment goes a step further than Continuous Delivery:

Useful when:

Pipeline

A CI/CD pipeline is the automated path that code changes follow:

  1. Code is pushed or merged
  2. Pipeline is triggered
  3. A series of stages (e.g., build → test → package → deploy) run
  4. Each stage runs one or more jobs (e.g., unit tests, integration tests, code quality checks)
  5. If all stages succeed, the result is an artifact or a deployment

On Linux, these jobs usually run in containers or on Linux build agents.

Artifacts

Artifacts are build outputs that move between stages:

Principle: build once, use many times (test, then deploy the same artifact).

CI/CD Lifecycle at a High Level

Consider a typical lifecycle for a code change:

  1. Commit & Push
    • Developer works locally
    • Pushes to a feature branch
  2. CI Trigger
    • Push or merge request triggers CI job(s) on a Linux runner
  3. Build Stage
    • Fetch dependencies
    • Compile/build application
    • Produce build artifacts
  4. Test Stage
    • Run unit tests
    • Run basic integration tests
    • Optionally run static analysis, style checks, security scans
  5. Package Stage
    • Bundle application into:
      • A container image
      • A Linux package
      • A signed binary or archive
  6. Deploy to Non‑Production
    • Automatically deploy to a test or staging environment
    • Run further checks (e2e tests, performance smoke tests)
  7. Production Deployment
    • Continuous Delivery: manual approval/trigger
    • Continuous Deployment: automatic if previous stages passed
  8. Post‑Deployment Verification
    • Health checks, logs, metrics
    • Rollback if needed

Linux is typically the underlying OS at every step: runners, build environments, test servers, and production hosts.

Core Principles of Effective CI/CD

1. Small, Frequent Changes

2. Fast Feedback

3. Single Source of Truth and Declarative Config

Principle: everything that can be automated (build, test, deployment logic) should live in declarative configuration, not be manual or ad‑hoc scripts run from someone’s laptop.

4. Build Once, Promote Many Times

Avoid rebuilding code at each stage:

Why:

On Linux, this often means:

5. Environments and Promotion

An environment is a deploy target (e.g., test, staging, production).

Key ideas:

Linux hosts may differ per environment, but the deployment process should be consistent and automated.

6. Idempotent and Repeatable Deployments

A deployment process is idempotent if running it multiple times leads to the same result, without harmful side effects.

Principles:

CI/CD tools and configuration management (covered elsewhere) work together to enforce this.

7. Test Automation as a Gate

CI/CD relies heavily on automated tests:

Common test gating patterns:

8. Security and Compliance in the Pipeline

Security checks are integrated into CI/CD:

Principles:

9. Observability and Traceability

You need visibility into:

CI/CD supports this with:

In Linux environments, log files, systemd logs, and monitoring agents complement CI/CD system logs for full traceability.

10. Rollback and Failure Handling

CI/CD design assumes things will fail and prepares for it:

Principle: deployment should be reversible and quick.

Common CI/CD Workflow Patterns

Branching and Integration Patterns

CI/CD supports either style; Linux runners simply execute the jobs defined for each branch.

Build and Test Strategies

Typical pipeline stages:

  1. lint – fast static checks (e.g., formatting, style)
  2. unit-test – quick tests focused on small pieces of code
  3. integration-test – require services (databases, APIs), often in containers on Linux
  4. e2e or system tests – more expensive, may run only on specific branches

Principle: cheapest checks first, fail early.

Deployment Strategies

Different strategies manage risk when deploying to Linux servers:

CI/CD orchestrates these strategies, while Linux tools (systemd, orchestrators, load balancers) execute them.

CI/CD and Linux: Practical Considerations

Although tool‑specific details are covered separately, some Linux‑specific aspects are important to the principles:

Designing a Simple CI/CD Pipeline (Conceptually)

To tie the principles together, consider this conceptual minimal pipeline for a web app deployed on Linux:

  1. Trigger: push to main or a merge request.
  2. Build:
    • Run on a Linux runner
    • Install dependencies
    • Build the app
    • Create a container image
  3. Test:
    • Run unit tests inside the same environment
    • If any test fails → pipeline fails → no deployment
  4. Package & Push:
    • Push container image to a registry
    • Tag image with commit hash and maybe a semantic version
  5. Deploy to Staging:
    • SSH or orchestrated deployment to Linux staging servers
    • Run smoke tests
  6. Approval for Production (Continuous Delivery) or automatic deployment (Continuous Deployment):
    • Apply deployment strategy (rolling/blue‑green)
    • Monitor health and metrics
  7. Post‑Deployment:
    • Mark the deployment as successful
    • If issues arise, trigger rollback using previous image/tag

This pipeline exemplifies CI/CD principles: small changes, automated verification, reproducible builds, controlled promotion, and safe rollback — all running on Linux infrastructure.

Summary of CI/CD Principles

These principles form the conceptual foundation; later chapters focus on implementing them with specific CI/CD tools and Linux‑centric workflows.

Views: 66

Comments

Please login to add a comment.

Don't have an account? Register now!