CI/CD in a nutshell

Continuos Integration

Integration means adding new code to the shared codebase

What does it mean to do that continously?

Version Control

  • The code needs to be in version control.

These days that means git

  • Roll back when something is wrong
  • Work independently on a shared codebase
  • A record of who has done what

Test

  • All tests are run automatically
  • New code can't break tests
  • You still need to write the tests! 😉

Lint

It is common to have a linter setup - a utility that checks codestyle, formatting etc.

This ensures that the code is formatted consistently across multiple developers

Review

After tests are green and linters have passed, another developer gives a code review.

Reviews are focused on logic and implementation

Build

Take the approved code and package it into an artifact, pushing it to some artifact storage

This usually means a Docker Image, though it could be a binary, a JAR or a Python package

Continous Integration

Continous Integration has three goals

  • Quick feedback
  • Rapid integration of new code into the main codebase
  • ...while ensuring high quality through automatic testing and linting

Continous Delivery

Continous Delivery is making sure that code is always in a releasable state.

The CD part of the pipeline is in charge of taking the artifact and deploying to an environment

Quick Aside - Definitions

Artifact

The packaged code that is the result of our CI step

Deploying

Releasing the artifact into a given environment

Environment

A set of services and their configuration. Isolated from each other, so they don’t share resources

Configuration

A setting that changes how the artifact operates.

In one environment, the GDPR masking setting might be turned on and another might have it turned off.

Same artifact - different behaviour depending on configuration

Read more at https://12factor.net/

Deployment vs Delivery

  • Continous Deployment is having code that's always shippable
  • Continous Delivery is always shipping code

Most implement Continous Deployment - a pipeline that is able to deploy a given artifact to a given environment

Deploying

What deploying means is different from project to project

  • Upload a binary to a homepage
  • Publish a package to a package index
  • Copy code to a webserver
  • Create a Kubernetes release

CICD Services

There are many vendors in this space

Jenkins

  • Is open source
  • Written in Java
  • Tons of plugins
  • Groovy syntax

Gitlab CI/CD

  • Pioneered Repo -> CICD integration
  • Tied to Gitlab
  • YAML syntax

Github Actions

  • The new kid on the block
  • Uses Node.js / Docker containers
  • Tied to Github
  • YAML syntax

Bamboo

  • Integrated with Bitbucket
  • Written in Java
  • Has a limited subset in YAML

Git workflow

To best use CI/CD, we often combine it with a standardized git workflow.

This helps write CI/CD pipelines that match the intentions when using git

Git flow

Each type of branch has a meaning

Main branch

Is always in a releasable state - should only be merged into when ready to release

Develop

Contains the newest features being worked on - the basis for new features

Feature branch

When starting work on a new feature we create a feature branch starting from develop.

This is the main unit of work - every bit of new code starts as a feature branch and is merged back into develop when done, through a Pull Request.

When the feature branch is merged, it should be deleted

Release

When we are ready to release, we create a release branch and run through the release checklist.

for example:

  • Update versions
  • Update any version references
  • Merge into master and develop.
  • Tag master with the version number and push tags

CI/CD is often set up to run deployment if it’s a tagged commit

Resources