4NK_env/scripts/lecoffre_node/deploy-autonomous.sh
LeCoffre Deployment 43a05a2742 clean
2025-09-25 12:19:35 +00:00

116 lines
3.7 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
echo "🚀 DÉPLOIEMENT DE L'ARCHITECTURE AUTONOME COMPLÈTE"
echo "================================================="
# Fonction de logging
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Variables
MASTER_IMAGE_NAME="lecoffre-node-master"
MASTER_IMAGE_TAG="ext"
CONTAINER_NAME="lecoffre-node-master"
HOST_PORT=80
log "🔧 Préparation de l'environnement..."
# Vérification des prérequis
if ! command -v docker &> /dev/null; then
log "❌ Docker non disponible"
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
log "❌ Docker Compose non disponible"
exit 1
fi
log "✅ Prérequis validés"
# Arrêt des services existants
log "🛑 Arrêt des services existants..."
cd /home/debian/4NK_env/lecoffre_node
docker compose down 2>/dev/null || true
# Construction de l'image master
log "🏗️ Construction de l'image master..."
docker build -f Dockerfile.master -t ${MASTER_IMAGE_NAME}:${MASTER_IMAGE_TAG} .
log "🧹 Nettoyage des conteneurs existants..."
docker stop ${CONTAINER_NAME} 2>/dev/null || true
docker rm ${CONTAINER_NAME} 2>/dev/null || true
# Création des répertoires de données
log "📁 Création des répertoires de données..."
mkdir -p /home/debian/4NK_env/lecoffre_node/{data,logs,backup}
log "🚀 Démarrage du conteneur master autonome..."
log " Le conteneur utilise son propre Nginx (ports 80, 443, 3000) - indépendant du host"
log " Port 3000 pour redirections externes IdNot (dev3.4nkweb.com)"
docker run -d \
--name ${CONTAINER_NAME} \
--privileged \
--restart unless-stopped \
-p 80:80 \
-p 443:443 \
-p 3000:3000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/debian/4NK_env/lecoffre_node/data:/app/data \
-v /home/debian/4NK_env/lecoffre_node/logs:/app/logs \
-v /home/debian/4NK_env/lecoffre_node/conf:/app/conf \
-v /home/debian/4NK_env/lecoffre_node/backup:/app/backup \
-v /home/debian/4NK_env/lecoffre_node/.env.master:/app/.env \
${MASTER_IMAGE_NAME}:${MASTER_IMAGE_TAG}
log "⏳ Attente du démarrage du conteneur master..."
sleep 30
log "🔍 Vérification du statut du conteneur..."
docker ps | grep ${CONTAINER_NAME}
log "🧪 Test de connectivité des services..."
sleep 20
# Tests de connectivité
services=(
"http://localhost:${HOST_PORT}/status/|Status Page"
"http://localhost:${HOST_PORT}/grafana/|Grafana"
"http://localhost:${HOST_PORT}/lecoffre/|LeCoffre Front"
"http://localhost:${HOST_PORT}/|IHM Client"
"http://localhost:${HOST_PORT}/api/v1/health|API Backend"
)
for service in "${services[@]}"; do
IFS='|' read -r url name <<< "$service"
if curl -f -s "$url" > /dev/null 2>&1; then
log "$name: Accessible"
else
log "⚠️ $name: Inaccessible (peut être normal pendant le démarrage)"
fi
done
log "📊 Logs du conteneur master:"
docker logs ${CONTAINER_NAME} --tail 10
log "🎉 Architecture autonome déployée!"
log "📋 Services disponibles:"
log " - Status Page: http://localhost:${HOST_PORT}/status/"
log " - Grafana: http://localhost:${HOST_PORT}/grafana/"
log " - LeCoffre Front: http://localhost:${HOST_PORT}/lecoffre/"
log " - IHM Client: http://localhost:${HOST_PORT}/"
log " - API Backend: http://localhost:${HOST_PORT}/api/"
log ""
log "🔧 Architecture autonome:"
log " - Nginx intégré dans le conteneur (port 80)"
log " - Indépendant du Nginx du host"
log " - Toutes les configurations dans lecoffre_node/"
log ""
log "🔧 Commandes utiles:"
log " - Logs: docker logs ${CONTAINER_NAME}"
log " - Shell: docker exec -it ${CONTAINER_NAME} bash"
log " - Redémarrage: docker restart ${CONTAINER_NAME}"
log " - Arrêt: docker stop ${CONTAINER_NAME}"