Add remote build fallback to deploy script

This commit is contained in:
kris
2026-04-07 09:30:32 +08:00
parent 992f8dbba4
commit c5223c7c16
2 changed files with 144 additions and 6 deletions

View File

@@ -84,3 +84,93 @@ exec "$@"
await rm(tempRoot, { recursive: true, force: true });
}
});
test("deploy-server falls back to remote build when local build hits ENOSPC", async () => {
const tempRoot = await mkdtemp(path.join(os.tmpdir(), "boss-deploy-script-remote-build-"));
const binDir = path.join(tempRoot, "bin");
const logDir = path.join(tempRoot, "logs");
const repoRoot = "/Users/kris/code/boss";
await mkdir(binDir, { recursive: true });
await mkdir(logDir, { recursive: true });
await writeExecutable(
path.join(binDir, "security"),
`#!/bin/sh
printf 'Asd123456.'
`,
);
await writeExecutable(
path.join(binDir, "npm"),
`#!/bin/sh
COUNT_FILE="${path.join(logDir, "npm-count")}"
count=0
if [ -f "$COUNT_FILE" ]; then
count="$(cat "$COUNT_FILE")"
fi
count=$((count + 1))
printf '%s' "$count" > "$COUNT_FILE"
printf '%s\\0' "$*" >> "${path.join(logDir, "npm.log")}"
if [ "$count" -eq 1 ]; then
printf 'Error: ENOSPC: no space left on device\\n' >&2
exit 1
fi
exit 0
`,
);
await writeExecutable(
path.join(binDir, "rsync"),
`#!/bin/sh
printf '%s\\0' "$*" >> "${path.join(logDir, "rsync.log")}"
exit 0
`,
);
await writeExecutable(
path.join(binDir, "ssh"),
`#!/bin/sh
printf '%s\\0' "$*" >> "${path.join(logDir, "ssh.log")}"
exit 0
`,
);
await writeExecutable(
path.join(binDir, "sshpass"),
`#!/bin/sh
if [ "$1" = "-e" ]; then
shift
fi
exec "$@"
`,
);
try {
await execFileAsync("zsh", [path.join(repoRoot, "scripts/deploy-server.sh")], {
cwd: repoRoot,
env: {
...process.env,
PATH: `${binDir}:${process.env.PATH ?? ""}`,
},
});
const rsyncLog = await readFile(path.join(logDir, "rsync.log"), "utf8");
const rsyncArgs = rsyncLog
.split("\0")
.map((line) => line.trim())
.filter(Boolean)
.join(" ");
assert.match(rsyncArgs, /--exclude \.next/);
const sshLog = await readFile(path.join(logDir, "ssh.log"), "utf8");
const sshCalls = sshLog
.split("\0")
.map((line) => line.trim())
.filter(Boolean);
assert.equal(sshCalls.length, 2);
assert.match(sshCalls[1] ?? "", /npm install && BOSS_RUNTIME_ROOT=\/opt\/boss BOSS_STATE_FILE=\/opt\/boss\/data\/boss-state\.json npm run build/);
assert.match(sshCalls[1] ?? "", /npm prune --omit=dev/);
assert.doesNotMatch(sshCalls[1] ?? "", /npm install --omit=dev/);
} finally {
await rm(tempRoot, { recursive: true, force: true });
}
});