-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
489 lines (460 loc) · 20.5 KB
/
Copy pathTaskfile.yml
File metadata and controls
489 lines (460 loc) · 20.5 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# Taskfile.yml
version: '3'
vars:
NAMESPACE: ms
QDRANT_COLLECTION: homel_memory
POSTGRES_POD:
sh: kubectl get pod -n {{.NAMESPACE}} -l app=postgres -o jsonpath='{.items[0].metadata.name}' || echo ""
INGRESS_HTTP_PORT: '30080'
INGRESS_HTTPS_PORT: '30443'
BACKUP_DIR: './backups'
# Tooling image used by every ephemeral ops Job (migrate/backup/restore/export).
# Local minikube default (loaded by `task build`, no registry pull needed).
# For GHCR set: ghcr.io/<owner>/<repo>/tooling:latest
TOOLING_IMAGE: ghcr.io/homel-dev/memory-steward/tooling:latest
tasks:
default:
desc: List all tasks
cmds:
- task --list
# ============================================================================
# 🚀 LIFECYCLE
# ============================================================================
up:
desc: "Full Bootstrap: Bootstrap -> Deploy -> Wait -> Init -> Verify"
cmds:
- minikube start --driver=docker --cpus=8 --memory=16384 --gpus all
- task: k8s:deploy
- task: ingress:setup
- task: k8s:wait
- task: db:init
- task: verify:health
down:
desc: "Teardown: Delete Namespace (DELETES PVCs in the namespace too)"
cmds:
- kubectl delete namespace {{.NAMESPACE}} --ignore-not-found
status:all:
desc: "Status"
cmds:
- kubectl get pods -n {{.NAMESPACE}}
- kubectl get svc -n {{.NAMESPACE}}
nuke:
desc: "🔥 DESTRUCTIVE: Delete this namespace and its Persistent Volumes"
prompt: "This will destroy all memory and logs in namespace '{{.NAMESPACE}}'. Continue?"
cmds:
- kubectl delete namespace {{.NAMESPACE}} --ignore-not-found
- kubectl delete pvc --all -n {{.NAMESPACE}} --ignore-not-found --force --grace-period=0
# ============================================================================
# 🐳 BUILD
# ============================================================================
build:
desc: "Build images into Minikube (incl. tooling)"
cmds:
- minikube image build -t homel/embeddings:dev ./components/embeddings
- minikube image build -t homel/memory-router:dev ./components/memory_router
- minikube image build -t homel/memory-steward:dev ./components/memory_steward
- minikube image build -t homel/memory-steward-mcp:dev ./components/memory_steward_mcp
- minikube image build -t homel/memory-steward-list:dev ./components/memory_steward_list
- minikube image build -t homel/tooling:dev -f ./components/tooling/Dockerfile .
# ============================================================================
# ☸️ KUBERNETES OPERATIONS
# ============================================================================
k8s:deploy:
desc: "Apply manifests"
cmds:
- kubectl apply -f k8s/namespace.yaml
- kubectl apply -f k8s/
- kubectl apply -f k8s/tooling/
- kubectl apply -f k8s/backup/
- kubectl apply -f k8s/vector/
- kubectl apply -f k8s/grafana/
k8s:wait:
desc: "Block until core services are Ready"
cmds:
- kubectl rollout status -n {{.NAMESPACE}} statefulset/postgres --timeout=120s
- kubectl rollout status -n {{.NAMESPACE}} statefulset/qdrant --timeout=120s
- kubectl rollout status -n {{.NAMESPACE}} deployment/memory-router --timeout=120s
- kubectl rollout status -n {{.NAMESPACE}} deployment/memory-steward --timeout=120s
k8s:restart:
desc: "Restart all core services"
cmds:
- kubectl rollout restart -n {{.NAMESPACE}} deployment/memory-router
- kubectl rollout restart -n {{.NAMESPACE}} deployment/memory-steward
- kubectl rollout restart -n {{.NAMESPACE}} deployment/memory-steward-mcp
- kubectl rollout restart -n {{.NAMESPACE}} deployment/memory-steward-list
- kubectl rollout restart -n {{.NAMESPACE}} deployment/open-webui
# ============================================================================
# 💾 DATA & STATE (INIT) -- non-destructive
# ============================================================================
db:init:
desc: "Idempotent init: migrations (tooling Job) + ensure Qdrant collection"
cmds:
- task: migrate:up
- task: db:init-qdrant
db:init-qdrant:
internal: true
cmds:
- |
set -e
kubectl delete job tooling-qdrant-init -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-qdrant-init, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 180
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: qdrant-init
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["bash","/opt/tooling/init_qdrant.sh","ensure"]
env:
- {name: QDRANT_URL, value: "http://qdrant:6333"}
- {name: QDRANT_COLLECTION, value: "{{.QDRANT_COLLECTION}}"}
EOF
kubectl wait --for=condition=complete job/tooling-qdrant-init -n {{.NAMESPACE}} --timeout=120s \
|| { kubectl logs job/tooling-qdrant-init -n {{.NAMESPACE}}; exit 1; }
kubectl logs job/tooling-qdrant-init -n {{.NAMESPACE}}
db:reset:
desc: "🔥 DESTRUCTIVE: drop & rebuild Postgres schema + Qdrant collection"
prompt: "This ERASES all Postgres tables and the Qdrant collection. Continue?"
cmds:
- |
set -e
kubectl delete job tooling-reset -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-reset, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 180
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: reset
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["sh","-c","psql -v ON_ERROR_STOP=1 -c 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;' && bash /opt/tooling/init_qdrant.sh delete"]
env:
- {name: PGHOST, value: "postgres"}
- {name: PGUSER, value: "homel"}
- {name: PGPASSWORD, value: "homel"}
- {name: PGDATABASE, value: "homel"}
- {name: QDRANT_URL, value: "http://qdrant:6333"}
- {name: QDRANT_COLLECTION, value: "{{.QDRANT_COLLECTION}}"}
EOF
kubectl wait --for=condition=complete job/tooling-reset -n {{.NAMESPACE}} --timeout=180s \
|| { kubectl logs job/tooling-reset -n {{.NAMESPACE}}; exit 1; }
kubectl logs job/tooling-reset -n {{.NAMESPACE}}
- task: db:init
db:shell:
desc: "Open PSQL shell"
interactive: true
cmds:
- kubectl exec -it -n {{.NAMESPACE}} {{.POSTGRES_POD}} -- psql -U homel -d homel
# ============================================================================
# 🧬 MIGRATIONS (ephemeral tooling Job; tracked in schema_migrations)
# ============================================================================
migrate:up:
desc: "Apply pending migrations via an ephemeral tooling Job"
cmds:
- |
set -e
kubectl delete job tooling-migrate -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-migrate, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 300
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: migrate
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["bash","/opt/tooling/migrate.sh","up"]
env:
- {name: PGHOST, value: "postgres"}
- {name: PGUSER, value: "homel"}
- {name: PGPASSWORD, value: "homel"}
- {name: PGDATABASE, value: "homel"}
EOF
kubectl wait --for=condition=complete job/tooling-migrate -n {{.NAMESPACE}} --timeout=180s \
|| { echo "--- logs ---"; kubectl logs job/tooling-migrate -n {{.NAMESPACE}}; exit 1; }
kubectl logs job/tooling-migrate -n {{.NAMESPACE}}
migrate:status:
desc: "Show applied vs pending migrations (ephemeral tooling Job)"
cmds:
- |
set -e
kubectl delete job tooling-migstatus -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-migstatus, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 120
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: migstatus
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["bash","/opt/tooling/migrate.sh","status"]
env:
- {name: PGHOST, value: "postgres"}
- {name: PGUSER, value: "homel"}
- {name: PGPASSWORD, value: "homel"}
- {name: PGDATABASE, value: "homel"}
EOF
kubectl wait --for=condition=complete job/tooling-migstatus -n {{.NAMESPACE}} --timeout=120s >/dev/null
kubectl logs job/tooling-migstatus -n {{.NAMESPACE}}
# ============================================================================
# 🗄️ BACKUP (ephemeral tooling Job -> backups PVC)
# ============================================================================
backup:
desc: "Back up Postgres + Qdrant to the backups PVC"
cmds:
- |
set -e
kubectl delete job tooling-backup -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-backup, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 600
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: backup
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["bash","/opt/tooling/backup.sh"]
env:
- {name: PGHOST, value: "postgres"}
- {name: PGUSER, value: "homel"}
- {name: PGPASSWORD, value: "homel"}
- {name: PGDATABASE, value: "homel"}
- {name: QDRANT_URL, value: "http://qdrant:6333"}
- {name: QDRANT_COLLECTION, value: "{{.QDRANT_COLLECTION}}"}
volumeMounts: [{name: backups, mountPath: /backups}]
volumes:
- name: backups
persistentVolumeClaim: {claimName: backups}
EOF
kubectl wait --for=condition=complete job/tooling-backup -n {{.NAMESPACE}} --timeout=600s \
|| { kubectl logs job/tooling-backup -n {{.NAMESPACE}}; exit 1; }
kubectl logs job/tooling-backup -n {{.NAMESPACE}}
# ============================================================================
# ♻️ RESTORE (ephemeral tooling Job from backups PVC, then forward-migrate)
# ============================================================================
restore:
desc: "DR restore. Usage: task restore DUMP=<f.dump> [SNAPSHOT=<f.snapshot>]"
cmds:
- |
set -e
[ -n "{{.DUMP}}" ] || { echo "usage: task restore DUMP=<pgfile.dump> [SNAPSHOT=<file.snapshot>]"; exit 1; }
kubectl delete job tooling-restore -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-restore, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 600
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: restore
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["bash","/opt/tooling/restore.sh"]
env:
- {name: PGHOST, value: "postgres"}
- {name: PGUSER, value: "homel"}
- {name: PGPASSWORD, value: "homel"}
- {name: PGDATABASE, value: "homel"}
- {name: QDRANT_URL, value: "http://qdrant:6333"}
- {name: QDRANT_COLLECTION, value: "{{.QDRANT_COLLECTION}}"}
- {name: DUMP_FILE, value: "{{.DUMP}}"}
- {name: SNAPSHOT_FILE, value: "{{.SNAPSHOT}}"}
volumeMounts: [{name: backups, mountPath: /backups}]
volumes:
- name: backups
persistentVolumeClaim: {claimName: backups}
EOF
kubectl wait --for=condition=complete job/tooling-restore -n {{.NAMESPACE}} --timeout=600s \
|| { kubectl logs job/tooling-restore -n {{.NAMESPACE}}; exit 1; }
kubectl logs job/tooling-restore -n {{.NAMESPACE}}
- task: migrate:up
- echo "✅ Restore + forward-migrate complete. Run 'task migrate:status' to confirm head."
# ============================================================================
# 📤 EXPORT (ephemeral tooling Job -> backups PVC + stdout)
# ============================================================================
export:memory:
desc: "Export memory dataset. e.g. task export:memory -- --level rich --since 30"
cmds:
- |
set -e
ARGS="{{.CLI_ARGS}}"; [ -n "$ARGS" ] || ARGS="--level standard"
kubectl delete job tooling-export -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-export, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 600
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: export
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["sh","-c","mkdir -p /backups/exports && python3 /opt/tooling/memory_export.py $ARGS | tee /backups/exports/memory-\$(date +%Y%m%d-%H%M%S).json"]
env:
- {name: POSTGRES_USER, value: "homel"}
- {name: POSTGRES_PASSWORD, value: "homel"}
- {name: POSTGRES_DB, value: "homel"}
- {name: EXPORT_PG_HOST, value: "postgres"}
- {name: QDRANT_URL, value: "http://qdrant:6333"}
- {name: QDRANT_COLLECTION, value: "{{.QDRANT_COLLECTION}}"}
volumeMounts: [{name: backups, mountPath: /backups}]
volumes:
- name: backups
persistentVolumeClaim: {claimName: backups}
EOF
kubectl wait --for=condition=complete job/tooling-export -n {{.NAMESPACE}} --timeout=600s \
|| { kubectl logs job/tooling-export -n {{.NAMESPACE}}; exit 1; }
echo "✅ Export written to backups PVC at /backups/exports/. Pull locally with: task export:fetch"
export:fetch:
desc: "Copy the newest export from the backups PVC to {{.BACKUP_DIR}}/exports locally"
cmds:
- |
set -e
mkdir -p {{.BACKUP_DIR}}/exports
kubectl delete job tooling-fetch -n {{.NAMESPACE}} --ignore-not-found >/dev/null 2>&1 || true
cat <<EOF | kubectl apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata: {name: tooling-fetch, namespace: {{.NAMESPACE}}}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 120
template:
spec:
serviceAccountName: memory-tooling
restartPolicy: Never
containers:
- name: fetch
image: {{.TOOLING_IMAGE}}
imagePullPolicy: IfNotPresent
command: ["sh","-c","cat \$(ls -1t /backups/exports/*.json | head -1)"]
volumeMounts: [{name: backups, mountPath: /backups}]
volumes:
- name: backups
persistentVolumeClaim: {claimName: backups}
EOF
kubectl wait --for=condition=complete job/tooling-fetch -n {{.NAMESPACE}} --timeout=120s >/dev/null
OUT="{{.BACKUP_DIR}}/exports/memory-export-$(date +%Y%m%d-%H%M%S).json"
kubectl logs job/tooling-fetch -n {{.NAMESPACE}} > "$OUT"
echo "✅ $OUT"
# ============================================================================
# ✅ VERIFICATION
# ============================================================================
verify:health:
desc: "Check healthz endpoints"
cmds:
- kubectl exec -n {{.NAMESPACE}} deploy/memory-router -- curl -sSf http://localhost:8080/healthz
- kubectl exec -n {{.NAMESPACE}} deploy/memory-router -- curl -sSf http://memory-steward:8090/healthz
verify:amp:
desc: "Smoke-test AMP artifact write + exact Router retrieval (no LLM required)"
cmds:
- |
kubectl exec -i -n {{.NAMESPACE}} deploy/memory-router -- python - <<'PY'
import hashlib
import json
import requests
project_id = "amp-smoke"
payload = {"smoke": "amp", "version": 1}
canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
content_hash = hashlib.sha256(canonical.encode("utf-8")).hexdigest()
outcome = requests.post(
"http://memory-steward:8090/v1/agent/outcomes",
json={
"outcome_id": "amp-smoke-v1",
"project_id": project_id,
"objective": "AMP deterministic artifact smoke test",
"result": "artifact generated",
"admit_knowledge": False,
"repository_state": {"repository": "amp-smoke", "revision": "smoke-v1"},
"artifacts": [{
"artifact_type": "repository_ir",
"schema_version": "1",
"producer_type": "analyzer",
"producer_name": "amp-smoke",
"producer_version": "1",
"content_hash": content_hash,
"payload": payload,
"provenance": [{"kind": "smoke_test"}],
}],
},
timeout=30,
)
outcome.raise_for_status()
retrieved = requests.post(
"http://localhost:8080/v1/context/retrieve",
headers={"X-Project-ID": project_id},
json={
"artifact_selectors": [{
"artifact_type": "repository_ir",
"repository": "amp-smoke",
"revision": "smoke-v1",
}]
},
timeout=30,
)
retrieved.raise_for_status()
body = retrieved.json()
artifacts = body.get("agent_reference", [])
assert artifacts, body
assert artifacts[0]["payload"] == payload, body
assert artifacts[0]["content_hash"] == content_hash, body
print(json.dumps({
"ok": True,
"outcome": outcome.json(),
"context_request_id": body["context_request_id"],
"artifact_id": artifacts[0]["id"],
}, indent=2))
PY
logs:router:
desc: "Tail Router Logs"
cmds:
- kubectl logs -n {{.NAMESPACE}} -l app=memory-router -f
logs:steward:
desc: "Tail Steward Logs"
cmds:
- kubectl logs -n {{.NAMESPACE}} -l app=memory-steward -f