Fondamenti della pipeline CI/CD
L'integrazione continua e la distribuzione continua automatizzano il processo di distribuzione del software.
Fasi della pipeline
┌─────────┐ ┌───────┐ ┌────────┐ ┌────────┐
│ Code │ → │ Build │ → │ Test │ → │ Deploy │
└─────────┘ └───────┘ └────────┘ └────────┘
│ │ │ │
commit compile unit staging
push bundle integration prod
Esempio: azioni GitHub
name: CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Lint
run: ruff check .
- name: Type check
run: mypy src/
- name: Test
run: pytest --cov
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy
run: ./scripts/deploy.sh
Principi chiave
- Feedback fisso: i test dovrebbero essere eseguiti rapidamente
- Fail early: rileva i problemi prima della fusione
- Build riproducibili: stesso input = stesso output
- Distribuzione incrementale: distribuisce spesso piccole modifiche
Strategia ambientale
| Ambiente | Scopo | Distribuisci trigger |
|---|---|---|
| Sviluppo | Prova | Spingi a dev |
| Messa in scena | Convalida pre-produzione | Unisci a main |
| Produzione | Sito live | Approvazione manuale |