-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
349 lines (322 loc) Β· 12.4 KB
/
Makefile
File metadata and controls
349 lines (322 loc) Β· 12.4 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# Simplified Janitor Makefile
# Replaces complex Terraform infrastructure with simple persistent GPU instance
# Load environment variables from .env
ifneq (,$(wildcard ./.env))
include .env
export
endif
# Default values
AWS_REGION ?= us-east-1
AWS_PROFILE ?= default
SSH_KEY_PATH ?= ~/.ssh/janitor-key
# =============================================================================
# Setup Commands (One-time)
# =============================================================================
.PHONY: setup-supabase
setup-supabase:
@echo "π Setting up Supabase for Janitor Agent..."
@chmod +x scripts/setup-supabase.sh
@./scripts/setup-supabase.sh
# =============================================================================
# Instance Management
# =============================================================================
.PHONY: start
start:
@echo "π Starting GPU instance with full Janitor setup..."
@chmod +x scripts/start-instance.sh
@./scripts/start-instance.sh
.PHONY: stop
stop:
@echo "ποΈ Terminating GPU instance (complete cleanup)..."
@chmod +x scripts/stop-instance.sh
@./scripts/stop-instance.sh
.PHONY: pause
pause:
@echo "βΈοΈ Pausing GPU instance (preserve for restart)..."
@chmod +x scripts/pause-instance.sh
@./scripts/pause-instance.sh
.PHONY: deploy
deploy:
@echo "π Hot deploying Janitor code (zero downtime, atomic swap)..."
@chmod +x scripts/deploy.sh
@./scripts/deploy.sh
.PHONY: rollback
rollback:
ifdef RELEASE
@echo "β©οΈ Rolling back to release: $(RELEASE)"
@chmod +x scripts/rollback.sh
@./scripts/rollback.sh "$(RELEASE)"
else
@echo "π Available releases for rollback:"
@chmod +x scripts/rollback.sh
@./scripts/rollback.sh
endif
.PHONY: ssh
ssh:
@echo "π Connecting to GPU instance via SSH..."
@if [ -f ".env" ]; then \
source .env && \
INSTANCE_ID=$$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=janitor-gpu-instance" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION" 2>/dev/null || echo "None"); \
if [ "$$INSTANCE_ID" != "None" ] && [ "$$INSTANCE_ID" != "null" ]; then \
PUBLIC_IP=$$(aws ec2 describe-instances \
--instance-ids "$$INSTANCE_ID" \
--query "Reservations[0].Instances[0].PublicIpAddress" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION"); \
echo "π Instance: $$INSTANCE_ID"; \
echo "π IP: $$PUBLIC_IP"; \
echo "π Key: $$SSH_KEY_PATH"; \
echo ""; \
echo "π Connecting to ubuntu@$$PUBLIC_IP..."; \
echo "π‘ Tip: Run 'nvidia-smi' or 'docker run --rm --gpus all nvidia/cuda:12.6.0-base-ubuntu22.04 nvidia-smi' to test GPU"; \
echo ""; \
ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP"; \
else \
echo "β No running instance found"; \
echo "π‘ Start one with: make start"; \
fi; \
else \
echo "β .env file not found"; \
fi
# =============================================================================
# Monitoring Commands
# =============================================================================
.PHONY: logs
logs:
@echo "π Streaming Janitor agent logs (press Ctrl+C to exit)..."
@chmod +x scripts/show-logs.sh
@./scripts/show-logs.sh
.PHONY: status
status:
@echo "π Checking Janitor service status..."
@if [ -f ".env" ]; then \
source .env && \
INSTANCE_ID=$$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=janitor-gpu-instance" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION" 2>/dev/null || echo "None"); \
if [ "$$INSTANCE_ID" != "None" ] && [ "$$INSTANCE_ID" != "null" ]; then \
PUBLIC_IP=$$(aws ec2 describe-instances \
--instance-ids "$$INSTANCE_ID" \
--query "Reservations[0].Instances[0].PublicIpAddress" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION"); \
echo "π Instance: $$INSTANCE_ID"; \
echo "π IP: $$PUBLIC_IP"; \
echo ""; \
SERVICE_STATUS=$$(ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP" 'sudo systemctl is-active janitor-mastra' 2>/dev/null || echo "unknown"); \
if [ "$$SERVICE_STATUS" = "active" ]; then \
echo "β
Service is running"; \
ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP" 'sudo systemctl status janitor-mastra --no-pager --lines=5' || true; \
elif [ "$$SERVICE_STATUS" = "inactive" ]; then \
echo "β οΈ Service is not running"; \
echo "π§ To start: ssh -i $$SSH_KEY_PATH ubuntu@$$PUBLIC_IP 'sudo systemctl start janitor-mastra'"; \
echo "π To check logs: make logs"; \
else \
echo "β Service status unknown - checking full status..."; \
ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP" 'sudo systemctl status janitor-mastra --no-pager' || true; \
fi; \
else \
echo "β No running instance found"; \
fi; \
else \
echo "β .env file not found"; \
fi
.PHONY: restart
restart:
@echo "π Restarting Janitor service..."
@if [ -f ".env" ]; then \
source .env && \
INSTANCE_ID=$$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=janitor-gpu-instance" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION" 2>/dev/null || echo "None"); \
if [ "$$INSTANCE_ID" != "None" ] && [ "$$INSTANCE_ID" != "null" ]; then \
PUBLIC_IP=$$(aws ec2 describe-instances \
--instance-ids "$$INSTANCE_ID" \
--query "Reservations[0].Instances[0].PublicIpAddress" \
--output text \
--profile "$$AWS_PROFILE" \
--region "$$AWS_REGION"); \
echo "π Instance: $$INSTANCE_ID"; \
echo "π IP: $$PUBLIC_IP"; \
echo ""; \
ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP" 'sudo systemctl restart janitor-mastra'; \
echo "β³ Waiting for service to start..."; \
sleep 5; \
SERVICE_STATUS=$$(ssh -i "$$SSH_KEY_PATH" -o StrictHostKeyChecking=no ubuntu@"$$PUBLIC_IP" 'sudo systemctl is-active janitor-mastra' 2>/dev/null || echo "failed"); \
if [ "$$SERVICE_STATUS" = "active" ]; then \
echo "β
Service restarted successfully"; \
else \
echo "β Service failed to start"; \
echo "π Check logs with: make logs"; \
fi; \
else \
echo "β No running instance found"; \
fi; \
else \
echo "β .env file not found"; \
fi
# =============================================================================
# Usage Commands
# =============================================================================
.PHONY: prompt
prompt:
@echo "π€ Sending prompt to Mastra server..."
ifdef FILE
@echo "π Resolving prompt file: $(FILE)"
@# Try direct path first
@if [ -f "$(FILE)" ]; then \
echo "β
Found: $(FILE)"; \
chmod +x scripts/send-prompt.sh; \
./scripts/send-prompt.sh "$$(cat $(FILE))"; \
elif [ -f "prompts/$(FILE)" ]; then \
echo "β
Found: prompts/$(FILE)"; \
chmod +x scripts/send-prompt.sh; \
./scripts/send-prompt.sh "$$(cat prompts/$(FILE))"; \
elif [ -f "prompts/$(FILE).md" ]; then \
echo "β
Found: prompts/$(FILE).md"; \
chmod +x scripts/send-prompt.sh; \
./scripts/send-prompt.sh "$$(cat prompts/$(FILE).md)"; \
else \
echo "β Error: Prompt file not found"; \
echo ""; \
echo "Searched locations:"; \
echo " - $(FILE)"; \
echo " - prompts/$(FILE)"; \
echo " - prompts/$(FILE).md"; \
echo ""; \
echo "π‘ Create a prompt file:"; \
echo " cat > prompts/$(FILE).md << 'EOF'"; \
echo " # PROMPT"; \
echo " Add your detailed instructions here"; \
echo " "; \
echo " # REPOS"; \
echo " - worker-basic"; \
echo " - worker-template"; \
echo " EOF"; \
echo ""; \
echo "π Available prompt files:"; \
if [ -d "prompts" ]; then \
ls -la prompts/ 2>/dev/null | grep -E '\.(md|txt)$$' || echo " (no .md or .txt files found)"; \
else \
echo " (prompts/ folder does not exist)"; \
fi; \
exit 1; \
fi
else ifndef PROMPT
@echo "β Error: PROMPT parameter or FILE parameter required"
@echo ""
@echo "Usage:"
@echo " make prompt PROMPT=\"validate RunPod/worker-basic\""
@echo " make prompt FILE=\"validate\" # Uses prompts/validate.md"
@echo " make prompt FILE=\"prompts/custom.md\" # Direct path"
@echo ""
@echo "π Markdown prompts:"
@echo " make prompt FILE=validate # Uses default validation prompt"
@echo ""
@echo "π Create custom prompts in markdown:"
@echo " cat > prompts/my-task.md << 'EOF'"
@echo " # PROMPT"
@echo " Add comprehensive logging with structured output"
@echo " "
@echo " # REPOS"
@echo " - worker-basic"
@echo " - worker-template"
@echo " EOF"
@echo ""
@echo "Legacy format (still supported):"
@echo " make prompt PROMPT=\"validate worker-basic, worker-template\""
@exit 1
else
@chmod +x scripts/send-prompt.sh
@./scripts/send-prompt.sh "$(PROMPT)"
endif
.PHONY: query-results
query-results:
@echo "π Querying validation results from Supabase..."
@chmod +x scripts/query-results.sh
@./scripts/query-results.sh
.PHONY: continue
continue:
@echo "π Managing incomplete validation runs..."
@chmod +x scripts/continue.sh
@./scripts/continue.sh
.PHONY: cancel
cancel:
@echo "β Cancelling validation run..."
@chmod +x scripts/cancel.sh
@./scripts/cancel.sh "$(RUN_ID)"
# =============================================================================
# Local Development
# =============================================================================
.PHONY: install
install:
@echo "π¦ Installing dependencies..."
@cd packages/janitor-agent && npm install
.PHONY: test-local
test-local:
@echo "π§ͺ Running local tests..."
@cd packages/janitor-agent && npm run start:local
.PHONY: check-build
check-build:
@echo "π Running pre-deployment build checks..."
@chmod +x scripts/check-build.sh
@./scripts/check-build.sh
# =============================================================================
# Help
# =============================================================================
.PHONY: help
help:
@echo "π€ Simplified Janitor Agent Commands"
@echo "===================================="
@echo ""
@echo "Setup (one-time):"
@echo " make setup-supabase - Set up Supabase database"
@echo " make start - Launch GPU instance"
@echo " make deploy - Hot deploy janitor code (zero downtime)"
@echo ""
@echo "Daily usage:"
@echo " make prompt PROMPT=\"validate RunPod/worker-basic\" - Send validation request"
@echo " make query-results - Check recent results"
@echo " make query-results RUN_ID=your-run-id - Check specific run"
@echo " make query-results REPO=worker-basic - Check repository results"
@echo " make continue - View/continue incomplete runs"
@echo " make cancel RUN_ID=your-run-id - Cancel specific incomplete run"
@echo ""
@echo "Instance management:"
@echo " make start - Start GPU instance (reuses stopped or creates new)"
@echo " make stop - Terminate instance (complete cleanup, no costs)"
@echo " make pause - Pause instance (preserve for quick restart)"
@echo " make deploy - Hot deploy code (zero downtime, atomic swap)"
@echo " make rollback - List releases or rollback (RELEASE=timestamp)"
@echo " make ssh - SSH into running instance for debugging"
@echo ""
@echo "Monitoring commands:"
@echo " make status - Check service status"
@echo " make logs - Stream real-time logs"
@echo " make restart - Restart the service"
@echo ""
@echo "Development:"
@echo " make install - Install dependencies locally"
@echo " make test-local - Run local tests"
@echo " make check-build - Verify TypeScript compilation before deploy"
@echo ""
@echo "Examples:"
@echo " make prompt PROMPT=\"please validate these repos: RunPod/worker-basic\""
@echo " make prompt PROMPT=\"validate worker-template and create a PR if fixes needed\""
@echo " make deploy # Hot deploy latest code"
@echo " make rollback # List available releases"
@echo " make rollback RELEASE=20250103-143022 # Rollback to specific release"
.DEFAULT_GOAL := help