Day 11: Introduction to CI/CD
1 min read
CI/CD is about streamlining software delivery: integrate often, test automatically, and ship in small, safe steps.
This builds on the overview in the Day 1 post.
CI vs CD
- Continuous Integration (CI): merge code changes from multiple developers into a shared repository (e.g., Git) as frequently as possible. Automated builds and tests run on each integration to catch errors and conflicts early.
- Continuous Deployment (CD): automatically deploy tested, verified code to production so new features and bug fixes reach users quickly and reliably.
Benefits of CI/CD
- Faster feedback: automated builds and tests flag broken changes within minutes.
- Improved collaboration: frequent integration keeps divergences small and conflicts rare.
- Higher code quality: regression suites run on every change instead of before a big release.
- Faster delivery: automation removes manual handoffs between build, test, and deploy.
CI/CD tool options
Jenkins
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/username/repo.git'
}
}
stage('Build') {
steps {
sh 'pip install poetry'
sh 'poetry install'
}
}
stage('Test') {
steps {
sh 'poetry run pytest'
}
}
stage('Deliver') {
steps {
echo 'Codebase approved, deliver to production environment'
}
}
stage('Deploy') {
steps {
echo 'Deploy changes to production'
// Add your deployment steps here
}
}
}
}
GitHub Actions
name: CI/CD
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build
run: |
pip install poetry
poetry install
- name: Test
run: |
poetry run pytest
- name: Deliver
run: |
echo 'Codebase approved, deliver to production environment'
- name: Deploy
run: |
echo 'Deploy changes to production'
# Add your deployment steps here
CircleCI
TIP — Visual Config Editor
CircleCI has a Visual Config Editor for visualizing pipelines.
version: 2.1
jobs:
build:
docker:
- image: cimg/python:3.11
steps:
- checkout
- run:
name: Build
command: |
pip install poetry
poetry install
- run:
name: Test
command: |
poetry run pytest
- run:
name: Deliver
command: |
echo 'Codebase approved, deliver to production environment'
- run:
name: Deploy
command: |
echo 'Deploy changes to production'
# Add your deployment steps here
workflows:
version: 2
build-deploy:
jobs:
- build
Travis CI
language: python
python:
- "3.11"
install:
- pip install poetry
- poetry install
script:
- poetry run pytest
after_success:
- echo 'Codebase approved, deliver to production environment'
- echo 'Deploy changes to production'
# Add your deployment steps here
Further reading: