6.2 KiB
🚀 CI/CD Multi-Environnements - Proposition
📊 Configuration Actuelle
Trigger :
on:
push:
branches:
- preprod # ← UNIQUEMENT preprod
Tags créés :
xpeditis-backend:preprodxpeditis-frontend:preprod
Problème : Si vous créez d'autres branches (staging, production), elles ne déclenchent pas la CI/CD.
✅ Solution 1 : Multi-Environnements (Recommandé)
Configuration Proposée
on:
push:
branches:
- main # Production
- preprod # Pre-production
- staging # Staging (optionnel)
- develop # Development (optionnel)
Tags Créés Automatiquement
| Branche | Tags Créés | Usage |
|---|---|---|
main |
xpeditis-backend:mainxpeditis-backend:latest |
Production |
preprod |
xpeditis-backend:preprod |
Pre-production |
staging |
xpeditis-backend:staging |
Staging |
develop |
xpeditis-backend:develop |
Development |
Avantages
- ✅ Chaque environnement a son tag dédié
- ✅ Tag
latestautomatiquement créé pour production (main) - ✅ Workflow GitFlow supporté
- ✅ Pas besoin de modifier les tags manuellement
✅ Solution 2 : Ajouter Tag latest pour Preprod
Si vous voulez que preprod crée aussi un tag latest :
tags: |
type=ref,event=branch
type=raw,value=latest # ← Enlever le "enable={{is_default_branch}}"
Résultat :
- Push sur
preprod→ Tags :preprod+latest
Inconvénient : Le tag latest pointe toujours vers la dernière image buildée, peu importe la branche.
✅ Solution 3 : Tags Supplémentaires (Git SHA, Date)
Pour avoir plus de traçabilité :
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
Résultat pour preprod :
xpeditis-backend:preprod(tag principal)xpeditis-backend:preprod-a1b2c3d(tag avec commit SHA)
Avantages :
- ✅ Rollback facile vers un commit spécifique
- ✅ Traçabilité complète
✅ Solution 4 : Tags Sémantiques (Releases)
Pour les releases en production avec versioning :
on:
push:
branches:
- main
- preprod
tags:
- 'v*.*.*' # v1.0.0, v1.2.3, etc.
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
Résultat pour tag v1.2.3 :
xpeditis-backend:1.2.3xpeditis-backend:1.2xpeditis-backend:latest
📋 Recommandation pour Xpeditis
Configuration Proposée (Production-Ready)
name: CI/CD Pipeline
on:
push:
branches:
- main # Production
- preprod # Pre-production
pull_request:
branches:
- main
- preprod
env:
REGISTRY: rg.fr-par.scw.cloud/weworkstudio
NODE_VERSION: '20'
jobs:
backend:
name: Backend - Build, Test & Push
runs-on: ubuntu-latest
# ...
steps:
# ... (setup steps)
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/xpeditis-backend
tags: |
# Tag avec le nom de la branche
type=ref,event=branch
# Tag "latest" seulement pour main (production)
type=raw,value=latest,enable={{is_default_branch}}
# Tag avec le commit SHA (pour rollback)
type=sha,prefix={{branch}}-,format=short
# Tag avec la date (optionnel)
type=raw,value={{branch}}-{{date 'YYYYMMDD-HHmmss'}}
- name: Build and push Backend Docker image
uses: docker/build-push-action@v5
with:
context: ./apps/backend
file: ./apps/backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
Tags Créés
Push sur preprod :
xpeditis-backend:preprodxpeditis-backend:preprod-a1b2c3dxpeditis-backend:preprod-20251119-143022
Push sur main :
xpeditis-backend:mainxpeditis-backend:latest← Production stablexpeditis-backend:main-a1b2c3dxpeditis-backend:main-20251119-143022
🎯 Configuration Minimale (Actuelle + Latest)
Si vous voulez juste ajouter le tag latest pour preprod :
tags: |
type=ref,event=branch
type=raw,value=latest
Résultat :
- Push sur
preprod→ Tags :preprod+latest
📊 Tableau Comparatif
| Solution | Tags pour Preprod | Tags pour Main | Rollback | Complexité |
|---|---|---|---|---|
| Actuelle | preprod |
❌ Pas de CI/CD | ❌ | ⚡ Simple |
| Solution 1 | preprod |
main, latest |
❌ | ⚡ Simple |
| Solution 2 | preprod, latest |
❌ | ❌ | ⚡ Simple |
| Solution 3 | preprod, preprod-SHA |
main, latest, main-SHA |
✅ | 🔧 Moyen |
| Solution 4 | preprod, tags sémantiques |
main, 1.2.3, latest |
✅ | 🔧 Avancé |
✅ Ma Recommandation
Pour Xpeditis, utilisez Solution 1 (Multi-environnements) :
- Ajouter branche
mainau trigger CI/CD main→ Production (avec taglatest)preprod→ Pre-production (tagpreprod)- Optionnel : Ajouter SHA tags pour rollback
Workflow Git :
develop → preprod → main
↓ ↓ ↓
staging testing production
🔧 Fichier à Modifier
Fichier : .github/workflows/ci.yml
Modification minimale (lignes 3-6) :
on:
push:
branches:
- main # ← AJOUTER pour production
- preprod # ← Garder pour pre-production
Résultat :
- Push sur
preprod→ Build et tagpreprod - Push sur
main→ Build et tagmain+latest
Date : 2025-11-19 Impact : 🟡 Moyen - Permet déploiement multi-environnements Urgence : 🟢 Basse - Configuration actuelle fonctionne pour preprod