feat: Début des évolutions interfaces mobiles v3.2.4

- Préparation de la nouvelle branche pour les évolutions
- Mise à jour de la version vers 3.2.4
- Intégration des modifications en cours

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-04 16:49:29 +02:00
parent 2187dccfeb
commit 2786252307
86 changed files with 3434 additions and 180898 deletions

View File

@@ -1,28 +1,42 @@
#!/bin/bash
# Script de déploiement pour GEOSECTOR API
# Version: 3.0 (10 mai 2025)
# Script de déploiement unifié pour GEOSECTOR API
# Version: 4.0 (Janvier 2025)
# Auteur: Pierre (avec l'aide de Claude)
#
# Usage:
# ./deploy-api.sh # Déploiement local DEV (code → container geo)
# ./deploy-api.sh rca # Livraison RECETTE (container geo → rca-geo)
# ./deploy-api.sh pra # Livraison PRODUCTION (rca-geo → pra-geo)
set -euo pipefail
# =====================================
# Configuration générale
# =====================================
# Paramètre optionnel pour l'environnement cible
TARGET_ENV=${1:-dev}
# Configuration SSH
HOST_KEY="/home/pierre/.ssh/id_rsa_mbpi"
HOST_PORT="22"
HOST_USER="root"
# Configuration des serveurs
JUMP_USER="root"
JUMP_HOST="195.154.80.116"
JUMP_PORT="22"
JUMP_KEY="/home/pierre/.ssh/id_rsa_mbpi"
RCA_HOST="195.154.80.116" # Serveur de recette
PRA_HOST="51.159.7.190" # Serveur de production
# Paramètres du container Incus
INCUS_PROJECT=default
INCUS_CONTAINER=dva-geo
CONTAINER_USER=root
# Paramètres de déploiement
FINAL_PATH="/var/www/geosector/api"
# Configuration Incus
INCUS_PROJECT="default"
API_PATH="/var/www/geosector/api"
FINAL_OWNER="nginx"
FINAL_GROUP="nginx"
FINAL_OWNER_LOGS="nobody"
# Configuration de sauvegarde
BACKUP_DIR="/data/backup/geosector"
# Couleurs pour les messages
GREEN='\033[0;32m'
RED='\033[0;31m'
@@ -30,134 +44,311 @@ YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
run_in_container() {
echo "-> Running: $*"
incus exec "${INCUS_CONTAINER}" -- "$@" || {
echo "❌ Failed to run: $*"
exit 1
}
}
# =====================================
# Fonctions utilitaires
# =====================================
# Fonction pour afficher les messages d'étape
echo_step() {
echo -e "${GREEN}==>${NC} $1"
}
# Fonction pour afficher les informations
echo_info() {
echo -e "${BLUE}Info:${NC} $1"
}
# Fonction pour afficher les avertissements
echo_warning() {
echo -e "${YELLOW}Warning:${NC} $1"
}
# Fonction pour afficher les erreurs
echo_error() {
echo -e "${RED}Error:${NC} $1"
exit 1
}
# Vérification de l'environnement
echo_step "Verifying environment..."
# Fonction pour créer une sauvegarde locale
create_local_backup() {
local archive_file=$1
local backup_type=$2
echo_info "Creating backup in ${BACKUP_DIR}..."
if [ ! -d "${BACKUP_DIR}" ]; then
mkdir -p "${BACKUP_DIR}" || echo_warning "Could not create backup directory ${BACKUP_DIR}"
fi
if [ -d "${BACKUP_DIR}" ]; then
BACKUP_FILE="${BACKUP_DIR}/api-${backup_type}-$(date +%Y%m%d-%H%M%S).tar.gz"
cp "${archive_file}" "${BACKUP_FILE}" && {
echo_info "Backup saved to: ${BACKUP_FILE}"
echo_info "Backup size: $(du -h "${BACKUP_FILE}" | cut -f1)"
# Nettoyer les anciens backups (garder les 10 derniers)
echo_info "Cleaning old backups (keeping last 10)..."
ls -t "${BACKUP_DIR}"/api-${backup_type}-*.tar.gz 2>/dev/null | tail -n +11 | xargs -r rm -f && {
REMAINING_BACKUPS=$(ls "${BACKUP_DIR}"/api-${backup_type}-*.tar.gz 2>/dev/null | wc -l)
echo_info "Kept ${REMAINING_BACKUPS} backup(s)"
}
} || echo_warning "Failed to create backup in ${BACKUP_DIR}"
fi
}
# Vérification des fichiers requis
if [ ! -f "src/Config/AppConfig.php" ]; then
echo_error "Configuration file missing"
fi
# =====================================
# Détermination de la configuration selon l'environnement
# =====================================
if [ ! -f "composer.json" ] || [ ! -f "composer.lock" ]; then
echo_error "Composer files missing"
fi
case $TARGET_ENV in
"dev")
echo_step "Configuring for LOCAL DEV deployment"
SOURCE_TYPE="local_code"
DEST_CONTAINER="geo"
DEST_HOST="local"
ENV_NAME="DEVELOPMENT"
;;
"rca")
echo_step "Configuring for RECETTE delivery"
SOURCE_TYPE="local_container"
SOURCE_CONTAINER="geo"
DEST_CONTAINER="rca-geo"
DEST_HOST="${RCA_HOST}"
ENV_NAME="RECETTE"
;;
"pra")
echo_step "Configuring for PRODUCTION delivery"
SOURCE_TYPE="remote_container"
SOURCE_HOST="${RCA_HOST}"
SOURCE_CONTAINER="rca-geo"
DEST_CONTAINER="pra-geo"
DEST_HOST="${PRA_HOST}"
ENV_NAME="PRODUCTION"
;;
*)
echo_error "Unknown environment: $TARGET_ENV. Use 'dev', 'rca' or 'pra'"
;;
esac
# Étape 0: Définir le nom de l'archive
ARCHIVE_NAME="api-deploy-$(date +%s).tar.gz"
echo_info "Deployment flow: ${ENV_NAME}"
# =====================================
# Création de l'archive selon la source
# =====================================
TIMESTAMP=$(date +%s)
ARCHIVE_NAME="api-deploy-${TIMESTAMP}.tar.gz"
TEMP_ARCHIVE="/tmp/${ARCHIVE_NAME}"
echo_info "Archive name will be: $ARCHIVE_NAME"
# Étape 1: Créer une archive du projet
echo_step "Creating project archive..."
tar --exclude='.git' \
--exclude='.gitignore' \
--exclude='.vscode' \
--exclude='logs' \
--exclude='*.template' \
--exclude='*.sh' \
--exclude='.env' \
--exclude='*.log' \
--exclude='.DS_Store' \
--exclude='README.md' \
--exclude="*.tar.gz" \
--exclude='node_modules' \
--exclude='vendor' \
--exclude='*.swp' \
--exclude='*.swo' \
--exclude='*~' \
--warning=no-file-changed \
--no-xattrs \
-czf "${TEMP_ARCHIVE}" . || echo_error "Failed to create archive"
if [ "$SOURCE_TYPE" = "local_code" ]; then
# DEV: Créer une archive depuis le code local
echo_step "Creating archive from local code..."
# Vérification des fichiers requis
if [ ! -f "src/Config/AppConfig.php" ]; then
echo_error "Configuration file missing"
fi
if [ ! -f "composer.json" ] || [ ! -f "composer.lock" ]; then
echo_error "Composer files missing"
fi
tar --exclude='.git' \
--exclude='.gitignore' \
--exclude='.vscode' \
--exclude='logs' \
--exclude='*.template' \
--exclude='*.sh' \
--exclude='.env' \
--exclude='*.log' \
--exclude='.DS_Store' \
--exclude='README.md' \
--exclude="*.tar.gz" \
--exclude='node_modules' \
--exclude='vendor' \
--exclude='*.swp' \
--exclude='*.swo' \
--exclude='*~' \
--warning=no-file-changed \
--no-xattrs \
-czf "${TEMP_ARCHIVE}" . || echo_error "Failed to create archive"
create_local_backup "${TEMP_ARCHIVE}" "dev"
elif [ "$SOURCE_TYPE" = "local_container" ]; then
# RCA: Créer une archive depuis le container local
echo_step "Creating archive from local container ${SOURCE_CONTAINER}..."
echo_info "Switching to Incus project ${INCUS_PROJECT}..."
incus project switch ${INCUS_PROJECT} || echo_error "Failed to switch project"
# Créer l'archive directement depuis le container local
incus exec ${SOURCE_CONTAINER} -- tar \
--exclude='logs' \
--exclude='uploads' \
--warning=no-file-changed \
-czf /tmp/${ARCHIVE_NAME} -C ${API_PATH} . || echo_error "Failed to create archive from container"
# Récupérer l'archive depuis le container
incus file pull ${SOURCE_CONTAINER}/tmp/${ARCHIVE_NAME} ${TEMP_ARCHIVE} || echo_error "Failed to pull archive from container"
incus exec ${SOURCE_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME}
create_local_backup "${TEMP_ARCHIVE}" "to-rca"
elif [ "$SOURCE_TYPE" = "remote_container" ]; then
# PRA: Créer une archive depuis un container distant
echo_step "Creating archive from remote container ${SOURCE_CONTAINER} on ${SOURCE_HOST}..."
# Créer l'archive sur le serveur source
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${SOURCE_HOST} "
incus project switch ${INCUS_PROJECT} &&
incus exec ${SOURCE_CONTAINER} -- tar \
--exclude='logs' \
--exclude='uploads' \
--warning=no-file-changed \
-czf /tmp/${ARCHIVE_NAME} -C ${API_PATH} .
" || echo_error "Failed to create archive on remote"
# Extraire l'archive du container vers l'hôte
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${SOURCE_HOST} "
incus file pull ${SOURCE_CONTAINER}/tmp/${ARCHIVE_NAME} /tmp/${ARCHIVE_NAME} &&
incus exec ${SOURCE_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME}
" || echo_error "Failed to extract archive from remote container"
# Copier l'archive vers la machine locale pour backup
scp -i ${HOST_KEY} -P ${HOST_PORT} ${HOST_USER}@${SOURCE_HOST}:/tmp/${ARCHIVE_NAME} ${TEMP_ARCHIVE} || echo_error "Failed to copy archive locally"
create_local_backup "${TEMP_ARCHIVE}" "to-pra"
fi
# Vérifier la taille de l'archive
ARCHIVE_SIZE=$(du -h "${TEMP_ARCHIVE}" | cut -f1)
echo_info "Archive size: ${ARCHIVE_SIZE}"
SSH_JUMP_CMD="ssh -i ${JUMP_KEY} -p ${JUMP_PORT} ${JUMP_USER}@${JUMP_HOST}"
# =====================================
# Déploiement selon la destination
# =====================================
# Étape 2: Copier l'archive vers le serveur de saut
echo_step "Copying archive to jump server..."
echo_info "Archive size: $ARCHIVE_SIZE"
scp -i "${JUMP_KEY}" -P "${JUMP_PORT}" "${TEMP_ARCHIVE}" "${JUMP_USER}@${JUMP_HOST}:/tmp/${ARCHIVE_NAME}" || echo_error "Failed to copy archive to jump server"
# Étape 3: Exécuter les commandes sur le serveur de saut pour déployer dans le container Incus
echo_step "Deploying to Incus container..."
$SSH_JUMP_CMD "
set -euo pipefail
echo '✅ Passage au projet Incus...'
incus project switch ${INCUS_PROJECT} || exit 1
echo '📦 Poussée de archive dans le conteneur...'
incus file push /tmp/${ARCHIVE_NAME} ${INCUS_CONTAINER}/tmp/${ARCHIVE_NAME} || exit 1
echo '📁 Préparation du dossier final...'
incus exec ${INCUS_CONTAINER} -- mkdir -p ${FINAL_PATH} || exit 1
incus exec ${INCUS_CONTAINER} -- rm -rf ${FINAL_PATH}/* || exit 1
incus exec ${INCUS_CONTAINER} -- tar -xzf /tmp/${ARCHIVE_NAME} -C ${FINAL_PATH}/ || exit 1
echo '🔧 Réglage des permissions...'
incus exec ${INCUS_CONTAINER} -- mkdir -p ${FINAL_PATH}/logs || exit 1
incus exec ${INCUS_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_GROUP} ${FINAL_PATH} || exit 1
incus exec ${INCUS_CONTAINER} -- find ${FINAL_PATH} -type d -exec chmod 755 {} \; || exit 1
incus exec ${INCUS_CONTAINER} -- find ${FINAL_PATH} -type f -exec chmod 644 {} \; || exit 1
# Permissions spéciales pour le dossier logs (pour permettre à PHP-FPM de l'utilisateur nobody d'y écrire)
incus exec ${INCUS_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_OWNER_LOGS} ${FINAL_PATH}/logs || exit 1
incus exec ${INCUS_CONTAINER} -- chmod -R 775 ${FINAL_PATH}/logs || exit 1
incus exec ${INCUS_CONTAINER} -- find ${FINAL_PATH}/logs -type f -exec chmod 664 {} \; || exit 1
echo '📁 Création des dossiers uploads...'
incus exec ${INCUS_CONTAINER} -- mkdir -p ${FINAL_PATH}/uploads || exit 1
incus exec ${INCUS_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_OWNER_LOGS} ${FINAL_PATH}/uploads || exit 1
incus exec ${INCUS_CONTAINER} -- chmod -R 775 ${FINAL_PATH}/uploads || exit 1
incus exec ${INCUS_CONTAINER} -- find ${FINAL_PATH}/uploads -type f -exec chmod -R 664 {} \; || exit 1
echo '📦 Mise à jour des dépendances Composer...'
incus exec ${INCUS_CONTAINER} -- bash -c 'cd ${FINAL_PATH} && composer update --no-dev --optimize-autoloader' || {
echo '⚠️ Composer non disponible ou échec, poursuite sans mise à jour des dépendances'
}
echo '🧹 Nettoyage...'
incus exec ${INCUS_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME} || exit 1
rm -f /tmp/${ARCHIVE_NAME} || exit 1
"
if [ "$DEST_HOST" = "local" ]; then
# Déploiement sur container local (DEV)
echo_step "Deploying to local container ${DEST_CONTAINER}..."
echo_info "Switching to Incus project ${INCUS_PROJECT}..."
incus project switch ${INCUS_PROJECT} || echo_error "Failed to switch to project ${INCUS_PROJECT}"
echo_info "Pushing archive to container..."
incus file push "${TEMP_ARCHIVE}" ${DEST_CONTAINER}/tmp/${ARCHIVE_NAME} || echo_error "Failed to push archive to container"
echo_info "Preparing deployment directory..."
incus exec ${DEST_CONTAINER} -- mkdir -p ${API_PATH} || echo_error "Failed to create deployment directory"
incus exec ${DEST_CONTAINER} -- rm -rf ${API_PATH}/* || echo_warning "Could not clean deployment directory"
echo_info "Extracting archive..."
incus exec ${DEST_CONTAINER} -- tar -xzf /tmp/${ARCHIVE_NAME} -C ${API_PATH}/ || echo_error "Failed to extract archive"
echo_info "Setting permissions..."
incus exec ${DEST_CONTAINER} -- mkdir -p ${API_PATH}/logs ${API_PATH}/uploads
incus exec ${DEST_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_GROUP} ${API_PATH}
incus exec ${DEST_CONTAINER} -- find ${API_PATH} -type d -exec chmod 755 {} \;
incus exec ${DEST_CONTAINER} -- find ${API_PATH} -type f -exec chmod 644 {} \;
# Permissions spéciales pour logs et uploads
incus exec ${DEST_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_OWNER_LOGS} ${API_PATH}/logs ${API_PATH}/uploads
incus exec ${DEST_CONTAINER} -- chmod -R 775 ${API_PATH}/logs ${API_PATH}/uploads
echo_info "Updating Composer dependencies..."
incus exec ${DEST_CONTAINER} -- bash -c "cd ${API_PATH} && composer update --no-dev --optimize-autoloader" || echo_warning "Composer not available or failed"
echo_info "Cleaning up..."
incus exec ${DEST_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME}
else
# Déploiement sur container distant (RCA ou PRA)
echo_step "Deploying to remote container ${DEST_CONTAINER} on ${DEST_HOST}..."
# Créer une sauvegarde sur le serveur de destination
BACKUP_TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
REMOTE_BACKUP_DIR="${API_PATH}_backup_${BACKUP_TIMESTAMP}"
echo_info "Creating backup on destination..."
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${DEST_HOST} "
incus project switch ${INCUS_PROJECT} &&
incus exec ${DEST_CONTAINER} -- test -d ${API_PATH} &&
incus exec ${DEST_CONTAINER} -- cp -r ${API_PATH} ${REMOTE_BACKUP_DIR} &&
echo 'Backup created: ${REMOTE_BACKUP_DIR}'
" || echo_warning "No existing installation to backup"
# Transférer l'archive vers le serveur de destination
echo_info "Transferring archive to ${DEST_HOST}..."
if [ "$SOURCE_TYPE" = "local_container" ]; then
# Pour RCA: copier depuis local vers distant
scp -i ${HOST_KEY} -P ${HOST_PORT} ${TEMP_ARCHIVE} ${HOST_USER}@${DEST_HOST}:/tmp/${ARCHIVE_NAME} || echo_error "Failed to copy archive to destination"
else
# Pour PRA: copier de serveur à serveur
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${SOURCE_HOST} "
scp -i ${HOST_KEY} -P ${HOST_PORT} /tmp/${ARCHIVE_NAME} ${HOST_USER}@${DEST_HOST}:/tmp/${ARCHIVE_NAME}
" || echo_error "Failed to transfer archive between servers"
# Nettoyer sur le serveur source
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${SOURCE_HOST} "rm -f /tmp/${ARCHIVE_NAME}"
fi
# Déployer sur le container de destination
echo_info "Extracting on destination container..."
ssh -i ${HOST_KEY} -p ${HOST_PORT} ${HOST_USER}@${DEST_HOST} "
set -euo pipefail
# Pousser l'archive dans le container
incus project switch ${INCUS_PROJECT} &&
incus file push /tmp/${ARCHIVE_NAME} ${DEST_CONTAINER}/tmp/${ARCHIVE_NAME} &&
# Nettoyer sélectivement (préserver logs et uploads)
incus exec ${DEST_CONTAINER} -- find ${API_PATH} -mindepth 1 -maxdepth 1 ! -name 'uploads' ! -name 'logs' -exec rm -rf {} \; 2>/dev/null || true &&
# Extraire l'archive
incus exec ${DEST_CONTAINER} -- tar -xzf /tmp/${ARCHIVE_NAME} -C ${API_PATH}/ &&
# Permissions
incus exec ${DEST_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_GROUP} ${API_PATH} &&
incus exec ${DEST_CONTAINER} -- find ${API_PATH} -type d -exec chmod 755 {} \; &&
incus exec ${DEST_CONTAINER} -- find ${API_PATH} -type f -exec chmod 644 {} \; &&
# Permissions spéciales pour logs
incus exec ${DEST_CONTAINER} -- test -d ${API_PATH}/logs &&
incus exec ${DEST_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_OWNER_LOGS} ${API_PATH}/logs &&
incus exec ${DEST_CONTAINER} -- chmod -R 775 ${API_PATH}/logs || true &&
# Permissions spéciales pour uploads
incus exec ${DEST_CONTAINER} -- test -d ${API_PATH}/uploads &&
incus exec ${DEST_CONTAINER} -- chown -R ${FINAL_OWNER}:${FINAL_OWNER_LOGS} ${API_PATH}/uploads &&
incus exec ${DEST_CONTAINER} -- chmod -R 775 ${API_PATH}/uploads || true &&
# Composer
incus exec ${DEST_CONTAINER} -- bash -c 'cd ${API_PATH} && composer update --no-dev --optimize-autoloader' || echo 'Composer update skipped' &&
# Nettoyage
incus exec ${DEST_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME} &&
rm -f /tmp/${ARCHIVE_NAME}
" || echo_error "Deployment failed on destination"
echo_info "Remote backup saved: ${REMOTE_BACKUP_DIR} on ${DEST_CONTAINER}"
fi
# Nettoyage local
rm -f "${TEMP_ARCHIVE}"
# =====================================
# Résumé final
echo_step "Deployment completed successfully."
echo_info "Your API has been updated on the container."
# =====================================
echo_step "Deployment completed successfully!"
echo_info "Environment: ${ENV_NAME}"
if [ "$TARGET_ENV" = "dev" ]; then
echo_info "Deployed from local code to container ${DEST_CONTAINER}"
elif [ "$TARGET_ENV" = "rca" ]; then
echo_info "Delivered from ${SOURCE_CONTAINER} (local) to ${DEST_CONTAINER} on ${DEST_HOST}"
elif [ "$TARGET_ENV" = "pra" ]; then
echo_info "Delivered from ${SOURCE_CONTAINER} on ${SOURCE_HOST} to ${DEST_CONTAINER} on ${DEST_HOST}"
fi
echo_info "Deployment completed at: $(date)"
# Journaliser le déploiement
echo "$(date '+%Y-%m-%d %H:%M:%S') - API deployed to ${JUMP_HOST}:${INCUS_CONTAINER}" >> ~/.geo_deploy_history
echo "$(date '+%Y-%m-%d %H:%M:%S') - API deployed to ${ENV_NAME} (${DEST_CONTAINER})" >> ~/.geo_deploy_history