summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-02 21:57:06 +0900
committerAdam Malczewski <[email protected]>2026-06-02 21:57:06 +0900
commit4b45d33c256cf580a53054078be6fd7148fa6302 (patch)
tree0f549e08607f083d1f04306ce35e132923d6e3d3
parentd9f53727845dface3e6d8a84ba2270b1de55482b (diff)
downloaddispatch-4b45d33c256cf580a53054078be6fd7148fa6302.tar.gz
dispatch-4b45d33c256cf580a53054078be6fd7148fa6302.zip
Fix build scripts and deployment port issue
-rwxr-xr-xbin/build-pkg5
-rwxr-xr-xbin/install-pkg10
-rw-r--r--packages/api/src/index.ts26
-rw-r--r--packaging/PKGBUILD51
4 files changed, 59 insertions, 33 deletions
diff --git a/bin/build-pkg b/bin/build-pkg
index d257efc..f8bc8b2 100755
--- a/bin/build-pkg
+++ b/bin/build-pkg
@@ -8,6 +8,11 @@
#
# Override frontend build target with VITE_API_URL, e.g.:
# VITE_API_URL="https://api.example.com" bin/build-pkg
+#
+# The patched `cs` code-search binary is reused from an already-installed
+# code-search package instead of being recompiled. Force a fresh clone+build
+# (required after bumping _cs_commit in the PKGBUILD) with:
+# DISPATCH_FORCE_CS_BUILD=1 bin/build-pkg
set -euo pipefail
diff --git a/bin/install-pkg b/bin/install-pkg
index 9665847..9af784d 100755
--- a/bin/install-pkg
+++ b/bin/install-pkg
@@ -35,7 +35,15 @@ declare -a names
declare -a paths
if [ $# -eq 0 ]; then
- names=(dispatch dispatch-systemd code-search)
+ names=(dispatch dispatch-systemd)
+ # code-search ships a self-contained `cs` binary pinned to _cs_commit in the
+ # PKGBUILD; it rarely changes. Skip reinstalling it if it's already present —
+ # run `bin/install-pkg code-search` to force a reinstall (e.g. after a bump).
+ if pacman -Qq code-search &>/dev/null; then
+ echo "code-search already installed — skipping (run 'bin/install-pkg code-search' to force)"
+ else
+ names+=(code-search)
+ fi
elif [ "${1:-}" = "--all" ]; then
names=(dispatch dispatch-systemd dispatch-s6 dispatch-electron code-search)
else
diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts
index 478abe0..5615e08 100644
--- a/packages/api/src/index.ts
+++ b/packages/api/src/index.ts
@@ -70,24 +70,24 @@ app.get(
export { app };
-// Starting port (overridable via PORT) and the inclusive ceiling we will bump
-// up to when a port is already in use. If 3000 is taken we try 3001, 3002, …
-// up to MAX_PORT, so multiple dispatch instances (e.g. testing several
-// features at once) can coexist without manually juggling ports. The frontend
-// defaults to :3000 — point it at the chosen port via the in-app API-URL
-// field / VITE_API_URL when a bump happens.
+// Starting port (overridable via PORT). When the port is already in use we
+// bump up one at a time (3000 → 3001 → 3002, …) until we find a free one, so
+// multiple dispatch instances (e.g. testing several features at once) can
+// coexist without manually juggling ports. The frontend defaults to :3000 —
+// point it at the chosen port via the in-app API-URL field / VITE_API_URL
+// when a bump happens.
const START_PORT = Number(process.env.PORT) || 3000;
-const MAX_PORT = 3010;
/**
* Bind the server to `START_PORT`, incrementing by one on EADDRINUSE until a
- * free port is found or MAX_PORT is exceeded. Bun's `Bun.serve` throws
- * synchronously when the port is taken, so we can catch and retry. Returns the
- * live server (whose `.port` reflects the port actually bound).
+ * free port is found (up to the maximum valid TCP port, 65535). Bun's
+ * `Bun.serve` throws synchronously when the port is taken, so we can catch and
+ * retry. Returns the live server (whose `.port` reflects the port actually
+ * bound).
*/
function serveWithPortFallback() {
let lastError: unknown;
- for (let port = START_PORT; port <= MAX_PORT; port++) {
+ for (let port = START_PORT; port <= 65535; port++) {
try {
const server = Bun.serve({
port,
@@ -113,10 +113,10 @@ function serveWithPortFallback() {
}
}
console.error(
- `dispatch: no free port in range ${START_PORT}-${MAX_PORT}. ` +
+ `dispatch: no free port at or above ${START_PORT}. ` +
`Free one up or set PORT to an open port.`,
);
- throw lastError ?? new Error(`No free port in range ${START_PORT}-${MAX_PORT}`);
+ throw lastError ?? new Error(`No free port at or above ${START_PORT}`);
}
// Only start the server when run as the entry point — importing this module
diff --git a/packaging/PKGBUILD b/packaging/PKGBUILD
index 878b15f..323f9cc 100644
--- a/packaging/PKGBUILD
+++ b/packaging/PKGBUILD
@@ -61,25 +61,38 @@ build() {
rm -rf node_modules
bun install --frozen-lockfile --production
- # --- Build the patched `cs` code-search binary for the search_code tool ---
- # Clone the pinned cs commit, apply the Luau declaration + fuzzy-distance
- # patches, and build a
- # statically-linked binary. cs vendors its deps, so `go build -mod=vendor`
- # needs no network beyond the clone. Mirrors the Docker cs-builder stage.
- #
- # rm -rf first so a rerun (makepkg -e, or two invocations without -C) that
- # reuses $srcdir doesn't abort on "destination path already exists". This
- # PKGBUILD intentionally avoids source=() (the s6 service files share
- # basenames and would collide in $srcdir), so we clone here rather than via
- # makepkg's VCS source handling.
- rm -rf "${srcdir}/cs-src"
- git clone https://github.com/boyter/cs.git "${srcdir}/cs-src"
- cd "${srcdir}/cs-src"
- git checkout "${_cs_commit}"
- git apply "${_projectdir}/docker/cs/luau-declarations.patch"
- git apply "${_projectdir}/docker/cs/fuzzy-distance.patch"
- CGO_ENABLED=0 GOFLAGS=-mod=vendor GOPATH="${srcdir}/gopath" GOCACHE="${srcdir}/gocache" \
- go build -ldflags="-s -w" -o "${srcdir}/cs" .
+ # --- Provide the patched `cs` code-search binary for the search_code tool ---
+ # Building cs means a network clone + Go compile every run, which is wasted
+ # work when a matching cs is already on the system: the code-search package
+ # owns /usr/bin/cs and is pinned to the same _cs_commit. If it's already
+ # installed, reuse that binary instead of recloning/recompiling. Force a
+ # fresh build with DISPATCH_FORCE_CS_BUILD=1 (required when bumping
+ # _cs_commit, since the installed binary won't reflect the new commit).
+ if [ -z "${DISPATCH_FORCE_CS_BUILD:-}" ] && pacman -Qq code-search &>/dev/null \
+ && [ -x /usr/bin/cs ]; then
+ echo "cs: code-search already installed — reusing /usr/bin/cs" \
+ "(set DISPATCH_FORCE_CS_BUILD=1 to rebuild)"
+ cp /usr/bin/cs "${srcdir}/cs"
+ else
+ # Clone the pinned cs commit, apply the Luau declaration + fuzzy-distance
+ # patches, and build a statically-linked binary. cs vendors its deps, so
+ # `go build -mod=vendor` needs no network beyond the clone. Mirrors the
+ # Docker cs-builder stage.
+ #
+ # rm -rf first so a rerun (makepkg -e, or two invocations without -C)
+ # that reuses $srcdir doesn't abort on "destination path already exists".
+ # This PKGBUILD intentionally avoids source=() (the s6 service files
+ # share basenames and would collide in $srcdir), so we clone here rather
+ # than via makepkg's VCS source handling.
+ rm -rf "${srcdir}/cs-src"
+ git clone https://github.com/boyter/cs.git "${srcdir}/cs-src"
+ cd "${srcdir}/cs-src"
+ git checkout "${_cs_commit}"
+ git apply "${_projectdir}/docker/cs/luau-declarations.patch"
+ git apply "${_projectdir}/docker/cs/fuzzy-distance.patch"
+ CGO_ENABLED=0 GOFLAGS=-mod=vendor GOPATH="${srcdir}/gopath" GOCACHE="${srcdir}/gocache" \
+ go build -ldflags="-s -w" -o "${srcdir}/cs" .
+ fi
"${srcdir}/cs" --version
}