Overview
CI/CD stands for Continuous Integration and Continuous Deployment (or Delivery). It is a set of practices and tools that automate the process of integrating code changes from multiple contributors into a shared repository and deploying them to production.
Core Concepts
- Continuous Integration (CI):
- Automated Build: Every commit triggers a build process.
- Automated Testing: Running the unit, integration, and E2E tests on every commit.
- Goal: Detect integration errors as early as possible.
- Continuous Delivery (CD):
- Automated Release: The code is always in a deployable state, but the final push to production may be manual.
- Continuous Deployment (CD):
- Automated Production Push: Every change that passes the CI pipeline is automatically deployed to production without human intervention.
- Deployment Strategies:
- Blue-Green Deployment: Running two identical production environments. You switch traffic to the new version (Green) only after it’s verified.
- Canary Deployment: Rolling out the change to a small subset of users first to monitor for errors.
- Rolling Update: Gradually replacing old versions of the service with new ones.
Code Examples
# Conceptual GitHub Actions workflow
name: CI Pipeline
on: [push]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm test
- run: npm run lint
Use Cases
- Faster Time-to-Market: Reducing the time between a feature being conceptualized and being available to users.
- Improved Stability: Automation eliminates human error during deployment.
- Small, Frequent Releases: Instead of one giant “release day” every 6 months, you deploy small changes daily.
Gotchas
- Pipeline Flakiness: When a test fails intermittently (flaky tests), developers stop trusting the CI pipeline.
- Complexity: Managing complex deployment pipelines for microservices can be a significant operational burden.
- Dependency Hell: Ensuring that the CI environment perfectly matches the production environment.
