Docker-Compose Dateien vereinfachen und redundante entfernen

This commit is contained in:
stefan
2025-09-02 15:08:28 +02:00
parent 4fcb4bb48c
commit abd2543caf
9 changed files with 314 additions and 2014 deletions
+124 -155
View File
@@ -8,9 +8,23 @@
.PHONY: clients-up clients-down clients-restart clients-logs
.PHONY: prod-up prod-down prod-restart prod-logs
.PHONY: infrastructure-up infrastructure-down infrastructure-logs
.PHONY: dev-tools-up dev-tools-down status health-check
.PHONY: dev-tools-up dev-tools-down status health-check logs shell env-template dev-info clean-all build-service build-client
.ONESHELL:
# Choose docker compose CLI (prefers new plugin)
DOCKER_COMPOSE_PLUGIN := $(shell docker compose version >/dev/null 2>&1 && echo 1 || echo 0)
DOCKER_COMPOSE_LEGACY := $(shell command -v docker-compose >/dev/null 2>&1 && echo 1 || echo 0)
ifeq ($(DOCKER_COMPOSE_PLUGIN),1)
COMPOSE = docker compose
else ifeq ($(DOCKER_COMPOSE_LEGACY),1)
COMPOSE = docker-compose
else
COMPOSE = docker compose
endif
# Default target
.DEFAULT_GOAL := help
help: ## Show this help message
@echo "Meldestelle Docker Development Commands"
@echo "======================================"
@@ -20,163 +34,124 @@ help: ## Show this help message
# Development Workflow Commands
# ===================================================================
dev-up: ## Start full development environment (infrastructure + services + clients)
@echo "🚀 Starting full development environment..."
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
up -d
dev-up: ## Start development environment (single compose)
@echo "🚀 Starting development environment..."
$(COMPOSE) -f docker-compose.yml up -d
@$(MAKE) dev-info
dev-down: ## Stop full development environment
@echo "🛑 Stopping full development environment..."
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
down
dev-down: ## Stop development environment
@echo "🛑 Stopping development environment..."
$(COMPOSE) -f docker-compose.yml down
dev-restart: ## Restart full development environment
@$(MAKE) dev-down
@$(MAKE) dev-up
dev-logs: ## Show logs for all development services
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
logs -f
$(COMPOSE) -f docker-compose.yml logs -f
# ===================================================================
# Layer-specific Commands
# ===================================================================
infrastructure-up: ## Start only infrastructure services (postgres, redis, etc.)
infrastructure-up: ## Start only infrastructure services (postgres, redis, keycloak, consul)
@echo "🏗️ Starting infrastructure services..."
docker-compose -f docker-compose.yml up -d
$(COMPOSE) -f docker-compose.yml up -d
@echo "✅ Infrastructure services started"
@echo "📊 Grafana: http://localhost:3000 (admin/admin)"
@echo "🔍 Prometheus: http://localhost:9090"
@echo "🗄️ PostgreSQL: localhost:5432"
@echo "🔴 Redis: localhost:6379"
@echo "🗄️ PostgreSQL: localhost:5432"
@echo "🔴 Redis: localhost:6379"
@echo "🔐 Keycloak: http://localhost:8180"
@echo "🧭 Consul: http://localhost:8500"
infrastructure-down: ## Stop infrastructure services
docker-compose -f docker-compose.yml down
$(COMPOSE) -f docker-compose.yml down
infrastructure-logs: ## Show infrastructure logs
docker-compose -f docker-compose.yml logs -f
$(COMPOSE) -f docker-compose.yml logs -f
services-up: ## Start application services (requires infrastructure)
@echo "⚙️ Starting application services..."
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
up -d
@echo "✅ Application services started"
@echo "🚪 API Gateway: http://localhost:8080"
@echo "🔐 Auth Server: http://localhost:8081"
@echo "📊 Monitoring Server: http://localhost:8083"
@echo "🏓 Ping Service: http://localhost:8082"
services-up: ## Start application services (simplified: base compose only)
@echo "⚙️ Starting services (simplified setup using docker-compose.yml only)..."
$(COMPOSE) -f docker-compose.yml up -d
@echo "✅ Services started (based on docker-compose.yml)"
services-down: ## Stop application services
docker-compose -f docker-compose.services.yml down
services-down: ## Stop application services (simplified)
$(COMPOSE) -f docker-compose.yml down
services-restart: ## Restart application services
@$(MAKE) services-down
@$(MAKE) services-up
services-logs: ## Show application services logs
docker-compose -f docker-compose.services.yml logs -f
services-logs: ## Show application services logs (simplified)
$(COMPOSE) -f docker-compose.yml logs -f
clients-up: ## Start client applications (requires services)
@echo "💻 Starting client applications..."
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
up -d
@echo "✅ Client applications started"
@echo "🌐 Web App: http://localhost:3001"
clients-up: ## Start client applications (simplified using base compose)
@echo "💻 Starting client applications (simplified)..."
$(COMPOSE) -f docker-compose.yml up -d
@echo "✅ Client applications started (docker-compose.yml)"
clients-down: ## Stop client applications
docker-compose -f docker-compose.clients.yml down
clients-down: ## Stop client applications (simplified)
$(COMPOSE) -f docker-compose.yml down
clients-restart: ## Restart client applications
@$(MAKE) clients-down
@$(MAKE) clients-up
clients-logs: ## Show client application logs
docker-compose -f docker-compose.clients.yml logs -f
clients-logs: ## Show client application logs (simplified)
$(COMPOSE) -f docker-compose.yml logs -f
# ===================================================================
# Production Commands
# ===================================================================
prod-up: ## Start production environment
@echo "🚀 Starting production environment..."
prod-up: ## Start production environment (simplified)
@echo "🚀 Starting production environment (simplified)..."
@echo "⚠️ Make sure environment variables are properly set!"
docker-compose \
-f docker-compose.prod.yml \
-f docker-compose.services.yml \
up -d
@echo "✅ Production environment started"
$(COMPOSE) -f docker-compose.yml up -d
@echo "✅ Production environment started (docker-compose.yml)"
prod-down: ## Stop production environment
docker-compose \
-f docker-compose.prod.yml \
-f docker-compose.services.yml \
down
prod-down: ## Stop production environment (simplified)
$(COMPOSE) -f docker-compose.yml down
prod-restart: ## Restart production environment
@$(MAKE) prod-down
@$(MAKE) prod-up
prod-logs: ## Show production logs
docker-compose \
-f docker-compose.prod.yml \
-f docker-compose.services.yml \
logs -f
prod-logs: ## Show production logs (simplified)
$(COMPOSE) -f docker-compose.yml logs -f
# ===================================================================
# Development Tools
# ===================================================================
dev-tools-up: ## Start development tools (pgAdmin, Redis Commander)
@echo "🔧 Starting development tools..."
docker-compose --profile dev-tools up -d pgadmin redis-commander
@echo "✅ Development tools started"
@echo "🐘 pgAdmin: http://localhost:5050 (admin@meldestelle.dev/admin)"
@echo "🔴 Redis Commander: http://localhost:8081"
dev-tools-up: ## Info: development tool containers were removed (use local tools instead)
@echo "️ Development tool containers are not part of the simplified setup."
@echo "Use your local tools instead (e.g., pgAdmin, TablePlus, DBeaver, RedisInsight)."
@echo "Connection hints:"
@echo " PostgreSQL: localhost:5432 (user/password per .env or defaults)"
@echo " Redis: localhost:6379"
@echo " Consul: http://localhost:8500"
@echo " Keycloak: http://localhost:8180"
dev-tools-down: ## Stop development tools
docker-compose --profile dev-tools down pgadmin redis-commander
dev-tools-down: ## Info: nothing to stop for dev tools in simplified setup
@echo "️ No dev-tool containers to stop in the simplified setup."
# ===================================================================
# Build and Maintenance Commands
# ===================================================================
build: ## Build all custom Docker images
@echo "🔨 Building all custom Docker images..."
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
build --no-cache
build: ## Build all custom Docker images (simplified)
@echo "🔨 Building all custom Docker images (using docker-compose.yml)..."
$(COMPOSE) -f docker-compose.yml build --no-cache
build-service: ## Build specific service (usage: make build-service SERVICE=auth-server)
@test -n "$(SERVICE)" || (echo "❌ SERVICE parameter required. Usage: make build-service SERVICE=auth-server"; exit 1)
@echo "🔨 Building $(SERVICE)..."
docker-compose \
-f docker-compose.services.yml \
build --no-cache $(SERVICE)
$(COMPOSE) -f docker-compose.yml build --no-cache $(SERVICE)
build-client: ## Build specific client (usage: make build-client CLIENT=web-app)
@test -n "$(CLIENT)" || (echo "❌ CLIENT parameter required. Usage: make build-client CLIENT=web-app"; exit 1)
@echo "🔨 Building $(CLIENT)..."
docker-compose \
-f docker-compose.clients.yml \
build --no-cache $(CLIENT)
$(COMPOSE) -f docker-compose.yml build --no-cache $(CLIENT)
clean: ## Clean up Docker resources
@echo "🧹 Cleaning up Docker resources..."
@@ -196,28 +171,32 @@ clean-all: ## Clean up all Docker resources (including images)
status: ## Show status of all containers
@echo "📊 Container Status:"
docker-compose \
-f docker-compose.yml \
-f docker-compose.services.yml \
-f docker-compose.clients.yml \
ps
$(COMPOSE) -f docker-compose.yml ps
health-check: ## Check health of all services
health-check: ## Check health of core infrastructure services
@echo "🏥 Health Check Results:"
@echo "========================"
@curl -s http://localhost:8080/actuator/health | jq -r '"API Gateway: " + .status' || echo "API Gateway: ❌ Not accessible"
@curl -s http://localhost:8081/actuator/health | jq -r '"Auth Server: " + .status' || echo "Auth Server: ❌ Not accessible"
@curl -s http://localhost:8082/actuator/health | jq -r '"Ping Service: " + .status' || echo "Ping Service: ❌ Not accessible"
@curl -s http://localhost:8083/actuator/health | jq -r '"Monitoring Server: " + .status' || echo "Monitoring Server: ❌ Not accessible"
@curl -s http://localhost:3001/health | grep -q healthy && echo "Web App: UP" || echo "Web App: ❌ Not accessible"
@$(COMPOSE) ps
@echo "-- Postgres --"
@$(COMPOSE) exec -T postgres pg_isready -U meldestelle -d meldestelle >/dev/null \
&& echo "PostgreSQL: ✅ Ready" || echo "PostgreSQL: ❌ Not ready"
@echo "-- Redis --"
@$(COMPOSE) exec -T redis redis-cli ping | grep -q PONG \
&& echo "Redis: ✅ PONG" || echo "Redis: ❌ Not responding"
@echo "-- Consul --"
@curl -sf http://localhost:8500/v1/status/leader >/dev/null \
&& echo "Consul: ✅ Leader elected" || echo "Consul: ❌ Not accessible"
@echo "-- Keycloak --"
@curl -sf http://localhost:8180/health/ready >/dev/null \
&& echo "Keycloak: ✅ Ready" || echo "Keycloak: ❌ Not accessible"
logs: ## Show logs for specific service (usage: make logs SERVICE=auth-server)
@test -n "$(SERVICE)" || (echo "❌ SERVICE parameter required. Usage: make logs SERVICE=auth-server"; exit 1)
docker-compose logs -f $(SERVICE)
logs: ## Show logs for specific service (usage: make logs SERVICE=postgres)
@test -n "$(SERVICE)" || (echo "❌ SERVICE parameter required. Usage: make logs SERVICE=postgres"; exit 1)
$(COMPOSE) logs -f $(SERVICE)
shell: ## Open shell in specific container (usage: make shell SERVICE=auth-server)
@test -n "$(SERVICE)" || (echo "❌ SERVICE parameter required. Usage: make shell SERVICE=auth-server"; exit 1)
docker-compose exec $(SERVICE) sh
shell: ## Open shell in specific container (usage: make shell SERVICE=postgres)
@test -n "$(SERVICE)" || (echo "❌ SERVICE parameter required. Usage: make shell SERVICE=postgres"; exit 1)
$(COMPOSE) exec $(SERVICE) sh
# ===================================================================
# Testing Commands
@@ -250,64 +229,54 @@ dev-info: ## Show development environment information
@echo "🚀 Meldestelle Development Environment Ready!"
@echo "============================================="
@echo ""
@echo "📊 Monitoring & Management:"
@echo " Grafana: http://localhost:3000 (admin/admin)"
@echo " Prometheus: http://localhost:9090"
@echo "🧭 Service Discovery:"
@echo " Consul: http://localhost:8500"
@echo ""
@echo "🔧 Application Services:"
@echo " API Gateway: http://localhost:8080"
@echo " Auth Server: http://localhost:8081"
@echo " Monitoring: http://localhost:8083"
@echo " Ping Service: http://localhost:8082"
@echo ""
@echo "💻 Client Applications:"
@echo " Web App: http://localhost:3001"
@echo "🔐 Authentication:"
@echo " Keycloak: http://localhost:8180 (admin/admin by default)"
@echo ""
@echo "🗄️ Infrastructure:"
@echo " PostgreSQL: localhost:5432 (meldestelle/meldestelle)"
@echo " PostgreSQL: localhost:5432 (default user: meldestelle)"
@echo " Redis: localhost:6379"
@echo " Keycloak: http://localhost:8180"
@echo ""
@echo "🔧 Development Tools (optional):"
@echo " make dev-tools-up to start pgAdmin & Redis Commander"
@echo "️ Tips: Use 'make health-check' to verify services, and 'make logs SERVICE=postgres' for logs."
@echo ""
env-template: ## Create .env template file
@echo "📝 Creating .env template..."
@cat > .env.template << 'EOF'
# ===================================================================
# Meldestelle Environment Variables Template
# Copy to .env and customize for your environment
# ===================================================================
@cat > .env.template <<-'EOF'
# ===================================================================
# Meldestelle Environment Variables Template
# Copy to .env and customize for your environment
# ===================================================================
# Database Configuration
POSTGRES_USER=meldestelle
POSTGRES_PASSWORD=meldestelle
POSTGRES_DB=meldestelle
# Database Configuration
POSTGRES_USER=meldestelle
POSTGRES_PASSWORD=meldestelle
POSTGRES_DB=meldestelle
# Redis Configuration
REDIS_PASSWORD=
# Redis Configuration
REDIS_PASSWORD=
# Keycloak Configuration
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=admin
KC_DB=postgres
KC_DB_URL=jdbc:postgresql://postgres:5432/keycloak
KC_DB_USERNAME=meldestelle
KC_DB_PASSWORD=meldestelle
# Keycloak Configuration
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=admin
KC_DB=postgres
KC_DB_URL=jdbc:postgresql://postgres:5432/keycloak
KC_DB_USERNAME=meldestelle
KC_DB_PASSWORD=meldestelle
# JWT Configuration
JWT_SECRET=meldestelle-auth-secret-key-change-in-production
JWT_EXPIRATION=86400
# JWT Configuration
JWT_SECRET=meldestelle-auth-secret-key-change-in-production
JWT_EXPIRATION=86400
# Monitoring Configuration
GF_SECURITY_ADMIN_USER=admin
GF_SECURITY_ADMIN_PASSWORD=admin
# Monitoring Configuration
GF_SECURITY_ADMIN_USER=admin
GF_SECURITY_ADMIN_PASSWORD=admin
# Production URLs (for production environment)
KC_HOSTNAME=auth.meldestelle.at
GRAFANA_HOSTNAME=monitor.meldestelle.at
PROMETHEUS_HOSTNAME=metrics.meldestelle.at
EOF
# Production URLs (for production environment)
KC_HOSTNAME=auth.meldestelle.at
GRAFANA_HOSTNAME=monitor.meldestelle.at
PROMETHEUS_HOSTNAME=metrics.meldestelle.at
EOF
@echo "✅ .env.template created"