feat(ssh): run preview builds on remotes from the release archive #11319
Mergedjuliusmarmingemerged 7 commits into
sea/runtime-archives fromrefs/pull/11319/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/ssh/src/tunnel.ts lines 515 to 516Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -406,0 +439,21 @@439+ if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2"440+ elif command -v wget >/dev/null 2>&1; then wget -q "$1" -O "$2"441+ else printf 'Remote host needs curl or wget to download %s.\\n' "$T3_ARCHIVE" >&2; exit 1442+ fi443+ }444+ t3_fetch "$T3_RELEASE_BASE_URL/v$T3_ARCHIVE_VERSION/SHA256SUMS" "$T3_STAGING/SHA256SUMS"445+ t3_fetch "$T3_RELEASE_BASE_URL/v$T3_ARCHIVE_VERSION/$T3_ARCHIVE" "$T3_STAGING/$T3_ARCHIVE"446+ T3_EXPECTED="$(grep " \\*\\{0,1\\}$T3_ARCHIVE$" "$T3_STAGING/SHA256SUMS" | cut -d' ' -f1)"447+ if command -v sha256sum >/dev/null 2>&1; then448+ T3_ACTUAL="$(sha256sum "$T3_STAGING/$T3_ARCHIVE" | cut -d' ' -f1)"449+ else450+ T3_ACTUAL="$(shasum -a 256 "$T3_STAGING/$T3_ARCHIVE" | cut -d' ' -f1)"451+ fi452+ if [ -z "$T3_EXPECTED" ] || [ "$T3_ACTUAL" != "$T3_EXPECTED" ]; then453+ printf 'Checksum mismatch for %s.\\n' "$T3_ARCHIVE" >&2; exit 1454+ fi455+ tar -xzf "$T3_STAGING/$T3_ARCHIVE" -C "$T3_STAGING" --strip-components=1456+ rm -f "$T3_STAGING/$T3_ARCHIVE" "$T3_STAGING/SHA256SUMS"457+ printf '%s\\n' "$T3_ARCHIVE_VERSION" > "$T3_STAGING/.install-complete"458+ rm -rf "$T3_RUNTIME_DIR"459+ mv "$T3_STAGING" "$T3_RUNTIME_DIR"
- @@ -96,3 +97,6 @@9697 nodeEngineRange: serverPackageJson.engines.node,9798 };9899 }100+ // Preview builds ship as self-contained archives, so the remote runs the101+ // same version this app is on without Node or npm.102+ if (!environment.isDevelopment && isArchiveDistributedVersion(environment.appVersion)) {
- @@ -473,4 +556,9 @@473556 fi474557 mv "$RUNNER_NEXT" "$RUNNER_FILE"475558 chmod 700 "$RUNNER_FILE"476-if ! ensure_remote_node_path; then559+T3_ARCHIVE_MODE=@@T3_ARCHIVE_MODE@@560+if [ "$T3_ARCHIVE_MODE" = "1" ]; then561+ # The archive ships the helpers below inside the executable; the remote562+ # needs no Node at all. Resolving the runner once here also downloads the563+ # archive before the port and readiness probes rely on it.564+ "$RUNNER_FILE" --version >/dev/null
- packages/ssh/src/tunnel.ts line 434OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -404,3 +418,17 @@404418405419 const REMOTE_RUNNER_SCRIPT = `#!/bin/sh406420 set -eu421+T3_ARCHIVE_VERSION=@@T3_ARCHIVE_VERSION@@422+if [ -n "$T3_ARCHIVE_VERSION" ]; then423+ # Self-contained release archive: no Node, npm, or compiler on the remote.424+ # Unpacked into the pinned-runtime layout so \`t3 service install\` reuses it.425+ T3_RELEASE_BASE_URL=@@T3_RELEASE_BASE_URL@@426+ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"427+ t3_runtime_ready() {428+ [ -x "$T3_RUNTIME_DIR/t3" ] && [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" = "$T3_ARCHIVE_VERSION" ]429+ }430+ if ! t3_runtime_ready; then431+ mkdir -p "$HOME/.t3/runtime/versions"432+ # Concurrent launches (two clients, a retry racing a slow first run) must433+ # not both install: mkdir is the atomic lock, a stale lock older than434+ # ten minutes is reclaimed, and the ready check repeats under the lock.
- @@ -653,3 +767,4 @@653767 export function buildRemoteT3RunnerScript(input?: RemoteT3RunnerOptions): string {654768 const packageSpec = shellSingleQuote(input?.packageSpec?.trim() || "t3@latest");655769 const nodeScriptPath = input?.nodeScriptPath?.trim() || "";770+ const archiveVersion = input?.archiveVersion?.trim() || "";
- packages/ssh/src/tunnel.ts line 466Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -406,0 +426,21 @@426+ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"427+ t3_runtime_ready() {428+ [ -x "$T3_RUNTIME_DIR/t3" ] && [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" = "$T3_ARCHIVE_VERSION" ]429+ }430+ if ! t3_runtime_ready; then431+ mkdir -p "$HOME/.t3/runtime/versions"432+ # Concurrent launches (two clients, a retry racing a slow first run) must433+ # not both install: mkdir is the atomic lock, a stale lock older than434+ # ten minutes is reclaimed, and the ready check repeats under the lock.435+ T3_LOCK="$HOME/.t3/runtime/versions/.$T3_ARCHIVE_VERSION.install.lock"436+ T3_LOCK_WAITED=0437+ while ! mkdir "$T3_LOCK" 2>/dev/null; do438+ # The holder records its pid; a lock whose owner is gone is stale439+ # regardless of age, and a live owner is never reclaimed no matter how440+ # slow its download is, so two installers can never run at once.441+ T3_LOCK_OWNER="$(cat "$T3_LOCK/pid" 2>/dev/null || true)"442+ if [ -n "$T3_LOCK_OWNER" ] && ! kill -0 "$T3_LOCK_OWNER" 2>/dev/null; then443+ rm -rf "$T3_LOCK"444+ continue445+ fi446+ if [ "$T3_LOCK_WAITED" -ge @@T3_ARCHIVE_LOCK_WAIT_SECONDS@@ ]; then
- packages/ssh/src/tunnel.ts lines 452 to 465Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -406,0 +425,21 @@425+ T3_RELEASE_BASE_URL=@@T3_RELEASE_BASE_URL@@426+ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"427+ t3_runtime_ready() {428+ [ -x "$T3_RUNTIME_DIR/t3" ] && [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" = "$T3_ARCHIVE_VERSION" ]429+ }430+ if ! t3_runtime_ready; then431+ mkdir -p "$HOME/.t3/runtime/versions"432+ # Concurrent launches (two clients, a retry racing a slow first run) must433+ # not both install: mkdir is the atomic lock, a stale lock older than434+ # ten minutes is reclaimed, and the ready check repeats under the lock.435+ T3_LOCK="$HOME/.t3/runtime/versions/.$T3_ARCHIVE_VERSION.install.lock"436+ T3_LOCK_WAITED=0437+ while ! mkdir "$T3_LOCK" 2>/dev/null; do438+ # The holder records its pid; a lock whose owner is gone is stale439+ # regardless of age, and a live owner is never reclaimed no matter how440+ # slow its download is, so two installers can never run at once.441+ T3_LOCK_OWNER="$(cat "$T3_LOCK/pid" 2>/dev/null || true)"442+ if [ -n "$T3_LOCK_OWNER" ] && ! kill -0 "$T3_LOCK_OWNER" 2>/dev/null; then443+ rm -rf "$T3_LOCK"444+ continue445+ fi
- packages/ssh/src/tunnel.ts line 482OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -406,0 +462,21 @@462+ if ! t3_runtime_ready; then463+ case "$(uname -s)" in464+ Darwin) T3_PLATFORM="darwin" ;;465+ Linux) T3_PLATFORM="linux" ;;466+ *) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -s)" >&2; exit 1 ;;467+ esac468+ case "$(uname -m)" in469+ arm64 | aarch64) T3_ARCH="arm64" ;;470+ x86_64 | amd64) T3_ARCH="x64" ;;471+ *) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -m)" >&2; exit 1 ;;472+ esac473+ T3_ARCHIVE="t3-$T3_ARCHIVE_VERSION-$T3_PLATFORM-$T3_ARCH.tar.gz"474+ T3_STAGING="$(mktemp -d "$HOME/.t3/runtime/versions/.staging-XXXXXX")"475+ trap 'rm -rf "$T3_STAGING" "$T3_LOCK"' EXIT476+ t3_fetch() {477+ if command -v curl >/dev/null 2>&1; then curl -fsSL --connect-timeout 30 --max-time @@T3_ARCHIVE_DOWNLOAD_SECONDS@@ "$1" -o "$2"478+ elif command -v wget >/dev/null 2>&1; then wget -q --timeout=30 --tries=1 "$1" -O "$2"479+ else printf 'Remote host needs curl or wget to download %s.\\n' "$T3_ARCHIVE" >&2; exit 1480+ fi481+ }482+ t3_fetch "$T3_RELEASE_BASE_URL/v$T3_ARCHIVE_VERSION/SHA256SUMS" "$T3_STAGING/SHA256SUMS"@@ -96,3 +97,7 @@9697 nodeEngineRange: serverPackageJson.engines.node,9798 };9899 }100+ // Preview builds ship as self-contained archives, so the remote runs the101+ // same version this app is on without Node or npm.102+ if (!environment.isDevelopment && isArchiveDistributedVersion(environment.appVersion)) {103+ return { archiveVersion: environment.appVersion };
- @@ -56,3 +57,10 @@5657 const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;5758 const REMOTE_READY_TIMEOUT_MS = 60_000;5859 const REMOTE_LAUNCH_TIMEOUT_MS = 90_000;60+// A cold archive launch also downloads and unpacks a ~70 MB release archive61+// and may wait on another installer's lock. The budgets nest: one download62+// is bounded, a waiter outlasts a full download plus extraction so it can63+// reuse the result, and the SSH command outlasts the waiter plus readiness.64+const REMOTE_ARCHIVE_DOWNLOAD_SECONDS = 240;65+const REMOTE_ARCHIVE_LOCK_WAIT_SECONDS = 300;66+const REMOTE_ARCHIVE_LAUNCH_TIMEOUT_MS = 600_000;packages/ssh/src/tunnel.ts line 446OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -406,0 +426,21 @@426+ # Self-contained release archive: no Node, npm, or compiler on the remote.427+ # Unpacked into the pinned-runtime layout so \`t3 service install\` reuses it.428+ T3_RELEASE_BASE_URL=@@T3_RELEASE_BASE_URL@@429+ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"430+ t3_runtime_ready() {431+ [ -x "$T3_RUNTIME_DIR/t3" ] && [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" = "$T3_ARCHIVE_VERSION" ]432+ }433+ if ! t3_runtime_ready; then434+ mkdir -p "$HOME/.t3/runtime/versions"435+ # Concurrent launches (two clients, a retry racing a slow first run) must436+ # not both install: mkdir is the atomic lock, a stale lock older than437+ # ten minutes is reclaimed, and the ready check repeats under the lock.438+ T3_LOCK="$HOME/.t3/runtime/versions/.$T3_ARCHIVE_VERSION.install.lock"439+ # The lock is a directory renamed into place with its owner pid already440+ # inside, so it never exists without an owner. A lock whose owner is gone441+ # is stale regardless of age; a live owner is never reclaimed no matter442+ # how slow its download is, so two installers can never run at once.443+ T3_LOCK_CANDIDATE="$(mktemp -d "$HOME/.t3/runtime/versions/.lock-XXXXXX")"444+ printf '%s\\n' "$$" > "$T3_LOCK_CANDIDATE/pid"445+ T3_LOCK_WAITED=0446+ while ! mv "$T3_LOCK_CANDIDATE" "$T3_LOCK" 2>/dev/null || [ -d "$T3_LOCK_CANDIDATE" ]; do
juliusmarminge merged this13c134c
juliusmarminge closed this
Sign in to join this conversation.
Bugbot is paused — on-demand spend limit reached
Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.
A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.