#!/bin/sh # DataCenterIndex container entrypoint (worker + api images). The first argument selects the role: # worker BullMQ crawl/ingest worker (apps/worker/src/main.ts) — default CMD of Dockerfile.worker # scheduler connector scheduler (apps/worker/src/scheduler.ts) # cli|dci `pnpm dci …` equivalent (apps/worker/src/cli.ts) — e.g. `cli run peeringdb --dry-run --limit 5` # migrate Postgres migrations → seed (if packages/db/src/seed.ts exists) → ClickHouse DDL, then exit # api Fastify API (apps/api/src/main.ts | server.ts | index.ts) — default CMD of Dockerfile.api # anything else is exec'd verbatim (`sh`, `node …`). set -eu cd /app TSX="node /app/node_modules/tsx/dist/cli.mjs" first_existing() { for f in "$@"; do if [ -f "$f" ]; then echo "$f"; return 0; fi done echo "entrypoint: none of the candidate entry files exist: $*" >&2 return 1 } role="${1:-worker}" [ "$#" -gt 0 ] && shift case "$role" in worker) exec $TSX apps/worker/src/main.ts "$@" ;; scheduler) exec $TSX apps/worker/src/scheduler.ts "$@" ;; cli|dci) exec $TSX apps/worker/src/cli.ts "$@" ;; api) entry="$(first_existing apps/api/src/main.ts apps/api/src/server.ts apps/api/src/index.ts)" exec $TSX "$entry" "$@" ;; migrate) echo "[migrate] postgres migrations" $TSX packages/db/src/migrate.ts if [ "${DCI_SKIP_SEED:-0}" != "1" ]; then if [ -f packages/db/src/seed.ts ]; then echo "[migrate] seed" $TSX packages/db/src/seed.ts else echo "[migrate] no packages/db/src/seed.ts — seed skipped" fi fi if [ "${DCI_SKIP_CLICKHOUSE:-0}" != "1" ]; then echo "[migrate] clickhouse ddl" $TSX deploy/docker/ensure-clickhouse.ts fi echo "[migrate] done" exit 0 ;; *) exec "$role" "$@" ;; esac