40 lines
1.1 KiB
Plaintext
40 lines
1.1 KiB
Plaintext
|
|
#!/usr/bin/env nu
|
||
|
|
# start-dev-stack.nu — Bring up the stratum docker-compose dev stack and wait for health.
|
||
|
|
|
||
|
|
def wait-for-http [url: string, label: string, max_secs: int]: nothing -> nothing {
|
||
|
|
let start = (date now)
|
||
|
|
loop {
|
||
|
|
let elapsed = ((date now) - $start | into int) / 1_000_000_000
|
||
|
|
if ($elapsed > $max_secs) {
|
||
|
|
error make { msg: $"[$label] not ready after [$max_secs]s" }
|
||
|
|
}
|
||
|
|
let r = (do { ^curl -sf $url } | complete)
|
||
|
|
if ($r.exit_code == 0) {
|
||
|
|
print $"[$label] ready"
|
||
|
|
break
|
||
|
|
}
|
||
|
|
sleep 2sec
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
def main []: nothing -> nothing {
|
||
|
|
print "Starting stratum dev stack..."
|
||
|
|
|
||
|
|
let up = (do {
|
||
|
|
^docker compose -f docker-compose.dev.yml up -d
|
||
|
|
} | complete)
|
||
|
|
|
||
|
|
if ($up.exit_code != 0) {
|
||
|
|
error make { msg: $"docker compose up failed:\n($up.stderr)" }
|
||
|
|
}
|
||
|
|
|
||
|
|
print "Containers started, waiting for services..."
|
||
|
|
|
||
|
|
wait-for-http "http://localhost:8100/health" "SurrealDB" 30
|
||
|
|
wait-for-http "http://localhost:5000/v2/" "Zot OCI" 30
|
||
|
|
|
||
|
|
print "Dev stack ready"
|
||
|
|
print " SurrealDB: ws://localhost:8100"
|
||
|
|
print " Zot OCI: http://localhost:5000"
|
||
|
|
}
|