Initial commit - SOGOMS v1.0.0
- sogoctl: supervisor avec health checks et restart auto - sogoway: gateway HTTP, auth JWT, routing par hostname - sogoms-db: microservice MariaDB avec pool par application - Protocol IPC Unix socket JSON length-prefixed - Config YAML multi-application (prokov) - Deploy script pour container Alpine gw3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
147
clients/prokov/api/deploy-api.sh
Executable file
147
clients/prokov/api/deploy-api.sh
Executable file
@@ -0,0 +1,147 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script de déploiement pour PROKOV API
|
||||
# Version: 1.0 (12 décembre 2025)
|
||||
# Auteur: Pierre (avec l'aide de Claude)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ENV=DEV
|
||||
JUMP_USER="root"
|
||||
JUMP_HOST="195.154.80.116"
|
||||
JUMP_PORT="22"
|
||||
JUMP_KEY="/home/pierre/.ssh/id_rsa_mbpi"
|
||||
INCUS_PROJECT=default
|
||||
INCUS_CONTAINER=dva-front
|
||||
|
||||
# Paramètres du container Incus
|
||||
CONTAINER_USER=root
|
||||
CONTAINER_IP="13.23.33.42"
|
||||
|
||||
# Paramètres de déploiement
|
||||
FINAL_PATH="/var/www/prokov/api"
|
||||
FINAL_OWNER="nginx"
|
||||
FINAL_GROUP="nginx"
|
||||
FINAL_OWNER_LOGS="nobody"
|
||||
|
||||
# Couleurs pour les messages
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 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..."
|
||||
echo_info "Deploying PROKOV API to $ENV environment"
|
||||
echo_info "Container: $INCUS_CONTAINER (IP: $CONTAINER_IP)"
|
||||
echo_info "Target path: $FINAL_PATH"
|
||||
|
||||
# Vérification des fichiers requis
|
||||
if [ ! -f "public/index.php" ]; then
|
||||
echo_error "public/index.php missing - are you in the api directory?"
|
||||
fi
|
||||
|
||||
if [ ! -d "core" ] || [ ! -d "controllers" ]; then
|
||||
echo_error "API structure incomplete (core/ or controllers/ missing)"
|
||||
fi
|
||||
|
||||
# Étape 0: Définir le nom de l'archive
|
||||
ARCHIVE_NAME="prokov-api-${ENV}-$(date +%s).tar.gz"
|
||||
ARCHIVE_PATH="/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" \
|
||||
--no-xattrs \
|
||||
-czf "${ARCHIVE_PATH}" . || echo_error "Failed to create archive"
|
||||
|
||||
# Vérifier la taille de l'archive
|
||||
ARCHIVE_SIZE=$(du -h "${ARCHIVE_PATH}" | cut -f1)
|
||||
|
||||
SSH_JUMP_CMD="ssh -i ${JUMP_KEY} -p ${JUMP_PORT} ${JUMP_USER}@${JUMP_HOST}"
|
||||
|
||||
# Étape 2: Copier l'archive vers le serveur de saut (IN3)
|
||||
echo_step "Copying archive to jump server (IN3)..."
|
||||
echo_info "Archive size: $ARCHIVE_SIZE"
|
||||
scp -i "${JUMP_KEY}" -P "${JUMP_PORT}" "${ARCHIVE_PATH}" "${JUMP_USER}@${JUMP_HOST}:/tmp/${ARCHIVE_NAME}" || echo_error "Failed to copy archive to jump server"
|
||||
|
||||
# Étape 3: Exécuter les commandes sur IN3 pour déployer dans le container Incus dva-front
|
||||
echo_step "Deploying to Incus container ($INCUS_CONTAINER)..."
|
||||
$SSH_JUMP_CMD "
|
||||
set -euo pipefail
|
||||
|
||||
echo '✅ Passage au projet Incus...'
|
||||
incus project switch ${INCUS_PROJECT} || exit 1
|
||||
|
||||
echo '📦 Poussée de l 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
|
||||
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
|
||||
|
||||
echo '🧹 Nettoyage...'
|
||||
incus exec ${INCUS_CONTAINER} -- rm -f /tmp/${ARCHIVE_NAME} || exit 1
|
||||
rm -f /tmp/${ARCHIVE_NAME} || exit 1
|
||||
"
|
||||
|
||||
# Nettoyage local
|
||||
rm -f "${ARCHIVE_PATH}"
|
||||
|
||||
# Résumé final
|
||||
echo_step "Deployment completed successfully."
|
||||
echo ""
|
||||
echo_info "PROKOV API deployed to $ENV environment"
|
||||
echo_info " Host: IN3 ($JUMP_HOST)"
|
||||
echo_info " Container: $INCUS_CONTAINER ($CONTAINER_IP)"
|
||||
echo_info " Path: $FINAL_PATH"
|
||||
echo_info " Deployment time: $(date)"
|
||||
echo ""
|
||||
echo_info "API should be accessible at: https://prokov.unikoffice.com/api/"
|
||||
|
||||
# Journaliser le déploiement
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - PROKOV API deployed to ${ENV} (${INCUS_CONTAINER}:${FINAL_PATH})" >> ~/.prokov_deploy_history
|
||||
Reference in New Issue
Block a user