feat: add infrastructure management commands to Makefile

Enhance Makefile with infrastructure service management:

**New Commands:**
- `network-create`: Create Docker networks (automa-proxy, automa-monitoring)
- `network-remove`: Remove Docker networks
- `infra-up`: Start all infrastructure services (Caddy, monitoring, etc.)
- `infra-down`: Stop all infrastructure services
- `infra-status`: Check status of infrastructure services
- `up`: Start infrastructure + all application services
- `down`: Stop all services + infrastructure

**Command Structure:**
```
make network-create  # Setup networks first
make infra-up        # Start infrastructure
make all-up          # Start applications
# Or simply: make up  (does all above)
```

**Infrastructure Services Managed:**
1. Caddy (reverse proxy)
2. Monitoring stack (Prometheus, Grafana, Loki, Promtail, cAdvisor)
3. Watchtower (auto-updates)
4. Duplicati (backups)
5. Fail2ban (security)

**Improvements:**
- Hierarchical service management (infra → apps)
- Graceful shutdown order (apps → infra)
- Network prerequisites automatically checked
- Enhanced help text with categorized commands
- Consistent error handling

Follows Unix philosophy: compose simple commands for complex workflows.

Refs: #4
This commit is contained in:
m1ngsama 2026-01-19 16:00:00 +08:00
parent 9b709b25b4
commit e1e5019097

View file

@ -4,6 +4,7 @@
.PHONY: help all status up down logs restart clean minecraft teamspeak nextcloud
.PHONY: health health-minecraft health-teamspeak health-nextcloud
.PHONY: backup backup-minecraft backup-teamspeak backup-nextcloud backup-list backup-cleanup
.PHONY: network-create network-remove infra-up infra-down infra-status
# Default target
help:
@ -11,11 +12,22 @@ help:
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Setup Commands:"
@echo " network-create Create Docker networks"
@echo " network-remove Remove Docker networks"
@echo ""
@echo "Infrastructure Commands:"
@echo " infra-up Start infrastructure (Caddy, Monitoring, etc.)"
@echo " infra-down Stop infrastructure"
@echo " infra-status Show infrastructure status"
@echo ""
@echo "Global Commands:"
@echo " help Show this help message"
@echo " status Show status of all services"
@echo " all-up Start all services"
@echo " all-down Stop all services"
@echo " up Start infrastructure + all services"
@echo " down Stop all services + infrastructure"
@echo " all-up Start all services only"
@echo " all-down Stop all services only"
@echo " health Run health checks on all services"
@echo " backup Backup all services"
@echo " backup-list List available backups"
@ -211,3 +223,65 @@ backup-list:
backup-cleanup:
@./bin/backup.sh cleanup
# ============================================================================
# Network Setup
# ============================================================================
network-create:
@echo "Creating Docker networks..."
@docker network create automa-proxy 2>/dev/null || echo " automa-proxy already exists"
@docker network create automa-monitoring 2>/dev/null || echo " automa-monitoring already exists"
@echo "✓ Networks ready"
network-remove:
@echo "Removing Docker networks..."
@docker network rm automa-proxy automa-monitoring 2>/dev/null || echo " Networks already removed"
@echo "✓ Networks removed"
# ============================================================================
# Infrastructure Targets
# ============================================================================
infra-up: network-create
@echo "Starting infrastructure services..."
@cd infrastructure/caddy && docker compose up -d
@cd infrastructure/monitoring && docker compose up -d
@cd infrastructure/watchtower && docker compose up -d
@cd infrastructure/duplicati && docker compose up -d
@cd infrastructure/fail2ban && docker compose up -d
@echo "✓ Infrastructure started"
infra-down:
@echo "Stopping infrastructure services..."
@cd infrastructure/fail2ban && docker compose down || true
@cd infrastructure/duplicati && docker compose down || true
@cd infrastructure/watchtower && docker compose down || true
@cd infrastructure/monitoring && docker compose down || true
@cd infrastructure/caddy && docker compose down || true
@echo "✓ Infrastructure stopped"
infra-status:
@echo "=== Infrastructure Status ==="
@echo ""
@echo "Caddy:"
@cd infrastructure/caddy && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Monitoring:"
@cd infrastructure/monitoring && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Watchtower:"
@cd infrastructure/watchtower && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Duplicati:"
@cd infrastructure/duplicati && docker compose ps 2>/dev/null || echo " Not running"
@echo ""
@echo "Fail2ban:"
@cd infrastructure/fail2ban && docker compose ps 2>/dev/null || echo " Not running"
# ============================================================================
# Full Stack Management
# ============================================================================
up: infra-up all-up
@echo "✓ Full stack started"
down: all-down infra-down
@echo "✓ Full stack stopped"