xpeditis2.0/CI_CD_MULTI_ENV.md
David 6e3191b50e
All checks were successful
CI/CD Pipeline / Backend - Build, Test & Push (push) Successful in 5m45s
CI/CD Pipeline / Frontend - Build, Test & Push (push) Successful in 28m26s
CI/CD Pipeline / Integration Tests (push) Has been skipped
CI/CD Pipeline / Deployment Summary (push) Successful in 1s
CI/CD Pipeline / Deploy to Portainer (push) Successful in 14s
CI/CD Pipeline / Discord Notification (Failure) (push) Has been skipped
CI/CD Pipeline / Discord Notification (Success) (push) Successful in 1s
fix ci/cd and docker
2025-11-20 00:12:01 +01:00

6.2 KiB

🚀 CI/CD Multi-Environnements - Proposition

📊 Configuration Actuelle

Trigger :

on:
  push:
    branches:
      - preprod  # ← UNIQUEMENT preprod

Tags créés :

  • xpeditis-backend:preprod
  • xpeditis-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:main
xpeditis-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 latest automatiquement 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.3
  • xpeditis-backend:1.2
  • xpeditis-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:preprod
  • xpeditis-backend:preprod-a1b2c3d
  • xpeditis-backend:preprod-20251119-143022

Push sur main :

  • xpeditis-backend:main
  • xpeditis-backend:latest ← Production stable
  • xpeditis-backend:main-a1b2c3d
  • xpeditis-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) :

  1. Ajouter branche main au trigger CI/CD
  2. main → Production (avec tag latest)
  3. preprod → Pre-production (tag preprod)
  4. 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 tag preprod
  • Push sur main → Build et tag main + latest

Date : 2025-11-19 Impact : 🟡 Moyen - Permet déploiement multi-environnements Urgence : 🟢 Basse - Configuration actuelle fonctionne pour preprod