# ---------------------------------- # Projekt: michaelschiemer.de # Docker & Ansible Makefile # ---------------------------------- PROJECT_NAME = michaelschiemer ENV ?= dev # Standart Docker Compose Befehle up: ## Startet alle Docker-Container docker compose up -d down: ## Stoppt alle Container docker compose down build: docker compose build restart: ## Neustart aller Container ./bin/restart logs: ## Zeigt Logs aus Docker docker compose logs -f ps: ## Docker PS docker compose ps reload: ## Dump Autoload & Restart PHP docker-compose exec php composer dump-autoload -o docker-compose restart php flush-redis: ## Clear Redis cache (FLUSHALL) docker exec redis redis-cli FLUSHALL # Wähle dev- oder prod-PHP-Konfig je nach ENV phpinfo: @echo "Aktive PHP-Konfiguration: php.$(ENV).ini" # Ansible Deployment setup: ## Führt Ansible Setup aus ./bin/setup deploy: ## Führt Ansible Deploy aus ./bin/deploy test: ## Führt alle Tests mit PHP 8.4 aus @echo "🧪 Running tests with PHP 8.4..." docker compose --profile test run --rm php-test ./vendor/bin/pest test-php85: ## Führt alle Tests mit PHP 8.5 aus (Development) @echo "🧪 Running tests with PHP 8.5..." docker exec php ./vendor/bin/pest test-coverage: ## Führt Tests mit Coverage-Report aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest --coverage test-coverage-html: ## Generiert HTML Coverage-Report (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest --coverage-html coverage-html @echo "📊 Coverage-Report verfügbar unter: coverage-html/index.html" test-unit: ## Führt nur Unit-Tests aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest tests/Unit/ test-framework: ## Führt nur Framework-Tests aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest tests/Framework/ test-domain: ## Führt nur Domain-Tests aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest tests/Domain/ test-watch: ## Führt Tests im Watch-Modus aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest --watch test-parallel: ## Führt Tests parallel aus (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest --parallel test-profile: ## Profiling der langsamsten Tests (PHP 8.4) docker compose --profile test run --rm php-test ./vendor/bin/pest --profile test-filter: ## Führt spezifische Tests aus (PHP 8.4) (Usage: make test-filter FILTER="EventDispatcher") docker compose --profile test run --rm php-test ./vendor/bin/pest --filter="$(FILTER)" # Security Checks security-check: ## Führt Composer Security Audit aus docker exec php composer security:audit security-audit-json: ## Führt Security Audit mit JSON-Output aus docker exec php composer security:audit-json security-check-prod: ## Prüft nur Production-Dependencies auf Schwachstellen docker exec php composer security:check # Cleanup temporärer/metadaten-Dateien clean: ## Entfernt temporäre Dateien find . -type f -name "*Zone.Identifier" -delete find . -type f -name "*.retry" -delete clean-coverage: ## Entfernt Coverage-Reports rm -rf coverage-html/ coverage-xml/ coverage.txt @echo "🧹 Coverage-Reports entfernt" static: ## Generate Static Files ./bin/generate-static.php # Projektstatus status: ## Zeigt Container-Status @echo "Aktuelles Projekt: $(PROJECT_NAME)" @echo "Umgebung: $(ENV)" doctor: ## Prüft ob Komponenten installiert sind @echo "🔍 Prüfe Voraussetzungen..." @which docker > /dev/null || echo "❌ Docker fehlt" @which ansible-playbook > /dev/null || echo "❌ Ansible fehlt" @test -f .env || echo "⚠️ .env-Datei fehlt" # Helfer: Automatische Zielübersicht help: ## Zeigt diese Hilfe an @echo "" @echo "🛠 Verfügbare Make-Befehle:" @grep -E '^[a-zA-Z_-]+:.*?## ' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}' @echo "" console: ## Run console commands (Usage: make console ARGS="command arguments") docker exec -it php php console.php $(ARGS) composer: ## Use Composer docker compose exec php composer $(ARGS) fix-perms: ## Fix permissions sudo chown -R $(USER):$(USER) . cs: @$(MAKE) composer ARGS="cs" cs-fix-file: ## Fix code style for a specific file docker compose exec -e PHP_CS_FIXER_IGNORE_ENV=1 php ./vendor/bin/php-cs-fixer fix $(subst \,/,$(FILE)) cs-fix: ## Fix code style for all PHP files docker compose exec -e PHP_CS_FIXER_IGNORE_ENV=1 php ./vendor/bin/php-cs-fixer fix phpstan: ## Run PHPStan static analysis @$(MAKE) composer ARGS="phpstan" phpstan-baseline: ## Generate PHPStan baseline @$(MAKE) composer ARGS="phpstan-baseline" setup-ssh: ## SSH-Schlüssel korrekt einrichten mkdir -p ~/.ssh cp /mnt/c/Users/Mike/.ssh/test.michaelschiemer.de ~/.ssh/staging chmod 600 ~/.ssh/staging @echo "SSH-Schlüssel für Staging korrekt eingerichtet" fix-ssh-perms: ## Korrigiert SSH-Schlüsselberechtigungen (veraltet) chmod 600 /mnt/c/Users/Mike/.ssh/test.michaelschiemer.de @echo "SSH-Schlüsselberechtigungen korrigiert" health: ansible-playbook ansible/check.yml # Ansible Konfiguration ANSIBLE_INVENTORY=ansible/inventory/hosts.ini PLAYBOOK_DIR=ansible/playbooks/deploy TAGS= .PHONY: dev staging production setup-server check # Deployment-Ziele dev: ## Lokales Deployment (Development) ansible-playbook -i $(ANSIBLE_INVENTORY) $(PLAYBOOK_DIR)/dev.yml --ask-become-pass $(if $(TAGS),--tags="$(TAGS)",) staging: ## Staging-Deployment ansible-playbook -i $(ANSIBLE_INVENTORY) $(PLAYBOOK_DIR)/staging.yml $(if $(TAGS),--tags="$(TAGS)",) production: ## Produktions-Deployment ansible-playbook -i $(ANSIBLE_INVENTORY) $(PLAYBOOK_DIR)/production.yml $(if $(TAGS),--tags="$(TAGS)",) setup-server: ## Server-Grundkonfiguration ansible-playbook -i $(ANSIBLE_INVENTORY) ansible/setup.yml $(if $(LIMIT),--limit="$(LIMIT)",) $(if $(TAGS),--tags="$(TAGS)",) check: ## Serververbindung prüfen ansible -i $(ANSIBLE_INVENTORY) all -m ping $(if $(LIMIT),--limit="$(LIMIT)",) # Beispielaufrufe: # make staging TAGS="deploy,check" # make setup-server LIMIT="staging" TAGS="docker" # Production Update Commands update-production: ## Update PHP files on production server @echo "🚀 Updating PHP files on production server..." @cd deployment && make application ENV=production @echo "✅ Production update completed" restart-production: ## Restart production PHP container only @echo "🔄 Restarting production PHP container..." @ssh -i ~/.ssh/production deploy@94.16.110.151 "cd /var/www/html && docker compose restart php" @echo "✅ Production PHP container restarted" deploy-production-quick: ## Quick production deployment via deployment Makefile @echo "⚡ Quick production deployment..." @cd deployment && make deploy-quick ENV=production @echo "✅ Quick production deployment completed" status-production: ## Check production deployment status @echo "📊 Checking production status..." @cd deployment && make status ENV=production logs-production: ## Show production logs @echo "📋 Showing production logs..." @cd deployment && make logs-prod-php logs-staging: ## Show staging-app container logs via SSH (container stdout/stderr) @echo "📋 Showing staging-app container logs..." @ssh -i ~/.ssh/production deploy@94.16.110.151 "cd ~/deployment/stacks/staging && docker compose logs -f staging-app" logs-staging-php: ## Show PHP application logs from staging-app (log files) @echo "📋 Showing PHP application logs from staging-app..." @ssh -i ~/.ssh/production deploy@94.16.110.151 "docker exec -i staging-app tail -f /var/www/html/storage/logs/*.log 2>/dev/null || docker exec -i staging-app ls -la /var/www/html/storage/logs/ 2>/dev/null || echo 'Log directory /var/www/html/storage/logs/ not accessible'" # SSL Certificate Management (PHP Framework Integration) ssl-init: ## Initialize Let's Encrypt certificates @echo "🔒 Initializing SSL certificates..." docker exec php php console.php ssl:init ssl-init-staging: ## Initialize Let's Encrypt certificates (Staging/Testing) @echo "🔒 Initializing SSL certificates (Staging Mode)..." @echo "💡 Hint: Set LETSENCRYPT_STAGING=1 in .env for staging mode" docker exec php php console.php ssl:init ssl-test: ## Test SSL configuration @echo "🔍 Testing SSL configuration..." docker exec php php console.php ssl:test ssl-renew: ## Manually renew certificates @echo "🔄 Renewing SSL certificates..." docker exec php php console.php ssl:renew ssl-status: ## Check certificate status and expiry @echo "📋 Certificate status:" docker exec php php console.php ssl:status ssl-backup: ## Backup Let's Encrypt certificates @echo "💾 Backing up SSL certificates..." @mkdir -p backups docker run --rm \ -v certbot-conf:/etc/letsencrypt \ -v $(PWD)/backups:/backup \ alpine tar czf /backup/letsencrypt-$(shell date +%Y%m%d-%H%M%S).tar.gz /etc/letsencrypt @echo "✅ Backup created in backups/" push-staging: ## Pusht den aktuellen Stand nach origin/staging git push origin HEAD:staging .PHONY: up down build restart logs ps phpinfo deploy setup clean clean-coverage status fix-ssh-perms setup-ssh test test-coverage test-coverage-html test-unit test-framework test-domain test-watch test-parallel test-profile test-filter security-check security-audit-json security-check-prod update-production restart-production deploy-production-quick status-production logs-production logs-staging logs-staging-php ssl-init ssl-init-staging ssl-test ssl-renew ssl-status ssl-backup push-staging