Files
EM2_ERP/em2rp/deploy_backend.ps1

110 lines
3.8 KiB
PowerShell

# Script de déploiement backend sécurisé
# Usage: .\deploy_backend.ps1 [test|prod]
param(
[Parameter(Mandatory=$true)]
[ValidateSet("test", "prod")]
[string]$mode
)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Migration Backend - Déploiement" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Mode TEST : Lancer les émulateurs
if ($mode -eq "test") {
Write-Host "Mode: TEST (émulateurs)" -ForegroundColor Yellow
Write-Host "Lancement des émulateurs Firebase..." -ForegroundColor Yellow
Write-Host ""
firebase emulators:start
exit
}
# Mode PROD : Déploiement en production
Write-Host "Mode: PRODUCTION" -ForegroundColor Green
Write-Host ""
# Confirmation
Write-Host "ATTENTION: Vous allez déployer en PRODUCTION !" -ForegroundColor Red
$confirmation = Read-Host "Tapez 'OUI' pour confirmer"
if ($confirmation -ne "OUI") {
Write-Host "Déploiement annulé." -ForegroundColor Yellow
exit 0
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Étape 1/4 : Vérification du code" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
# Vérifier que ApiConfig est en mode production
$apiConfigPath = "lib\config\api_config.dart"
$apiConfigContent = Get-Content $apiConfigPath -Raw
if ($apiConfigContent -match "isDevelopment = true") {
Write-Host "ERREUR: ApiConfig est en mode développement !" -ForegroundColor Red
Write-Host "Veuillez mettre 'isDevelopment = false' dans $apiConfigPath" -ForegroundColor Yellow
exit 1
}
Write-Host "✓ ApiConfig en mode production" -ForegroundColor Green
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Étape 2/4 : Installation dépendances" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Push-Location functions
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "ERREUR: Installation des dépendances échouée" -ForegroundColor Red
Pop-Location
exit 1
}
Pop-Location
Write-Host "✓ Dépendances installées" -ForegroundColor Green
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Étape 3/4 : Déploiement Cloud Functions" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
firebase deploy --only functions
if ($LASTEXITCODE -ne 0) {
Write-Host "ERREUR: Déploiement des functions échoué" -ForegroundColor Red
exit 1
}
Write-Host "✓ Cloud Functions déployées" -ForegroundColor Green
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Étape 4/4 : Déploiement Firestore Rules" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
firebase deploy --only firestore:rules
if ($LASTEXITCODE -ne 0) {
Write-Host "ERREUR: Déploiement des règles échoué" -ForegroundColor Red
exit 1
}
Write-Host "✓ Firestore Rules déployées" -ForegroundColor Green
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " DÉPLOIEMENT RÉUSSI !" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "Prochaines étapes :" -ForegroundColor Yellow
Write-Host "1. Tester les opérations CRUD (voir TESTING_PLAN.md)" -ForegroundColor Gray
Write-Host "2. Surveiller les logs: firebase functions:log" -ForegroundColor Gray
Write-Host "3. Vérifier les permissions utilisateurs" -ForegroundColor Gray
Write-Host ""
Write-Host "Console Firebase:" -ForegroundColor Cyan
Write-Host "https://console.firebase.google.com/project/em2rp-951dc/functions" -ForegroundColor Blue
Write-Host ""