-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
195 lines (172 loc) · 6.69 KB
/
Makefile
File metadata and controls
195 lines (172 loc) · 6.69 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# ===========================================================================
# OpenHomeLab — Makefile
# ===========================================================================
#
# Usage:
# make up SERVICE=ai/comfyui # start one service
# make down SERVICE=ai/comfyui # stop one service
# make logs SERVICE=llm/open-webui # tail logs
# make restart SERVICE=media/immich # restart a service
# make pull SERVICE=ai/comfyui # pull latest images
# make up-category CATEGORY=ai # start all services in a category
# make up-all # start every service
# make down-all # stop every service
# make pull-all # pull all latest images
# make status # list running containers
# make gpu # show GPU status
# make network # create the shared homelab network
# ===========================================================================
SERVICES_DIR := services
COMPOSE := docker compose
.PHONY: up down logs restart pull status gpu network \
up-category down-category \
up-all down-all pull-all \
help
# ---------------------------------------------------------------------------
# Single service targets — require SERVICE=<category>/<name>
# ---------------------------------------------------------------------------
## Start a single service: make up SERVICE=ai/comfyui
up:
ifndef SERVICE
$(error SERVICE is required. Usage: make up SERVICE=ai/comfyui)
endif
@echo "Starting $(SERVICE)..."
@cd $(SERVICES_DIR)/$(SERVICE) && $(COMPOSE) up -d
@echo "Done. Logs: make logs SERVICE=$(SERVICE)"
## Stop a single service: make down SERVICE=ai/comfyui
down:
ifndef SERVICE
$(error SERVICE is required. Usage: make down SERVICE=ai/comfyui)
endif
@echo "Stopping $(SERVICE)..."
@cd $(SERVICES_DIR)/$(SERVICE) && $(COMPOSE) down
@echo "Done."
## Tail logs: make logs SERVICE=llm/open-webui
logs:
ifndef SERVICE
$(error SERVICE is required. Usage: make logs SERVICE=llm/open-webui)
endif
@cd $(SERVICES_DIR)/$(SERVICE) && $(COMPOSE) logs -f
## Restart a service: make restart SERVICE=media/immich
restart:
ifndef SERVICE
$(error SERVICE is required. Usage: make restart SERVICE=media/immich)
endif
@cd $(SERVICES_DIR)/$(SERVICE) && $(COMPOSE) restart
## Pull latest images for a service: make pull SERVICE=ai/comfyui
pull:
ifndef SERVICE
$(error SERVICE is required. Usage: make pull SERVICE=ai/comfyui)
endif
@cd $(SERVICES_DIR)/$(SERVICE) && $(COMPOSE) pull
# ---------------------------------------------------------------------------
# Category targets — require CATEGORY=<category>
# ---------------------------------------------------------------------------
## Start all services in a category: make up-category CATEGORY=ai
up-category:
ifndef CATEGORY
$(error CATEGORY is required. Usage: make up-category CATEGORY=ai)
endif
@for dir in $(SERVICES_DIR)/$(CATEGORY)/*/; do \
if [ -f "$${dir}docker-compose.yml" ]; then \
echo "Starting $${dir}..."; \
(cd $${dir} && $(COMPOSE) up -d) || echo "WARNING: $${dir} failed to start"; \
fi \
done
@echo "Done starting category: $(CATEGORY)"
## Stop all services in a category: make down-category CATEGORY=ai
down-category:
ifndef CATEGORY
$(error CATEGORY is required. Usage: make down-category CATEGORY=ai)
endif
@for dir in $(SERVICES_DIR)/$(CATEGORY)/*/; do \
if [ -f "$${dir}docker-compose.yml" ]; then \
echo "Stopping $${dir}..."; \
(cd $${dir} && $(COMPOSE) down) || true; \
fi \
done
@echo "Done stopping category: $(CATEGORY)"
# ---------------------------------------------------------------------------
# Global targets
# ---------------------------------------------------------------------------
## Start all services
up-all:
@echo "Starting all services..."
@for dir in $(SERVICES_DIR)/*/*/; do \
if [ -f "$${dir}docker-compose.yml" ]; then \
echo "Starting $${dir}..."; \
(cd $${dir} && $(COMPOSE) up -d) || echo "WARNING: $${dir} failed to start"; \
fi \
done
@echo "All services started."
## Stop all services
down-all:
@echo "Stopping all services..."
@for dir in $(SERVICES_DIR)/*/*/; do \
if [ -f "$${dir}docker-compose.yml" ]; then \
echo "Stopping $${dir}..."; \
(cd $${dir} && $(COMPOSE) down) || true; \
fi \
done
@echo "All services stopped."
## Pull latest images for all services
pull-all:
@echo "Pulling latest images..."
@for dir in $(SERVICES_DIR)/*/*/; do \
if [ -f "$${dir}docker-compose.yml" ]; then \
echo "Pulling $${dir}..."; \
(cd $${dir} && $(COMPOSE) pull) || echo "WARNING: $${dir} pull failed"; \
fi \
done
@echo "All images updated."
# ---------------------------------------------------------------------------
# Status / monitoring
# ---------------------------------------------------------------------------
## Show all running containers
status:
@docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | sort
## Show GPU allocation
gpu:
@nvidia-smi
@echo ""
@echo "=== Containers with GPU access ==="
@docker ps --filter "label=gpu=true" --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"
# ---------------------------------------------------------------------------
# Network setup
# ---------------------------------------------------------------------------
## Create the shared homelab Docker network (run once)
network:
@docker network inspect homelab >/dev/null 2>&1 \
&& echo "Network 'homelab' already exists." \
|| (docker network create homelab && echo "Network 'homelab' created.")
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
## Show this help message
help:
@echo ""
@echo "OpenHomeLab — Makefile targets"
@echo "================================"
@echo ""
@echo "Single service (requires SERVICE=<category>/<name>):"
@echo " make up SERVICE=ai/comfyui"
@echo " make down SERVICE=ai/comfyui"
@echo " make logs SERVICE=llm/open-webui"
@echo " make restart SERVICE=media/immich"
@echo " make pull SERVICE=ai/comfyui"
@echo ""
@echo "Category (requires CATEGORY=<name>):"
@echo " make up-category CATEGORY=ai"
@echo " make down-category CATEGORY=ai"
@echo ""
@echo "Global:"
@echo " make up-all Start all services"
@echo " make down-all Stop all services"
@echo " make pull-all Pull latest images"
@echo " make status Show running containers"
@echo " make gpu Show GPU allocation"
@echo " make network Create homelab Docker network"
@echo ""
@echo "Available categories: ai, llm, media, home, monitoring, network, dev, utilities, infra"
@echo ""
.DEFAULT_GOAL := help