Files
streamline/control-server/build.sh
T
2026-11-16 17:26:44 -08:00

65 lines
2.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# SCM build for the control-server (Bun app, x86_64 Linux).
# ---------------------------------------------------------------------------
# Produces a self-contained artifact under repo-root ./output:
# output/server – standalone x86_64-linux executable with the Bun runtime
# BAKED IN (the runtime box needs NO bun and NO node; ~95MB).
# output/run.sh – FaaS/SCM entry (→ /opt/bytefaas/run.sh). `exec ./server`,
# executable, so the platform's SIGINT reaches Bun directly.
#
# bun is required ONLY here at BUILD time (to compile). Not at runtime.
#
# The server listens on _BYTEFAAS_RUNTIME_PORT (FaaS-injected) or PORT, binds
# dual-stack (ipv4+ipv6) on FaaS, and exposes GET /v1/ping for the liveness probe.
#
# Runtime env — set these in the platform (FaaS/SCM) env console, NOT in the repo
# (.env is gitignored and never shipped):
# DATABASE_URL postgres://user:pass@[2605:…ipv6…]:5432/StreamlineMain (required; bracket IPv6)
# LARK_* / MEEGO_* / TOS_* / CLUSTER_* / APP_BASE_URL … per enabled features
# (do NOT set HOST on FaaS — it force-binds dual-stack `::` there.)
#
# Wire the platform build command to: bash control-server/build.sh
# Default start command is run.sh (or run ./output/server directly).
# ---------------------------------------------------------------------------
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$ROOT"
TARGET="bun-linux-x64" # build/run machines are x86_64 linux
OUT="$ROOT/output"
# 1. Ensure bun is available (build-time only).
if ! command -v bun >/dev/null 2>&1; then
echo "[build] bun not found — installing…"
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="${BUN_INSTALL:-$HOME/.bun}"
export PATH="$BUN_INSTALL/bin:$PATH"
fi
echo "[build] using bun $(bun --version)"
# 2. Install workspace (@bbbug/*) + npm deps so the bundler can resolve them.
bun install
# 3. Compile the server (entry: control-server/src/index.ts) into ONE
# self-contained linux-x64 executable — all workspace + npm deps + the Bun
# runtime are embedded.
rm -rf "$OUT"
mkdir -p "$OUT"
bun build control-server/src/index.ts \
--compile --target="$TARGET" \
--outfile "$OUT/server"
chmod +x "$OUT/server"
test -x "$OUT/server" || { echo "[build] ERROR: $OUT/server not produced"; exit 1; }
# 4. run.sh — the FaaS/SCM entry (`/opt/bytefaas/run.sh`). Copy it in and make it
# executable (a non-executable run.sh → "permission denied" on publish). It
# `exec ./server`, so the platform's SIGINT reaches the Bun process directly.
cp "$SCRIPT_DIR/run.sh" "$OUT/run.sh"
chmod +x "$OUT/run.sh"
echo "[build] done → $OUT"
ls -la "$OUT"