From 23579533b204531b9829752a5526506e24445ffe Mon Sep 17 00:00:00 2001 From: dahoud Date: Sat, 10 Jan 2026 16:28:33 +0000 Subject: [PATCH] feat(build): Scripts et configuration pour build production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajout de scripts PowerShell et Bash pour build automatisé - Configuration pour connexion à l'API production (api.lions.dev/afterwork) - Documentation complète dans BUILD_CONFIG.md - Fichier .env.example pour référence - Support pour APK, App Bundle, iOS et Web --- .env.example | 43 +++++ BUILD_CONFIG.md | 293 +++++++++++++++++++++++++++++++++++ scripts/build_production.ps1 | 82 ++++++++++ scripts/build_production.sh | 99 ++++++++++++ 4 files changed, 517 insertions(+) create mode 100644 .env.example create mode 100644 BUILD_CONFIG.md create mode 100644 scripts/build_production.ps1 create mode 100644 scripts/build_production.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9451298 --- /dev/null +++ b/.env.example @@ -0,0 +1,43 @@ +# Configuration de l'environnement AfterWork +# Copiez ce fichier en .env et personnalisez les valeurs + +# ==================================================================== +# API CONFIGURATION +# ==================================================================== + +# URL de base de l'API backend +# Development: http://192.168.1.145:8080 +# Production: https://api.lions.dev/afterwork +API_BASE_URL=https://api.lions.dev/afterwork + +# Timeout pour les requêtes réseau (en secondes) +NETWORK_TIMEOUT=30 + +# ==================================================================== +# ENVIRONMENT +# ==================================================================== + +# Environnement d'exécution: development, staging, production +ENVIRONMENT=production + +# Mode debug (true/false) +DEBUG_MODE=false + +# ==================================================================== +# SERVICES EXTERNES (Optionnel) +# ==================================================================== + +# Clé API Google Maps (si nécessaire) +# GOOGLE_MAPS_API_KEY=votre_cle_api_google_maps + +# ==================================================================== +# NOTES +# ==================================================================== + +# Pour utiliser ces variables lors du build: +# flutter build apk --dart-define-from-file=.env + +# Ou spécifier individuellement: +# flutter build apk \ +# --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ +# --dart-define=ENVIRONMENT=production diff --git a/BUILD_CONFIG.md b/BUILD_CONFIG.md new file mode 100644 index 0000000..4b4efc9 --- /dev/null +++ b/BUILD_CONFIG.md @@ -0,0 +1,293 @@ +# Configuration de Build AfterWork + +Ce document explique comment configurer et builder l'application AfterWork pour différents environnements. + +## 📋 Table des matières + +- [Environnements](#environnements) +- [Configuration Rapide](#configuration-rapide) +- [Scripts de Build](#scripts-de-build) +- [Build Manuel](#build-manuel) +- [Variables d'Environnement](#variables-denvironnement) + +--- + +## 🌍 Environnements + +### Development (par défaut) +- **API URL** : `http://192.168.1.145:8080` +- **Usage** : Développement local avec le backend sur le réseau local +- **Debug** : Activé + +### Production +- **API URL** : `https://api.lions.dev/afterwork` +- **Usage** : Déploiement en production +- **Debug** : Désactivé + +--- + +## ⚡ Configuration Rapide + +### Windows (PowerShell) + +```powershell +# Build APK de production +.\scripts\build_production.ps1 + +# Build avec nettoyage préalable +.\scripts\build_production.ps1 -Clean + +# Build pour d'autres plateformes +.\scripts\build_production.ps1 -Platform appbundle +.\scripts\build_production.ps1 -Platform web +``` + +### Linux/Mac (Bash) + +```bash +# Rendre le script exécutable +chmod +x scripts/build_production.sh + +# Build APK de production +./scripts/build_production.sh + +# Build avec nettoyage préalable +./scripts/build_production.sh apk --clean + +# Build pour d'autres plateformes +./scripts/build_production.sh appbundle +./scripts/build_production.sh web +``` + +--- + +## 🔨 Scripts de Build + +### `build_production.ps1` / `build_production.sh` + +Scripts automatisés pour builder l'application en production. + +**Paramètres** : +- `Platform` : `apk` (défaut), `appbundle`, `ios`, `web` +- `--clean` / `-Clean` : Nettoie le projet avant le build + +**Configuration automatique** : +- ✅ API_BASE_URL = `https://api.lions.dev/afterwork` +- ✅ ENVIRONMENT = `production` +- ✅ Mode release activé + +**Sortie** : +- APK : `build/app/outputs/flutter-apk/app-release.apk` +- App Bundle : `build/app/outputs/bundle/release/app-release.aab` +- iOS : `build/ios/ipa/` +- Web : `build/web/` + +--- + +## 🛠️ Build Manuel + +Si vous préférez builder manuellement sans les scripts : + +### Android APK + +```bash +flutter build apk \ + --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ + --dart-define=ENVIRONMENT=production \ + --release +``` + +### Android App Bundle (pour Google Play) + +```bash +flutter build appbundle \ + --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ + --dart-define=ENVIRONMENT=production \ + --release +``` + +### iOS + +```bash +flutter build ios \ + --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ + --dart-define=ENVIRONMENT=production \ + --release +``` + +### Web + +```bash +flutter build web \ + --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ + --dart-define=ENVIRONMENT=production \ + --release +``` + +--- + +## 🔑 Variables d'Environnement + +### API_BASE_URL + +URL de base de l'API backend. + +- **Type** : String +- **Requis** : Non (utilise la valeur par défaut si non défini) +- **Défaut** : `http://192.168.1.145:8080` (développement) +- **Production** : `https://api.lions.dev/afterwork` + +**Exemple d'utilisation** : +```dart +import 'package:afterwork/core/constants/env_config.dart'; + +final apiUrl = EnvConfig.apiBaseUrl; +// En prod: https://api.lions.dev/afterwork +``` + +### ENVIRONMENT + +Environnement d'exécution de l'application. + +- **Type** : String +- **Valeurs** : `development`, `staging`, `production` +- **Défaut** : `development` + +**Exemple d'utilisation** : +```dart +import 'package:afterwork/core/constants/env_config.dart'; + +if (EnvConfig.isProduction) { + // Code spécifique à la production +} +``` + +### NETWORK_TIMEOUT + +Timeout pour les requêtes réseau en secondes. + +- **Type** : int +- **Défaut** : 30 +- **Production** : 30 (recommandé) + +### DEBUG_MODE + +Active les logs détaillés et fonctionnalités de debug. + +- **Type** : bool +- **Défaut** : `true` +- **Production** : Automatiquement `false` si `ENVIRONMENT=production` + +### GOOGLE_MAPS_API_KEY + +Clé API Google Maps (optionnelle). + +- **Type** : String +- **Requis** : Non +- **Défaut** : vide + +**Exemple** : +```bash +flutter build apk \ + --dart-define=API_BASE_URL=https://api.lions.dev/afterwork \ + --dart-define=GOOGLE_MAPS_API_KEY=votre_cle_api +``` + +--- + +## 🚀 Endpoints de l'API Production + +L'API production est accessible à l'adresse : **`https://api.lions.dev/afterwork`** + +### Endpoints Principaux + +| Endpoint | Description | +|----------|-------------| +| `/users` | Gestion des utilisateurs | +| `/users/authenticate` | Authentification | +| `/events` | Gestion des événements | +| `/friends` | Gestion des amis | +| `/messages` | Messagerie | +| `/posts` | Posts sociaux | +| `/stories` | Stories | +| `/notifications` | Notifications | + +### WebSockets + +| Endpoint | Description | +|----------|-------------| +| `/chat/ws/{userId}` | Chat en temps réel | +| `/notifications/ws/{userId}` | Notifications en temps réel | + +**URL complète** : +``` +wss://api.lions.dev/afterwork/chat/ws/{userId} +wss://api.lions.dev/afterwork/notifications/ws/{userId} +``` + +### Documentation API + +Swagger UI disponible à : +- **URL** : `https://api.lions.dev/afterwork/q/swagger-ui/` + +--- + +## 📝 Vérification de la Configuration + +Avant le déploiement, vérifiez que : + +✅ L'API backend est accessible : `https://api.lions.dev/afterwork/users` +✅ Les WebSockets fonctionnent +✅ Les certificats TLS sont valides +✅ Le CORS est correctement configuré +✅ L'application se connecte avec succès à l'API + +**Test rapide** : +```bash +# Tester l'API +curl https://api.lions.dev/afterwork/users + +# Devrait retourner: [] (liste vide si aucun utilisateur) +``` + +--- + +## 🐛 Dépannage + +### Erreur : "API_BASE_URL is not set" + +**Solution** : Vérifiez que vous utilisez `--dart-define=API_BASE_URL=...` lors du build. + +### Erreur : "Connection refused" + +**Solutions** : +1. Vérifiez que l'API est accessible : `curl https://api.lions.dev/afterwork/users` +2. Vérifiez votre connexion internet +3. Vérifiez que le CORS est configuré sur le backend + +### L'app se connecte au mauvais environnement + +**Solution** : Reconstruisez complètement l'application avec le bon `--dart-define`. + +```bash +# Nettoyage complet +flutter clean +flutter pub get + +# Rebuild avec la bonne configuration +flutter build apk --dart-define=API_BASE_URL=https://api.lions.dev/afterwork +``` + +--- + +## 📚 Ressources + +- [Documentation Flutter](https://flutter.dev/docs) +- [Flutter Build Modes](https://flutter.dev/docs/testing/build-modes) +- [Environment Variables in Flutter](https://flutter.dev/docs/deployment/flavors) +- [API Backend Repository](https://git.lions.dev/lionsdev/mic-after-work-server-impl-quarkus-main) + +--- + +**Dernière mise à jour** : 2026-01-10 +**Version** : 1.0.0 diff --git a/scripts/build_production.ps1 b/scripts/build_production.ps1 new file mode 100644 index 0000000..75197cb --- /dev/null +++ b/scripts/build_production.ps1 @@ -0,0 +1,82 @@ +# Script de build pour la production +# Usage: .\scripts\build_production.ps1 + +param( + [string]$Platform = "apk", # apk, appbundle, ios, web + [switch]$Clean = $false +) + +Write-Host "🚀 Build AfterWork pour la production..." -ForegroundColor Cyan +Write-Host " Plateforme: $Platform" -ForegroundColor Gray + +# Configuration de production +$API_BASE_URL = "https://api.lions.dev/afterwork" +$ENVIRONMENT = "production" + +# Nettoyage si demandé +if ($Clean) { + Write-Host "`n🧹 Nettoyage du projet..." -ForegroundColor Yellow + flutter clean + flutter pub get +} + +# Définir les dart-defines +$dartDefines = @( + "API_BASE_URL=$API_BASE_URL", + "ENVIRONMENT=$ENVIRONMENT" +) + +$dartDefineArgs = $dartDefines | ForEach-Object { "--dart-define=$_" } + +Write-Host "`n📝 Configuration:" -ForegroundColor Yellow +Write-Host " API_BASE_URL: $API_BASE_URL" -ForegroundColor Gray +Write-Host " ENVIRONMENT: $ENVIRONMENT" -ForegroundColor Gray + +# Build selon la plateforme +Write-Host "`n🔨 Build en cours..." -ForegroundColor Yellow + +switch ($Platform.ToLower()) { + "apk" { + Write-Host " Création de l'APK..." -ForegroundColor Gray + flutter build apk @dartDefineArgs --release + $outputPath = "build\app\outputs\flutter-apk\app-release.apk" + } + "appbundle" { + Write-Host " Création de l'App Bundle..." -ForegroundColor Gray + flutter build appbundle @dartDefineArgs --release + $outputPath = "build\app\outputs\bundle\release\app-release.aab" + } + "ios" { + Write-Host " Création de l'IPA iOS..." -ForegroundColor Gray + flutter build ios @dartDefineArgs --release + $outputPath = "build\ios\ipa" + } + "web" { + Write-Host " Création du build Web..." -ForegroundColor Gray + flutter build web @dartDefineArgs --release + $outputPath = "build\web" + } + default { + Write-Host " ❌ Plateforme non supportée: $Platform" -ForegroundColor Red + Write-Host " Plateformes disponibles: apk, appbundle, ios, web" -ForegroundColor Yellow + exit 1 + } +} + +# Vérifier le succès du build +if ($LASTEXITCODE -eq 0) { + Write-Host "`n✅ Build terminé avec succès!" -ForegroundColor Green + Write-Host "`n📦 Fichier de sortie:" -ForegroundColor Cyan + Write-Host " $outputPath" -ForegroundColor White + + if (Test-Path $outputPath) { + $size = (Get-Item $outputPath -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum + if ($size) { + $sizeMB = [math]::Round($size / 1MB, 2) + Write-Host " Taille: $sizeMB MB" -ForegroundColor Gray + } + } +} else { + Write-Host "`n❌ Le build a échoué!" -ForegroundColor Red + exit 1 +} diff --git a/scripts/build_production.sh b/scripts/build_production.sh new file mode 100644 index 0000000..15a0b10 --- /dev/null +++ b/scripts/build_production.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Script de build pour la production +# Usage: ./scripts/build_production.sh [platform] [--clean] +# Platforms: apk, appbundle, ios, web + +set -e + +# Couleurs pour le terminal +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +GRAY='\033[0;90m' +NC='\033[0m' # No Color + +# Configuration +PLATFORM="${1:-apk}" +CLEAN=false + +# Vérifier les arguments +if [[ "$2" == "--clean" || "$1" == "--clean" ]]; then + CLEAN=true +fi + +# Configuration de production +API_BASE_URL="https://api.lions.dev/afterwork" +ENVIRONMENT="production" + +echo -e "${CYAN}🚀 Build AfterWork pour la production...${NC}" +echo -e "${GRAY} Plateforme: $PLATFORM${NC}" + +# Nettoyage si demandé +if [ "$CLEAN" = true ]; then + echo -e "\n${YELLOW}🧹 Nettoyage du projet...${NC}" + flutter clean + flutter pub get +fi + +# Dart defines +DART_DEFINES=( + "--dart-define=API_BASE_URL=$API_BASE_URL" + "--dart-define=ENVIRONMENT=$ENVIRONMENT" +) + +echo -e "\n${YELLOW}📝 Configuration:${NC}" +echo -e "${GRAY} API_BASE_URL: $API_BASE_URL${NC}" +echo -e "${GRAY} ENVIRONMENT: $ENVIRONMENT${NC}" + +# Build selon la plateforme +echo -e "\n${YELLOW}🔨 Build en cours...${NC}" + +case "$PLATFORM" in + apk) + echo -e "${GRAY} Création de l'APK...${NC}" + flutter build apk "${DART_DEFINES[@]}" --release + OUTPUT_PATH="build/app/outputs/flutter-apk/app-release.apk" + ;; + appbundle) + echo -e "${GRAY} Création de l'App Bundle...${NC}" + flutter build appbundle "${DART_DEFINES[@]}" --release + OUTPUT_PATH="build/app/outputs/bundle/release/app-release.aab" + ;; + ios) + echo -e "${GRAY} Création de l'IPA iOS...${NC}" + flutter build ios "${DART_DEFINES[@]}" --release + OUTPUT_PATH="build/ios/ipa" + ;; + web) + echo -e "${GRAY} Création du build Web...${NC}" + flutter build web "${DART_DEFINES[@]}" --release + OUTPUT_PATH="build/web" + ;; + *) + echo -e "${RED} ❌ Plateforme non supportée: $PLATFORM${NC}" + echo -e "${YELLOW} Plateformes disponibles: apk, appbundle, ios, web${NC}" + exit 1 + ;; +esac + +# Vérifier le succès du build +if [ $? -eq 0 ]; then + echo -e "\n${GREEN}✅ Build terminé avec succès!${NC}" + echo -e "\n${CYAN}📦 Fichier de sortie:${NC}" + echo -e " ${OUTPUT_PATH}" + + if [ -e "$OUTPUT_PATH" ]; then + if [ -f "$OUTPUT_PATH" ]; then + SIZE=$(du -h "$OUTPUT_PATH" | cut -f1) + echo -e "${GRAY} Taille: $SIZE${NC}" + elif [ -d "$OUTPUT_PATH" ]; then + SIZE=$(du -sh "$OUTPUT_PATH" | cut -f1) + echo -e "${GRAY} Taille: $SIZE${NC}" + fi + fi +else + echo -e "\n${RED}❌ Le build a échoué!${NC}" + exit 1 +fi