summaryrefslogtreecommitdiffhomepage
path: root/bin/build
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-21 20:26:39 +0900
committerAdam Malczewski <[email protected]>2026-06-21 20:26:39 +0900
commit4434fbf951d06a721597e805094069477851178e (patch)
tree4d3103ccb0512ff77d9d472d7b4178c11c8b73b3 /bin/build
parentac69e5f8bea9377887a6f89ff362c6be0db1c874 (diff)
downloaddispatch-4434fbf951d06a721597e805094069477851178e.tar.gz
dispatch-4434fbf951d06a721597e805094069477851178e.zip
feat: standalone build + systemd install (Arch Linux)
bin/build: compiles standalone binaries (dispatch-server + dispatch CLI) via bun build --compile, builds the frontend static bundle with VITE_HTTP_PORT=24991 + VITE_WS_PORT=24990, copies to dist/web/. bin/install: installs binaries to /usr/bin/, frontend to /usr/share/dispatch/web/, systemd service to /etc/systemd/system/, config to /etc/dispatch/env, data dirs to /var/lib/dispatch/ + /var/log/dispatch/. Enables + starts the dispatch systemd service. Supports --uninstall and --no-build flags. systemd/dispatch.service: Type=simple, reads /etc/dispatch/env, restarts on failure, logs to journald. systemd/dispatch.env: template config (ports 24991 HTTP + 24990 WS, DISPATCH_WEB_DIR, API key, data paths). transport-http: optional webDir static file serving — unmatched GET requests fall through to Bun.file() serving with SPA index.html fallback. Gated on DISPATCH_WEB_DIR env var (backward compatible).
Diffstat (limited to 'bin/build')
-rwxr-xr-xbin/build56
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/build b/bin/build
new file mode 100755
index 0000000..0517af5
--- /dev/null
+++ b/bin/build
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+# bin/build — compile the backend + CLI binaries and the frontend static bundle.
+#
+# Output:
+# dist/dispatch-server — standalone backend binary (Bun compile)
+# dist/dispatch — standalone CLI binary (Bun compile)
+# dist/web/ — built frontend static files (vite build)
+#
+# The frontend is built with VITE_HTTP_PORT=24991 + VITE_WS_PORT=24990 so the
+# bundle talks to the backend on :24991 (HTTP) and :24990 (WS) at runtime.
+# The backend serves the frontend from DISPATCH_WEB_DIR (set in the systemd env).
+#
+# Usage: bin/build [--no-frontend] (skip the frontend build if already built)
+
+set -euo pipefail
+
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT="$(cd "$HERE/.." && pwd)"
+BACKEND="$ROOT"
+FRONTEND="$(cd "$ROOT/.." && pwd)/dispatch-web"
+
+BUILD_FRONTEND=1
+if [[ "${1:-}" == "--no-frontend" ]]; then
+ BUILD_FRONTEND=0
+fi
+
+echo "[build] backend binary → dist/dispatch-server"
+mkdir -p "$ROOT/dist"
+bun build --compile "$BACKEND/packages/host-bin/src/main.ts" \
+ --outfile "$ROOT/dist/dispatch-server" \
+ --minify 2>&1 | tail -3
+
+echo "[build] CLI binary → dist/dispatch"
+bun build --compile "$BACKEND/packages/cli/src/main.ts" \
+ --outfile "$ROOT/dist/dispatch" \
+ --minify 2>&1 | tail -3
+
+if [[ "$BUILD_FRONTEND" -eq 1 ]]; then
+ if [[ ! -d "$FRONTEND" ]]; then
+ echo "[build] frontend not found at $FRONTEND — skipping" >&2
+ else
+ echo "[build] frontend → dist/web/ (VITE_HTTP_PORT=24991 VITE_WS_PORT=24990)"
+ (
+ cd "$FRONTEND"
+ VITE_HTTP_PORT=24991 VITE_WS_PORT=24990 bun run build 2>&1 | tail -5
+ )
+ rm -rf "$ROOT/dist/web"
+ cp -r "$FRONTEND/dist" "$ROOT/dist/web"
+ echo "[build] copied $(find "$ROOT/dist/web" -type f | wc -l) files"
+ fi
+fi
+
+echo "[build] done."
+echo " dist/dispatch-server ($(du -h "$ROOT/dist/dispatch-server" | cut -f1))"
+echo " dist/dispatch ($(du -h "$ROOT/dist/dispatch" | cut -f1))"
+[[ -d "$ROOT/dist/web" ]] && echo " dist/web/ ($(du -sh "$ROOT/dist/web" | cut -f1))"