-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (80 loc) · 2.66 KB
/
Makefile
File metadata and controls
88 lines (80 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Docker Infrastructure Makefile
# Automatically discovers services with compose.yml files
# Find all directories with compose.yml files
SERVICES := $(shell find . -maxdepth 2 -name "compose.yml" -exec dirname {} \; | sed 's|^\./||' | sort)
# Default target
.PHONY: help
help:
@echo "🐳 Docker Infrastructure Services"
@echo ""
@echo "Available services:"
@for service in $(SERVICES); do \
echo " $$service"; \
done
@echo ""
@echo "Commands:"
@echo " make <service> Start a service (e.g., make postgres)"
@echo " make stop-<service> Stop a service (e.g., make stop-postgres)"
@echo " make logs-<service> View service logs (e.g., make logs-postgres)"
@echo " make restart-<service> Restart a service (e.g., make restart-postgres)"
@echo " make clean Stop all running services"
@echo " make help Show this help message"
@echo ""
# Service start targets
.PHONY: $(SERVICES)
$(SERVICES):
@if [ ! -f "$@/compose.yml" ]; then \
echo "❌ Error: $@/compose.yml not found"; \
exit 1; \
fi
@echo "🚀 Starting $@..."
@cd $@ && docker compose up -d --build
@echo "✅ $@ started successfully"
# Service stop targets
.PHONY: $(addprefix stop-,$(SERVICES))
$(addprefix stop-,$(SERVICES)):
$(eval SERVICE=$(patsubst stop-%,%,$@))
@if [ ! -f "$(SERVICE)/compose.yml" ]; then \
echo "❌ Error: $(SERVICE)/compose.yml not found"; \
exit 1; \
fi
@echo "🛑 Stopping $(SERVICE)..."
@cd $(SERVICE) && docker compose down
@echo "✅ $(SERVICE) stopped successfully"
# Service logs targets
.PHONY: $(addprefix logs-,$(SERVICES))
$(addprefix logs-,$(SERVICES)):
$(eval SERVICE=$(patsubst logs-%,%,$@))
@if [ ! -f "$(SERVICE)/compose.yml" ]; then \
echo "❌ Error: $(SERVICE)/compose.yml not found"; \
exit 1; \
fi
@echo "📋 Showing logs for $(SERVICE)..."
@cd $(SERVICE) && docker compose logs -f
# Service restart targets
.PHONY: $(addprefix restart-,$(SERVICES))
$(addprefix restart-,$(SERVICES)):
$(eval SERVICE=$(patsubst restart-%,%,$@))
@if [ ! -f "$(SERVICE)/compose.yml" ]; then \
echo "❌ Error: $(SERVICE)/compose.yml not found"; \
exit 1; \
fi
@echo "🔄 Restarting $(SERVICE)..."
@cd $(SERVICE) && docker compose restart
@echo "✅ $(SERVICE) restarted successfully"
# Stop all services
.PHONY: clean
clean:
@echo "🧹 Stopping all services..."
@for service in $(SERVICES); do \
if [ -f "$$service/compose.yml" ]; then \
echo "🛑 Stopping $$service..."; \
cd $$service && docker compose down && cd ..; \
fi; \
done
@echo "✅ All services stopped"
# Show running containers
.PHONY: status
status:
@echo "📊 Docker containers status:"
@docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"