Repository navigation
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·85 lines (79 loc) · 3.39 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·85 lines (79 loc) · 3.39 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
#!/usr/bin/env bash
# FlowProxy STORE-mode entrypoint (ADR-0016).
#
# For the demo, the "warehouse" is a DuckDB file that CI built and uploaded to
# S3 as a sidecar object, separate from the manifest bundle. This script:
# 1. downloads the DuckDB sidecar to local disk (if FLOWPROXY_DUCKDB_URI set)
# 2. exports FLOWPROXY_DUCKDB_PATH to that local file
# 3. execs the proxy, which pulls the bundle from FLOWPROXY_MANIFEST_URI and
# serves the PostgreSQL wire protocol in STORE mode
#
# With a real networked warehouse (Snowflake/Redshift) there is no sidecar:
# unset FLOWPROXY_DUCKDB_URI and pass the warehouse creds as env vars instead;
# this script then just execs the proxy.
set -euo pipefail
log() { echo "[entrypoint] $*"; }
# The local path the DuckDB file lands at (also what the profile template reads).
#
# IMPORTANT: DuckDB derives its CATALOG (database) name from the file's
# basename. MetricFlow's compiled SQL references that catalog by name (e.g.
# <project>.main.fct_...), so the downloaded sidecar MUST keep the same basename
# it had when the manifest was built - otherwise every query fails with
# 'Catalog "<name>" does not exist'. We therefore derive the local basename from
# the sidecar URI's basename, so this works for any project, not a fixed name.
if [[ -z "${FLOWPROXY_DUCKDB_PATH:-}" && -n "${FLOWPROXY_DUCKDB_URI:-}" ]]; then
FLOWPROXY_DUCKDB_PATH="/app/data/$(basename "${FLOWPROXY_DUCKDB_URI}")"
fi
# Fallback only when neither var is set (e.g. a non-DuckDB warehouse where the
# sidecar mechanism is unused). Generic name; the derived basename above wins.
: "${FLOWPROXY_DUCKDB_PATH:=/app/data/warehouse.duckdb}"
export FLOWPROXY_DUCKDB_PATH
download_sidecar() {
local uri="$1" dest="$2"
mkdir -p "$(dirname "$dest")"
case "$uri" in
s3://*)
if command -v aws >/dev/null 2>&1; then
log "downloading DuckDB sidecar via aws cli: $uri"
aws s3 cp "$uri" "$dest" --only-show-errors
else
log "aws cli absent; downloading sidecar via python/fsspec: $uri"
python - "$uri" "$dest" <<'PY'
import sys, fsspec
src, dst = sys.argv[1], sys.argv[2]
with fsspec.open(src, "rb") as r, open(dst, "wb") as w:
w.write(r.read())
PY
fi
;;
file://*|/*)
log "copying DuckDB sidecar from local/file uri: $uri"
python - "$uri" "$dest" <<'PY'
import sys, fsspec
src, dst = sys.argv[1], sys.argv[2]
with fsspec.open(src, "rb") as r, open(dst, "wb") as w:
w.write(r.read())
PY
;;
*)
log "FATAL: unsupported FLOWPROXY_DUCKDB_URI scheme: $uri" >&2
exit 1
;;
esac
}
if [[ -n "${FLOWPROXY_DUCKDB_URI:-}" ]]; then
download_sidecar "${FLOWPROXY_DUCKDB_URI}" "${FLOWPROXY_DUCKDB_PATH}"
if [[ ! -f "${FLOWPROXY_DUCKDB_PATH}" ]]; then
log "FATAL: DuckDB sidecar not present at ${FLOWPROXY_DUCKDB_PATH} after download" >&2
exit 1
fi
log "DuckDB warehouse ready at ${FLOWPROXY_DUCKDB_PATH} ($(du -h "${FLOWPROXY_DUCKDB_PATH}" | cut -f1))"
else
log "no FLOWPROXY_DUCKDB_URI set; assuming a networked warehouse via env creds"
fi
if [[ -z "${FLOWPROXY_MANIFEST_URI:-}" ]]; then
log "FATAL: FLOWPROXY_MANIFEST_URI is required for STORE mode" >&2
exit 1
fi
log "launching FlowProxy (STORE mode) on :${FLOWPROXY_PORT:-5432}, manifest=${FLOWPROXY_MANIFEST_URI}"
exec python /app/main.py