-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab-tmp.mjs
More file actions
56 lines (51 loc) · 1.89 KB
/
Copy pathlab-tmp.mjs
File metadata and controls
56 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
* ClawFix review lab on Blaxel.
*
* The repo's own scripts/blaxel-lab.mjs provisions from a pushed commit; this work is local
* only, so this uploads the working tree instead.
*/
import { SandboxInstance } from '@blaxel/core';
const NAME = process.env.LAB_NAME || 'clawfix-review-lab';
export async function lab() {
return SandboxInstance.createIfNotExists({
name: NAME,
image: 'blaxel/base-image:latest',
memory: 8192,
region: process.env.BL_REGION || 'us-pdx-1',
ports: [
{ name: 'clawfix', target: 3001, protocol: 'HTTP' },
{ name: 'openclaw', target: 18789, protocol: 'HTTP' },
],
envs: [{ name: 'SANDBOX_DISABLE_PROCESS_LOGGING', value: 'true' }],
labels: { project: 'clawfix', purpose: 'review-upgrade-pass' },
ttl: '24h',
});
}
export async function sh(sandbox, name, command, { workingDir = '/app/clawfix', timeout = 900, allowFail = false } = {}) {
const result = await sandbox.process.exec({
name: `${name}-${Math.random().toString(36).slice(2, 8)}`,
command,
workingDir,
waitForCompletion: true,
timeout,
restartOnFailure: false,
});
const out = `${result.stdout || ''}${result.stderr || ''}`;
if (!allowFail && result.exitCode !== 0) {
throw new Error(`[${name}] exit ${result.exitCode}\n${out.slice(-4000)}`);
}
return { exitCode: result.exitCode, out };
}
if (import.meta.url === `file://${process.argv[1]}`) {
const sandbox = await lab();
console.log(JSON.stringify({
name: sandbox.metadata.name,
status: sandbox.status,
image: sandbox.spec?.runtime?.image,
memory: sandbox.spec?.runtime?.memory,
expiresIn: sandbox.expiresIn,
}, null, 2));
const probe = await sh(sandbox, 'probe', 'uname -a; cat /etc/os-release | head -3; node --version 2>/dev/null || echo "no node"; which apk apt-get 2>/dev/null', { workingDir: '/', allowFail: true });
console.log(probe.out);
}