-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjustfile
More file actions
458 lines (339 loc) · 12 KB
/
Copy pathjustfile
File metadata and controls
458 lines (339 loc) · 12 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
# =======
# Configs
# =======
set shell := ["bash", "-uc"]
set dotenv-load
# -----
# Paths
# -----
local_dir := "local/"
init_sql_path := join(local_dir, "init.sql")
engine_db_path := join(local_dir, env_var("ENGINE_DB"))
stage_db_path := join(local_dir, env_var("STAGE_DB"))
secure_stage_db_path := join(local_dir, env_var("SECURE_STAGE_DB"))
graphs_mart_db_path := join(local_dir, env_var("GRAPHS_MART_DB"))
analytics_mart_db_path := join(local_dir, env_var("ANALYTICS_MART_DB"))
# --------
# Datasets
# --------
ds_dsn_url := "https://www.kaggle.com/datasets/andreagarritano/deezer-social-networks"
ds_msdsl_url := "https://www.kaggle.com/datasets/undefinenull/million-song-dataset-spotify-lastfm"
ds_dd_url := "https://huggingface.co/datasets/ShreyaR/DepressionDetection"
ds_dd_monitor_url := "https://huggingface.co/datasets/joangaes/depression"
# ======
# Common
# ======
default:
just -l
check binary:
@echo -n "Checking {{binary}}... "
@which {{binary}} >/dev/null && test -x $(which {{binary}}) \
|| (echo "failed ({{binary}} not found)"; exit 1)
@echo ok
check-dlctl:
just check dlctl
check-duckdb:
just check duckdb
check-curl:
just check curl
check-terraform:
just check terraform
check-docker:
just check docker
check-psql:
just check psql
check-pgloader:
just check pgloader
confirm:
#!/bin/bash
while true; do
read -p "Are you sure? [y/N] " yn
yn=${yn:-N}
case $yn in
[Yy]*) exit 0;;
[Nn]*) exit 1;;
esac
done
# ===========
# Development
# ===========
check-dev:
just check git
just check uv
just check nbdime
just check nbstripout
setup-dev:
just check git || sudo apt install -y git
just check uv || curl -LsSf https://astral.sh/uv/install.sh | sh
just check nbdime || nbdime config-git --enable --global
just check nbstripout || nbstripout --install --global
# ========
# DuckLake
# ========
check-init-sql:
test -r {{init_sql_path}} || just generate-init-sql
generate-init-sql: check-dlctl
dlctl tools generate-init-sql --path {{init_sql_path}}
lakehouse: check-duckdb check-init-sql
duckdb -init {{init_sql_path}} {{engine_db_path}}
# ====================
# GraphRAG with KùzuDB
# ====================
graphrag-ingest: check-dlctl
dlctl ingest dataset {{ds_dsn_url}}
dlctl ingest dataset {{ds_msdsl_url}}
graphrag-transform:
dlctl transform -m "+marts.graphs.music_taste"
graphrag-export:
dlctl export dataset graphs "music_taste"
graphrag-load:
dlctl graph load --overwrite "music_taste"
graphrag-tl: graphrag-transform graphrag-export graphrag-load
graphrag-etl: graphrag-ingest graphrag-tl
graphrag-embeddings: check-dlctl
dlctl graph compute embeddings "music_taste" -d 256 -b 9216 -e 5
dlctl graph reindex "music_taste"
graphrag: check-dlctl
dlctl graph rag "music_taste" -i
graphrag-all: graphrag-etl graphrag-embeddings graphrag
# =============================
# Economic Competition Networks
# =============================
econ-compnet-ingest: check-dlctl
dlctl ingest dataset -t "atlas" "The Atlas of Economic Complexity"
econ-compnet-transform: check-dlctl
dlctl transform -m "+marts.graphs.econ_comp"
econ-compnet-export: check-dlctl
dlctl export dataset graphs "econ_comp"
econ-compnet-load: check-dlctl
dlctl graph load --overwrite "econ_comp"
econ-compnet-tl: econ-compnet-transform econ-compnet-export econ-compnet-load
econ-compnet-etl: econ-compnet-ingest econ-compnet-tl
econ-compnet-scoring: check-dlctl
dlctl graph compute con-score "econ_comp" "Country" "CompetesWith"
econ-compnet-all: econ-compnet-etl econ-compnet-scoring
# ===================================================
# MLOps: A/B Testing with MLflow, Kafka, and DuckLake
# ===================================================
# ----
# ETL
# ----
mlops-ingest: check-dlctl
dlctl ingest dataset {{ds_dd_url}}
dlctl ingest dataset {{ds_dd_monitor_url}}
mlops-transform: check-dlctl
dlctl transform -m "+stage.depression_detection"
mlops-tl: mlops-transform
mlops-etl: mlops-ingest mlops-tl
# --------
# Training
# --------
mlops-train-logreg-tfidf: check-dlctl
dlctl ml train "dd" --method "logreg" --features "tfidf"
mlops-train-logreg-embeddings: check-dlctl
dlctl ml train "dd" --method "logreg" --features "embeddings"
mlops-train-logreg: mlops-train-logreg-tfidf mlops-train-logreg-embeddings
mlops-train-xgboost-tfidf: check-dlctl
dlctl ml train "dd" --method "xgboost" --features "tfidf"
mlops-train-xgboost-embeddings: check-dlctl
dlctl ml train "dd" --method "xgboost" --features "embeddings"
mlops-train-xgboost: mlops-train-xgboost-tfidf mlops-train-xgboost-embeddings
mlops-train: mlops-train-logreg mlops-train-xgboost
# --------------
# ETL + Training
# --------------
mlops-all: mlops-etl mlops-train
# ------
# Server
# ------
mlops-serve: check-dlctl
dlctl ml server
mlops_test_inference_payload := '''
{
"models": [
{
"name": "dd_logreg_tfidf",
"version": "latest"
},
{
"name": "dd_xgboost_embeddings",
"version": "latest"
}
],
"data": "hello twitter i m on a one week leave from school bc i have depression how are you all d",
"log_to_lakehouse": true
}
'''
mlops-test-inference: check-curl
curl -f -X POST "http://localhost:8000/inference" \
-H "Content-Type: application/json" \
-d '{{mlops_test_inference_payload}}'
@echo
curl -f -X GET "http://localhost:8000/inference/logs/flush"
mlops-test-feedback uuid feedback: check-curl
curl -f -X PATCH "http://localhost:8000/inference" \
-H "Content-Type: application/json" \
-d '{"inference_uuid": "{{uuid}}", "feedback": {{feedback}}}'
curl -f -X GET "http://localhost:8000/inference/logs/flush"
# ----------
# Monitoring
# ----------
mlops-simulate-inference: check-dlctl
dlctl ml simulate "dd" \
--sample-fraction 0.01 \
--model-uri "models:/dd_xgboost_embeddings/latest" \
--model-uri "models:/dd_logreg_tfidf/latest"
mlops-monitor-compute: check-dlctl
dlctl ml monitor compute "dd" \
--model-uri "models:/dd_xgboost_embeddings/latest" \
--model-uri "models:/dd_logreg_tfidf/latest"
mlops-monitor-plot: check-dlctl
dlctl ml monitor plot "dd" \
--model-uri "models:/dd_xgboost_embeddings/latest" \
--model-uri "models:/dd_logreg_tfidf/latest"
# ==============
# Data Lab Infra
# ==============
docker_shared_context := "docker-shared"
# -------------
# Config Checks
# -------------
infra-config-check-foundation: check-terraform
@echo -n "Checking foundation configs... "
@test -f infra/foundation/terraform.tfvars \
|| (echo "failed (terraform.tfvars: not found)"; exit 1)
@echo ok
infra-config-check-platform: check-terraform
@echo -n "Checking platform configs... "
@test -f infra/platform/terraform.tfvars \
|| (echo "failed: terraform.tfvars not found"; exit 1)
@test -f infra/platform/state.config \
|| (echo "state.config: not found"; exit 2)
@echo ok
infra-config-check-services: check-docker
@echo -n "Checking {{docker_shared_context}} docker context... "
@docker context ls --format "{{{{.Name}}" | grep -q '^{{docker_shared_context}}$' \
|| (echo "failed: {{docker_shared_context}} docker context not configured"; exit 1)
@echo ok
infra-config-check-all: infra-config-check-foundation \
infra-config-check-platform \
infra-config-check-services
# ---------------
# Initializations
# ---------------
infra-foundation-init: infra-config-check-foundation
terraform -chdir=infra/foundation init
infra-platform-init: infra-config-check-platform
terraform -chdir=infra/platform init -backend-config=state.config
infra-init: infra-foundation-init infra-platform-init
# ------------
# Provisioning
# ------------
infra-provision-foundation: infra-config-check-foundation
terraform -chdir=infra/foundation apply
infra-provision-platform: infra-config-check-platform
terraform -chdir=infra/platform apply
infra-provision-services: infra-config-check-services
terraform -chdir=infra/services/gitlab apply
docker -c {{docker_shared_context}} compose -p datalab -f infra/services/docker/compose.yml up -d
infra-provision-all: infra-provision-foundation \
infra-provision-platform \
infra-provision-services
infra-provision-local:
docker compose -p datalab -f infra/services/docker/compose.yml --profile dev up -d
# -----------
# Destruction
# -----------
infra-destroy-foundation:
terraform -chdir=infra/foundation destroy
infra-destroy-platform:
terraform -chdir=infra/platform destroy
infra-destroy-services: confirm
docker -c {{docker_shared_context}} compose -p datalab -f infra/services/docker/compose.yml down
terraform -chdir=infra/services/gitlab destroy -auto-approve
infra-destroy-all: infra-destroy-services \
infra-destroy-platform \
infra-destroy-foundation
infra-destroy-local:
docker compose -p datalab -f infra/services/docker/compose.yml --profile dev down
# ---------
# Utilities
# ---------
infra-show-tf-credentials layer:
@[[ " foundation platform " == *" {{layer}} "* ]] \
|| (echo "{{layer}}: invalid layer"; exit 1)
@terraform -chdir=infra/{{layer}} output -json \
| jq -r 'to_entries[] \
| select(.value.sensitive==true) \
| "\(.key) = \(.value.value)"'
infra-show-credentials: infra-config-check-all
@echo
@echo "=========="
@echo "Foundation"
@echo "=========="
@just infra-show-tf-credentials foundation
@echo
@echo "========"
@echo "Platform"
@echo "========"
@just infra-show-tf-credentials platform
# ====================================================
# Migrating DuckLake Catalog From SQLite to PostgreSQL
# ====================================================
migrate_lakehouse_fix_script := "./scripts/ducklake_sqlite_to_postgres_fix.sql"
test-lakehouse-catalog-connection: check-psql
#!/bin/bash
export PGHOST=$PSQL_CATALOG_HOST
export PGPORT=$PSQL_CATALOG_PORT
export PGDATABASE=$PSQL_CATALOG_DB
export PGUSER=$PSQL_CATALOG_USER
export PGPASSWORD=$PSQL_CATALOG_PASSWORD
echo -n "Testing lakehouse catalog connection... "
if output=$(psql -c '\q' 2>&1); then
echo "ok"
else
echo "failed"
echo $output
fi
migrate-lakehouse-catalog catalog: check-pgloader test-lakehouse-catalog-connection
#!/bin/bash
set -e
export PGHOST=$PSQL_CATALOG_HOST
export PGPORT=$PSQL_CATALOG_PORT
export PGDATABASE=$PSQL_CATALOG_DB
export PGUSER=$PSQL_CATALOG_USER
export PGPASSWORD=$PSQL_CATALOG_PASSWORD
case "{{catalog}}" in
"stage")
sqlite_db_path="{{stage_db_path}}"
psql_schema="$PSQL_CATALOG_STAGE_SCHEMA"
;;
"secure_stage")
sqlite_db_path="{{secure_stage_db_path}}"
psql_schema="$PSQL_CATALOG_SECURE_STAGE_SCHEMA"
;;
"graphs_mart")
sqlite_db_path="{{graphs_mart_db_path}}"
psql_schema="$PSQL_CATALOG_GRAPHS_MART_SCHEMA"
;;
"analytics_mart")
sqlite_db_path="{{analytics_mart_db_path}}"
psql_schema="$PSQL_CATALOG_ANALYTICS_MART_SCHEMA"
;;
esac
echo "Migrating {{catalog}} catalog from SQLite to PostgreSQL..."
psql_conn_str="postgresql://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE"
psql -c "CREATE SCHEMA IF NOT EXISTS $psql_schema"
pgloader --set search_path="'$psql_schema'" $sqlite_db_path $psql_conn_str
PGOPTIONS="--search-path=$psql_schema" psql -f "{{migrate_lakehouse_fix_script}}"
migrate-lakehouse-catalog-all:
just migrate-lakehouse-catalog stage
just migrate-lakehouse-catalog secure_stage
just migrate-lakehouse-catalog graphs_mart
just migrate-lakehouse-catalog analytics_mart
# ======
# Global
# ======
global-etl: graphrag-etl econ-compnet-etl mlops-etl
global-ingest: graphrag-ingest econ-compnet-ingest mlops-ingest
global-tl: graphrag-tl econ-compnet-tl mlops-tl