CI/CD: Continuous Integration and Deployment
Table of Contents
1. Background
CI/CD automates the software delivery process:
- Continuous Integration: Automatically build and test on every commit
- Continuous Delivery: Automated deployment to staging
- Continuous Deployment: Automated deployment to production
2. Providers
| Provider | Type | Key Features |
|---|---|---|
| GitHub Actions | Cloud | Native GitHub integration, YAML |
| GitLab CI | Cloud/OSS | Built into GitLab, Auto DevOps |
| CircleCI | Cloud | Docker-first, parallelism |
| Jenkins | OSS | Extensible, self-hosted |
| AWS CodeBuild | Cloud | AWS integration, pay-per-build |
| Buildkite | Hybrid | Self-hosted agents, cloud dashboard |
3. GitHub Actions Example
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run tests
run: pytest --cov
- name: Lint
run: ruff check .
4. GitLab CI Example
# .gitlab-ci.yml
stages:
- test
- build
- deploy
test:
stage: test
image: python:3.12
script:
- pip install -e ".[dev]"
- pytest --cov
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker build -t myapp .
deploy:
stage: deploy
only:
- main
script:
- ./deploy.sh
5. Best Practices
- Keep pipelines fast (< 10 minutes)
- Cache dependencies between runs
- Run tests in parallel when possible
- Use matrix builds for multiple versions
- Separate build and deploy stages
- Use environment-specific secrets
6. Key Features
| Feature | Description |
|---|---|
| Caching | Speed up builds with dependency caching |
| Parallelism | Run jobs concurrently |
| Matrix builds | Test across multiple environments |
| Secrets | Secure credential storage |
| Artifacts | Share files between jobs |
| Environments | Deploy to staging/production |