Continuous Integration & Continuous Delivery

Continuous Integration (CI)

Continuous Integration (CI) is the practice of integrating code changes into a shared codebase frequently and verifying those changes automatically.

In a typical development workflow, a developer creates a branch, makes some changes, and eventually creates a pull request or merges the branch into the main branch. CI adds an automated verification process around these changes.

For example, every time code is pushed to the repository, a CI pipeline might:

  1. Install dependencies.
  2. Run static checks, such as linters or formatters.
  3. Run automated unit tests.
  4. Build the application.
  5. Run automated functional tests.
  6. Report whether the pipeline passed or failed.

Notice that the steps and their order are not set in stone. They can vary from project to project, depending on the technology, testing strategy, and other project requirements.

The goal is to discover problems as soon as possible. For example, suppose a developer modifies a function and accidentally breaks an existing test. Without CI, the problem might not be discovered until someone manually runs the test suite or the application is deployed. With CI, the test suite runs automatically when the change is pushed:

Developer
    β”‚
    β”‚ git push
    β–Ό
Source Repository
    β”‚
    β–Ό
CI Pipeline
    β”‚
    β”œβ”€β”€ Install dependencies
    β”œβ”€β”€ Lint
    β”œβ”€β”€ Test
    └── Build
          β”‚
          β–Ό
       Pass / Fail

CI therefore provides a fast feedback loop between making a change and discovering whether that change is safe to integrate.

It is important to note that CI is more than simply running automated tests. The underlying practice is integrating changes frequently into a shared codebase and automatically verifying the resulting state.

Continuous Delivery (CD)

Continuous Delivery (CD) extends CI by automating the process of preparing software for release. Once the code has passed the CI checks, the application can be packaged and deployed to an environment such as a staging environment.

A simplified workflow might look like this:

Code Change
     β”‚
     β–Ό
   Build
     β”‚
     β–Ό
   Test
     β”‚
     β–Ό
Package Application
     β”‚
     β–Ό
Deploy to Staging
     β”‚
     β–Ό
Ready for Production

The important idea behind Continuous Delivery is that the software is kept in a releasable state.

Continuous Delivery does not necessarily mean that every successful change is automatically released to production. A production deployment may still require a manual approval or other release decision.

CI/CD

The distinction between CI and CD:

  • Continuous Integration β†’ continuously integrate and verify changes.
  • Continuous Delivery β†’ continuously prepare the software for release.

In practice, CI and CD are often combined into a single CI/CD pipeline.

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   Developer  β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
            git push
               β”‚
               β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚      CI      β”‚
        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β”‚ Lint         β”‚
        β”‚ Test         β”‚
        β”‚ Build        β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
            success
               β”‚
               β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚      CD      β”‚
        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β”‚   Package    β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
             deploy
               β”‚
               β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚  Staging  β”‚
         β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
               β”‚
         release decision
               β”‚
               β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚Production β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CI/CD and DevOps

CI/CD is closely associated with DevOps, but they are not the same thing:

  • DevOps is a broader approach to software development and delivery that aims to bring development and operations closer together. It emphasizes collaboration, automation, feedback, and shared responsibility throughout the software lifecycle.
  • CI/CD is a specific technical practice that helps put some of those principles into action.
                         DevOps
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚            β”‚            β”‚
          Culture      Practices   Technologies
             β”‚            β”‚            β”‚
       Collaboration   Automation   CI/CD
       Shared          Feedback     Containers
       Responsibility  IaC          Observability

Notice adopting a CI/CD pipeline alone does not mean that an organization has adopted DevOps. DevOps also involves areas such as team collaboration, infrastructure automation, monitoring and observability, incident response, and shared responsibility for running software in production.