From 01c0db45f51682bb3fcf54f5b0a1d8456b9d5ba5 Mon Sep 17 00:00:00 2001 From: BeauTroll <-> Date: Wed, 17 Dec 2025 20:19:23 +0100 Subject: [PATCH] feat: enhance Makefile with Docker Compose v2 support and new utilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Major improvements to the Makefile: - Auto-detect Docker Compose v2 (docker compose) vs v1 (docker-compose) - Add new utility commands: * make logs-all: View logs from all containers * make shell: Open bash in Nextcloud container * make db-shell: Open MySQL shell * make redis-shell: Open Redis CLI (with password support) * make permissions: Fix file permissions * make clean: Clean old logs (>30 days) and temp files - Improve restore command: * Now requires FILE= parameter for better UX * Shows helpful error with list of available backups * Example: make restore FILE=./backups/backup.tar.gz - Better help organization: * New "Monitoring" section * Better documentation for all commands * More detailed command descriptions - Simplify health check: * Use comprehensive check-health.sh script * Remove duplicate check-health target 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- Makefile | 78 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f0f2ce9..b2edbbc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ -.PHONY: help up down restart logs ps occ backup restore update health check-health recover +.PHONY: help up down restart logs logs-all ps shell db-shell redis-shell occ backup restore update health check-health recover clean permissions include .env export +# Detect Docker Compose command +DOCKER_COMPOSE := $(shell command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1 && echo "docker compose" || echo "docker-compose") + help: @echo "Nextcloud Docker - Commandes disponibles:" @echo "" @@ -12,6 +15,7 @@ help: @echo " make restart - Redémarrer tous les services" @echo " make ps - Lister les containers actifs" @echo " make logs - Afficher les logs Nextcloud en temps réel" + @echo " make logs-all - Afficher les logs de tous les containers" @echo "" @echo "Maintenance:" @echo " make backup - Backup complet (DB + fichiers + config)" @@ -27,29 +31,60 @@ help: @echo " → Upgrade base de données" @echo " → Optimisations post-update" @echo "" - @echo " make restore - Restaurer depuis un backup" + @echo " make restore FILE=" + @echo " - Restaurer depuis un backup" @echo " → Arrêt des services" @echo " → Restauration DB + fichiers" @echo " → Redémarrage et réparation" @echo "" + @echo " make recover - Récupération après erreur" + @echo " → Arrêt/nettoyage des containers" + @echo " → Redémarrage propre" + @echo " → Désactivation mode maintenance" + @echo "" + @echo "Monitoring:" + @echo " make health - Health check complet du système" + @echo " → Docker, containers, Nextcloud, DB, Redis" + @echo " → Espace disque, backups, logs" + @echo "" @echo "Outils:" @echo " make occ - Exécuter une commande OCC Nextcloud" - @echo " make health - Vérifier l'état (Nextcloud + DB + config)" + @echo " make shell - Ouvrir un shell dans le container Nextcloud" + @echo " make db-shell - Ouvrir un shell MySQL/MariaDB" + @echo " make redis-shell - Ouvrir un shell Redis" + @echo " make permissions - Réparer les permissions des fichiers" + @echo " make clean - Nettoyer les logs et fichiers temporaires" up: - docker-compose up -d + $(DOCKER_COMPOSE) up -d down: - docker-compose down + $(DOCKER_COMPOSE) down restart: - docker-compose restart + $(DOCKER_COMPOSE) restart logs: - docker-compose logs -f --tail=100 nextcloud + $(DOCKER_COMPOSE) logs -f --tail=100 nextcloud + +logs-all: + $(DOCKER_COMPOSE) logs -f --tail=50 ps: - docker-compose ps + $(DOCKER_COMPOSE) ps + +shell: + $(DOCKER_COMPOSE) exec nextcloud /bin/bash + +db-shell: + $(DOCKER_COMPOSE) exec db mysql -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE" + +redis-shell: + @if [ -n "$(REDIS_HOST_PASSWORD)" ]; then \ + $(DOCKER_COMPOSE) exec redis redis-cli -a "$(REDIS_HOST_PASSWORD)"; \ + else \ + $(DOCKER_COMPOSE) exec redis redis-cli; \ + fi occ: @bash scripts/occ.sh $(filter-out $@,$(MAKECMDGOALS)) @@ -58,22 +93,37 @@ backup: @bash scripts/backup.sh restore: - @bash scripts/restore.sh $(filter-out $@,$(MAKECMDGOALS)) + @if [ -z "$(FILE)" ]; then \ + echo "❌ Erreur: Spécifiez le fichier de backup avec FILE="; \ + echo "Exemple: make restore FILE=./backups/nextcloud_backup_20231217_123456.tar.gz"; \ + echo ""; \ + echo "Backups disponibles:"; \ + find ./backups -name "nextcloud_backup_*.tar.gz" -type f -printf '%T+ %p\n' 2>/dev/null | sort -r | head -5; \ + exit 1; \ + fi + @bash scripts/restore.sh "$(FILE)" update: @bash scripts/update.sh health: - @docker-compose exec nextcloud php occ status - @docker-compose exec nextcloud php occ config:list system - @docker-compose exec -T db sh -c 'mysql -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" -e "SELECT 1"' 2>/dev/null && echo "✅ Base de données accessible" || echo "❌ Erreur base de données" - -check-health: @bash scripts/check-health.sh recover: @bash scripts/recover.sh +permissions: + @echo "Réparation des permissions..." + $(DOCKER_COMPOSE) exec -u root nextcloud chown -R www-data:www-data /var/www/html/data /var/www/html/config /var/www/html/custom_apps + @echo "✅ Permissions réparées" + +clean: + @echo "Nettoyage des logs et fichiers temporaires..." + @find ./logs -type f -mtime +30 -delete 2>/dev/null && echo "✅ Logs > 30 jours supprimés" || true + @rm -f /tmp/nextcloud_*.lock 2>/dev/null && echo "✅ Fichiers lock supprimés" || true + @$(DOCKER_COMPOSE) exec -T nextcloud php occ files:cleanup 2>/dev/null && echo "✅ Fichiers orphelins nettoyés" || true + @echo "✅ Nettoyage terminé" + # Catch-all target pour permettre les arguments aux commandes occ et restore %: @: