๐Ÿ”ง DevOps

CI/CD

Continuous Integration / Continuous Delivery

The practice of automatically building, testing, and deploying code changes. Uses GitHub Actions, Jenkins, and CircleCI.

๐Ÿ“– Detailed Explanation

CI/CD (Continuous Integration / Continuous Delivery) is a software development practice that automatically builds, tests, and deploys code changes. In CI, developers integrate code frequently and detect problems early through automated tests, while CD makes tested code automatically ready for deployment.

In CI (Continuous Integration), builds and tests run automatically every time a developer pushes code. Integrating small changes frequently reduces merge conflicts and lets you find bugs quickly, lowering the cost of fixing them.

CD is interpreted in two ways: Continuous Delivery and Continuous Deployment. Delivery automates everything up to deployment readiness and requires manual approval for the actual deployment, while Deployment fully automates everything through production deployment. The choice depends on the organization's risk tolerance.

There are various tools such as GitHub Actions, Jenkins, GitLab CI, and CircleCI. A pipeline is generally composed of the following stages: build โ†’ unit test โ†’ integration test โ†’ security scan โ†’ artifact publishing โ†’ deployment.

๐Ÿ’ป Code Example

# .github/workflows/ci-cd.yml
name: CI/CD Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run test:coverage
      - uses: codecov/codecov-action@v4

  build-and-push:
    needs: test
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v5
        with:
          push: true
          tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  deploy:
    needs: build-and-push
    runs-on: ubuntu-latest
    environment: production
    steps:
      - run: |
          echo "Deploying version ${{ github.sha }} to production"
          # kubectl set image ๋˜๋Š” ArgoCD sync ๋“ฑ

๐Ÿ—ฃ๏ธ Examples of Practical Conversations

Senior: "Deployments went up from once a week to 10 times a day, yet incidents actually decreased. Thanks to the CI/CD pipeline, we deploy small changes frequently, so the scope of problems has become narrower."

Junior: "Isn't it hard to do CD if test coverage is low?"

Senior: "Right, so we set a coverage threshold and are raising it gradually. CD without tests is risky."

Interviewer: "What do you do when a test fails in a CI/CD pipeline?"

Candidate: "If the pipeline fails, the PR merge is blocked. We analyze the cause of the test failure and fix it, or if it is a flaky test, we isolate it and investigate it separately. The principle is to keep the main branch green at all times."

Take a mock interview on this topic โ†’ WIA SOOM AI Interview ยท Start for free

Reviewer: "Please don't put secrets directly into environment variables; fetch them from GitHub Secrets or Vault instead."

Developer: "Yes, I'll use the secrets context and also apply OIDC for AWS authentication."

โš ๏ธ Cautions

๐Ÿ”ฅ Real-World Incidents

GitLab 2017

6 hours of data lost due to unverified DB backups

Cause: After manually running rm -rf on the production DB, it was discovered that the backups were not working properly

Impact: 6 hours of project data permanently lost, GitLab.com down for 18 hours

Resolution: Recovered from the only surviving staging DB snapshot

Lesson: Added a backup verification test stage to the CI/CD pipeline and adopted Chaos Engineering

๐Ÿ“Ž View Details
Knight Capital 2012

$440 million lost in 45 minutes due to a deployment error

Cause: Old-version code was deployed to 1 of 8 servers (manual deployment, no automation)

Impact: $440M lost in 45 minutes from abnormal stock trading, putting the company at risk of bankruptcy

Resolution: Servers were shut down through manual intervention

Lesson: The importance of an automated CI/CD pipeline; securing rollback capability through Blue-Green deployment

๐Ÿ“ Comprehension Quiz

Q1. What is the core purpose of CI (Continuous Integration)?

Q2. What is the difference between Continuous Delivery and Continuous Deployment?

Q3. Why are flaky tests a problem in a CI/CD pipeline?

๐Ÿ“š Learn More

๐Ÿ’ฌ Questions & Contributions

If this page has any errors or you would like to add something, please let us know!