From dc9da64778f645ea3e4347ee9348acb9de268c47 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 3 Aug 2025 02:44:38 +0200 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 6148 bytes k8s/backend.yaml | 145 +++++++++++++++++++++++++++ k8s/frontend.yaml | 78 +++++++++++++++ k8s/ingress.yaml | 73 ++++++++++++++ k8s/namespace.yaml | 7 ++ k8s/postgres.yaml | 115 +++++++++++++++++++++ scripts/deploy.sh | 242 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 660 insertions(+) create mode 100644 .DS_Store create mode 100644 k8s/backend.yaml create mode 100644 k8s/frontend.yaml create mode 100644 k8s/ingress.yaml create mode 100644 k8s/namespace.yaml create mode 100644 k8s/postgres.yaml create mode 100755 scripts/deploy.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9b8a9374388c68cb4d9cb7f75bb7a7fa060291b2 GIT binary patch literal 6148 zcmeHKF-`+P475okBGIIz+%M2kuA=Y)K7dFXM5G`N`m6FTp2m!AAxPt3-`bKnh5KF9rC0XmDaL924WyfgxG| z;1c05%%hh8HU@yba7;u5=1B!6)vLwuq$A!cuNRJqNjHz1aZcUr)uDLYj(Cf7^PZ?t z3P^#e0*hR(S^w|gKlJ}ol2%ec3j8Yte7U{fZt$e4t+U6m);9P9oH-wG8s /dev/null; then + log_error "Docker n'est pas installé" + exit 1 + fi + + if ! command -v docker-compose &> /dev/null; then + log_error "Docker Compose n'est pas installé" + exit 1 + fi + + if [[ "$ENVIRONMENT" == "prod" ]] && ! command -v kubectl &> /dev/null; then + log_error "kubectl n'est pas installé (requis pour la production)" + exit 1 + fi + + log_success "Prérequis vérifiés" +} + +# Déploiement en développement +deploy_dev() { + log_info "Déploiement en environnement de développement..." + + cd "$PROJECT_ROOT" + + case $COMPONENT in + "all") + docker-compose down + docker-compose up --build -d + ;; + "backend") + docker-compose up --build -d backend + ;; + "frontend") + docker-compose up --build -d frontend + ;; + "database") + docker-compose up -d postgres + ;; + *) + log_error "Composant inconnu: $COMPONENT" + exit 1 + ;; + esac + + log_success "Déploiement dev terminé" + log_info "Frontend: http://localhost:3000" + log_info "Backend: http://localhost:8080" + log_info "Base de données: localhost:5432" +} + +# Déploiement en staging +deploy_staging() { + log_info "Déploiement en environnement de staging..." + + # Build et push des images + build_and_push_images "staging" + + # Déploiement Kubernetes + kubectl apply -f "$PROJECT_ROOT/k8s/namespace.yaml" + kubectl apply -f "$PROJECT_ROOT/k8s/" -n xpeditis-staging + + log_success "Déploiement staging terminé" +} + +# Déploiement en production +deploy_prod() { + log_info "Déploiement en environnement de production..." + + # Confirmation utilisateur + read -p "Êtes-vous sûr de vouloir déployer en production? (y/N): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + log_info "Déploiement annulé" + exit 0 + fi + + # Build et push des images + build_and_push_images "prod" + + # Déploiement Kubernetes + kubectl apply -f "$PROJECT_ROOT/k8s/namespace.yaml" + kubectl apply -f "$PROJECT_ROOT/k8s/" -n xpeditis + + # Attendre que les pods soient prêts + kubectl wait --for=condition=ready pod -l app=backend -n xpeditis --timeout=300s + kubectl wait --for=condition=ready pod -l app=frontend -n xpeditis --timeout=300s + + log_success "Déploiement production terminé" + log_info "Site web: https://xpeditis.fr" + log_info "API: https://api.xpeditis.fr" +} + +# Build et push des images Docker +build_and_push_images() { + local env=$1 + log_info "Build et push des images Docker pour $env..." + + # Backend + if [[ "$COMPONENT" == "all" || "$COMPONENT" == "backend" ]]; then + log_info "Build de l'image backend..." + docker build -t "xpeditis/backend:$env" "$PROJECT_ROOT/backend" + docker tag "xpeditis/backend:$env" "ghcr.io/your-username/xpeditis/backend:$env" + docker push "ghcr.io/your-username/xpeditis/backend:$env" + fi + + # Frontend + if [[ "$COMPONENT" == "all" || "$COMPONENT" == "frontend" ]]; then + log_info "Build de l'image frontend..." + docker build -t "xpeditis/frontend:$env" \ + --build-arg VITE_API_URL="https://api.xpeditis.fr" \ + --target production \ + "$PROJECT_ROOT/frontend" + docker tag "xpeditis/frontend:$env" "ghcr.io/your-username/xpeditis/frontend:$env" + docker push "ghcr.io/your-username/xpeditis/frontend:$env" + fi + + log_success "Images Docker buildées et pushées" +} + +# Fonction de rollback +rollback() { + log_warning "Rollback en cours..." + + if [[ "$ENVIRONMENT" == "dev" ]]; then + docker-compose down + docker-compose up -d + else + kubectl rollout undo deployment/backend -n xpeditis + kubectl rollout undo deployment/frontend -n xpeditis + fi + + log_success "Rollback terminé" +} + +# Afficher l'aide +show_help() { + echo "Usage: $0 [environment] [component]" + echo "" + echo "Environments:" + echo " dev - Environnement de développement (défaut)" + echo " staging - Environnement de staging" + echo " prod - Environnement de production" + echo "" + echo "Components:" + echo " all - Tous les composants (défaut)" + echo " backend - Backend Spring Boot uniquement" + echo " frontend - Frontend React uniquement" + echo " database - Base de données uniquement" + echo "" + echo "Options:" + echo " --rollback - Effectuer un rollback" + echo " --help - Afficher cette aide" + echo "" + echo "Exemples:" + echo " $0 # Déploiement dev complet" + echo " $0 prod all # Déploiement production complet" + echo " $0 staging backend # Déploiement staging backend uniquement" + echo " $0 --rollback # Rollback" +} + +# Point d'entrée principal +main() { + case "${1:-}" in + "--help"|"-h") + show_help + exit 0 + ;; + "--rollback") + rollback + exit 0 + ;; + esac + + log_info "Démarrage du déploiement Xpeditis" + log_info "Environnement: $ENVIRONMENT" + log_info "Composant: $COMPONENT" + + check_prerequisites + + case $ENVIRONMENT in + "dev") + deploy_dev + ;; + "staging") + deploy_staging + ;; + "prod") + deploy_prod + ;; + *) + log_error "Environnement inconnu: $ENVIRONMENT" + show_help + exit 1 + ;; + esac + + log_success "Déploiement terminé avec succès!" +} + +# Exécuter le script principal +main "$@"