From f201d5bf9c3f3f3b2be9dcb7ece3c36f4c5062a6 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sat, 15 Aug 2026 03:15:19 +0500 Subject: [PATCH] Clone upstream at build time; drop submodules; single httptoolkit binary --- .build/prod/build.sh | 14 +++++------- .gitea/workflows/build.yml | 7 ++---- .gitignore | 7 +++--- .gitmodules | 6 ------ httptoolkit-server | 1 - httptoolkit-ui | 1 - scripts/apply.sh | 44 -------------------------------------- scripts/build.sh | 40 ++++++++++++---------------------- scripts/patch.sh | 29 +++++++++++++++++++++++++ 9 files changed, 53 insertions(+), 96 deletions(-) delete mode 100644 .gitmodules delete mode 160000 httptoolkit-server delete mode 160000 httptoolkit-ui delete mode 100755 scripts/apply.sh create mode 100755 scripts/patch.sh diff --git a/.build/prod/build.sh b/.build/prod/build.sh index 12da8a6..576b5c3 100755 --- a/.build/prod/build.sh +++ b/.build/prod/build.sh @@ -1,24 +1,20 @@ #!/usr/bin/env bash # -# Runs INSIDE the .build/prod container. Builds the Linux single-file binary and -# drops it into .build/prod/out/ (mounted back to the host for the release step). +# Runs INSIDE the .build/prod container. Clones, patches, builds the binary, +# smoke-tests it, and drops it in .build/prod/out/ for the release step. # set -euo pipefail cd /source -# The repo is bind-mounted from the host (owned by a different uid), so git -# refuses to operate on it until we mark it safe: +# The repo is bind-mounted from the host (different uid), so mark it safe: git config --global --add safe.directory '*' OUT_DIR="/source/.build/prod/out" mkdir -p "$OUT_DIR" -# Reuse the platform-agnostic build (apply patches → build UI → embed → bun compile): -OUT_NAME=httptoolkit bash scripts/build.sh - -# Smoke-test the Linux binary before we consider it releasable: +bash scripts/build.sh bash scripts/smoke.sh dist/httptoolkit -cp -v dist/httptoolkit "$OUT_DIR/httptoolkit-linux-x64" +cp -v dist/httptoolkit "$OUT_DIR/httptoolkit" echo "==> Artifacts:" ls -lh "$OUT_DIR" diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index a761968..1158d05 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -14,17 +14,14 @@ jobs: runs-on: docker-compose steps: - - name: Checkout (with submodules) + - name: Checkout uses: actions/checkout@v4 with: - submodules: recursive fetch-depth: 0 - name: Build Linux binary (docker) working-directory: .build/prod - run: | - docker compose build - docker compose run --rm prod + run: docker compose run --build --rm prod - name: Create Gitea release & upload assets env: diff --git a/.gitignore b/.gitignore index 303ced4..711f01a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,9 @@ /dist/ /out/ -# Build artifacts staged inside the server submodule by scripts/build.sh -# (the submodule has its own .gitignore too; these are just in case) -/httptoolkit-server/ui.tar.gz -/httptoolkit-server/ui/ +# Upstream sources are cloned fresh at build time, not tracked here +/httptoolkit-ui/ +/httptoolkit-server/ # Local tooling / editor /.claude/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 4e6f803..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "httptoolkit-ui"] - path = httptoolkit-ui - url = https://github.com/httptoolkit/httptoolkit-ui.git -[submodule "httptoolkit-server"] - path = httptoolkit-server - url = https://github.com/httptoolkit/httptoolkit-server.git diff --git a/httptoolkit-server b/httptoolkit-server deleted file mode 160000 index b9f2810..0000000 --- a/httptoolkit-server +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b9f2810c5abcaed5463a1d906db6f8d458275711 diff --git a/httptoolkit-ui b/httptoolkit-ui deleted file mode 160000 index 237690c..0000000 --- a/httptoolkit-ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 237690ce485c6a2592aadaf92c5bbbcd1008430f diff --git a/scripts/apply.sh b/scripts/apply.sh deleted file mode 100755 index 805c5c0..0000000 --- a/scripts/apply.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# -# Apply our patches + overlay onto the pristine upstream submodules. -# -# Fails loudly if a patch no longer applies (i.e. upstream moved after a -# submodule bump), so you know exactly which patch to refresh. Idempotent: -# it resets each submodule's tracked files to the pinned commit first. -# -set -euo pipefail -ROOT="$(cd "$(dirname "$0")/.." && pwd)" -cd "$ROOT" - -echo "==> Ensuring submodules are initialised & at pinned commits" -git submodule update --init --recursive - -apply_patches() { - local name="$1" dir="$2" - if [ ! -d "patches/$name" ]; then return; fi - - echo "==> [$name] resetting to pinned commit" - git -C "$dir" checkout -- . 2>/dev/null || true - git -C "$dir" clean -fd -e node_modules 2>/dev/null || true - - echo "==> [$name] applying patches" - local applied=0 - for patch in patches/"$name"/*.patch; do - [ -e "$patch" ] || continue - echo " - $(basename "$patch")" - # --3way lets git fall back to a merge if context shifted slightly. - git -C "$dir" apply --3way "$ROOT/$patch" - applied=$((applied + 1)) - done - echo "==> [$name] $applied patch(es) applied" -} - -apply_patches ui httptoolkit-ui -apply_patches server httptoolkit-server - -echo "==> Copying overlay files into httptoolkit-server" -cp -v overlay/server/htk-entry.ts httptoolkit-server/htk-entry.ts -cp -v overlay/server/src/htk-app.ts httptoolkit-server/src/htk-app.ts -cp -v overlay/server/src/commands/app.ts httptoolkit-server/src/commands/app.ts - -echo "==> apply.sh complete." diff --git a/scripts/build.sh b/scripts/build.sh index 18cd312..6836bc7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,48 +1,36 @@ #!/usr/bin/env bash # -# Build the self-hosted single-file HTTP Toolkit binary. -# -# Requires: node (>=22), npm, bun, tar. Runs per-OS in CI (native modules can't -# be cross-compiled), so this builds for the *host* platform. -# -# Env: -# OUT_NAME output binary basename (default: httptoolkit) -# BUN_TARGET optional bun --target (default: host); e.g. bun-linux-x64 +# Clone upstream, patch, and build the single-file binary -> dist/httptoolkit +# Requires: node (>=22), npm, bun, tar, git. # set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" -OUT_NAME="${OUT_NAME:-httptoolkit}" -BUN_TARGET="${BUN_TARGET:-}" - -# The UI's postinstall pulls Puppeteer's Chromium (only needed for its own -# integration tests) - skip it, it's large and irrelevant to the build. export PUPPETEER_SKIP_DOWNLOAD=true export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true -EXT="" -case "${BUN_TARGET}" in *windows*) EXT=".exe";; esac -if [ -z "$BUN_TARGET" ] && [ "${OS:-}" = "Windows_NT" ]; then EXT=".exe"; fi +echo "==> Cloning upstream sources" +rm -rf httptoolkit-ui httptoolkit-server +git clone --depth 1 https://github.com/httptoolkit/httptoolkit-ui.git +git clone --depth 1 https://github.com/httptoolkit/httptoolkit-server.git -echo "==> 1/5 Apply patches + overlay" -bash scripts/apply.sh +echo "==> Applying patches + overlay" +bash scripts/patch.sh -echo "==> 2/5 Build UI -> httptoolkit-ui/dist" +echo "==> Building UI" ( cd httptoolkit-ui && npm ci && npm run build ) -echo "==> 3/5 Install server deps (+ tar for the entry) & embed the UI" +echo "==> Preparing server + embedding UI" ( cd httptoolkit-server \ && npm ci \ && npm install --no-save tar@^7 \ && tar -czf ui.tar.gz -C ../httptoolkit-ui/dist . \ && rm -rf ui && cp -r ../httptoolkit-ui/dist ui ) -echo "==> 4/5 Compile single-file binary with Bun" +echo "==> Compiling single-file binary -> dist/httptoolkit" mkdir -p dist -COMPILE=(build ./htk-entry.ts --compile --outfile "$ROOT/dist/${OUT_NAME}${EXT}") -if [ -n "$BUN_TARGET" ]; then COMPILE+=(--target "$BUN_TARGET"); fi -( cd httptoolkit-server && bun "${COMPILE[@]}" ) +( cd httptoolkit-server && bun build ./htk-entry.ts --compile --outfile "$ROOT/dist/httptoolkit" ) -echo "==> 5/5 Done -> dist/${OUT_NAME}${EXT}" -ls -lh "dist/${OUT_NAME}${EXT}" +echo "==> Done: dist/httptoolkit" +ls -lh dist/httptoolkit diff --git a/scripts/patch.sh b/scripts/patch.sh new file mode 100755 index 0000000..054bc6c --- /dev/null +++ b/scripts/patch.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# Apply our patches + overlay onto the cloned upstream repos. +# Fails loudly if a patch no longer applies (upstream moved). +# +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +cd "$ROOT" + +apply_patches() { + local name="$1" dir="$2" + [ -d "patches/$name" ] || return 0 + echo "==> [$name] applying patches" + for patch in patches/"$name"/*.patch; do + [ -e "$patch" ] || continue + echo " - $(basename "$patch")" + git -C "$dir" apply --3way "$ROOT/$patch" + done +} + +apply_patches ui httptoolkit-ui +apply_patches server httptoolkit-server + +echo "==> Copying overlay into httptoolkit-server" +cp -v overlay/server/htk-entry.ts httptoolkit-server/htk-entry.ts +cp -v overlay/server/src/htk-app.ts httptoolkit-server/src/htk-app.ts +cp -v overlay/server/src/commands/app.ts httptoolkit-server/src/commands/app.ts + +echo "==> patch.sh complete."