Module 10
⭐⭐⭐ Difficile
~4h
🐳 Conteneurisation & CI/CD Automatisé
Conteneuriser une application NestJS et mettre en place un pipeline CI/CD complet avec GitHub Actions. De git push au déploiement automatique en production.
📁 Fichiers à créer
project/
├── Dockerfile ← Multi-stage (builder + runner Alpine)
├── .dockerignore
├── docker-compose.yml ← Dev : API + Postgres + Redis + pgAdmin
├── docker-compose.prod.yml ← Prod : uniquement API + DB + Redis
├── .env.example ← Template variables d'env documenté
├── .github/
│ └── workflows/
│ ├── ci.yml ← lint + test + coverage
│ └── deploy.yml ← build Docker + push GHCR + SSH deploy
└── src/
└── health/
└── health.controller.ts ← GET /health
✅ Checklist de déploiement
- Dockerfile multi-stage (image finale < 200MB)
- Utilisateur non-root dans le conteneur
- Variables d'env validées avec Joi au démarrage
- Health check endpoint (
/health) avec DB + Redis - CI GitHub Actions : lint → test avec services DB → coverage upload
- CD : build Docker → push GHCR → deploy SSH
- Migrations TypeORM avant démarrage (entrypoint script)
Bonus : Ajoutez un
docker-compose.monitoring.yml avec Prometheus + Grafana pour monitorer l'API. Exposez les métriques avec @willsoto/nestjs-prometheus.