relayrunner 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/cli.js +314 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,13 @@ resume it without going offline (see `relayrunner pause`). The terminal tab's
|
|
|
40
40
|
title shows the machine and what it's doing, such as
|
|
41
41
|
`RelayRunner · M3P0 · Waiting for jobs`.
|
|
42
42
|
|
|
43
|
+
`connect` installs the latest GitHub runner when it starts. While it stays
|
|
44
|
+
open, it checks for a newer one every 6 hours, waiting until no job is running,
|
|
45
|
+
or going ahead after a busy day. New jobs run on the new runner, and a job
|
|
46
|
+
that's already running finishes on the one it started with. GitHub stops
|
|
47
|
+
sending jobs to a runner about 30 days after a newer release, so a machine left
|
|
48
|
+
connected for weeks keeps taking jobs.
|
|
49
|
+
|
|
43
50
|
Before it starts a job, `connect` checks the job's runner config: it must hold
|
|
44
51
|
only the files GitHub's do, every server in it must be GitHub's, over https, and
|
|
45
52
|
the runner must be named for that job. Anything else is refused and reported as
|
|
@@ -48,6 +55,10 @@ server of its own or write files outside the runner. It can't tell a job the
|
|
|
48
55
|
gateway routed here from a runner it minted on a GitHub repo of its own, so the
|
|
49
56
|
terminal shows which repo each job is from.
|
|
50
57
|
|
|
58
|
+
Only one `connect` runs on a computer at a time; a second one stops and says
|
|
59
|
+
so. For an app that runs `connect` for you, `--events` writes one JSON event
|
|
60
|
+
per line to stdout and takes `pause` or `resume` on stdin (see `events.ts`).
|
|
61
|
+
|
|
51
62
|
If another `connect` signs in as this machine while it's online, this one stops
|
|
52
63
|
and says so. When that happens from a different network, the person who
|
|
53
64
|
approved the machine also gets an email, since someone else may have its token.
|
|
@@ -89,7 +100,8 @@ approved the machine also gets an email, since someone else may have its token.
|
|
|
89
100
|
- `--no-isolated` runs jobs on the Mac itself, where they can read your
|
|
90
101
|
files. `--isolated` stops with an error when jobs can't run in VMs.
|
|
91
102
|
- `connect` removes the images it downloaded or built for older runner
|
|
92
|
-
versions. It never removes images you got yourself.
|
|
103
|
+
versions. It never removes images you got yourself. With `--image`, the
|
|
104
|
+
VMs keep your image when a newer runner comes out.
|
|
93
105
|
- `~/.relayrunner/isolated.log` records each `container` command and its
|
|
94
106
|
result, never a job's output or credentials. Send it along when you report
|
|
95
107
|
a problem.
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ import { Readable, Transform } from "node:stream";
|
|
|
11
11
|
import { pipeline } from "node:stream/promises";
|
|
12
12
|
import { styleText } from "node:util";
|
|
13
13
|
import { Scalar, YAMLSeq, isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
14
|
+
import { createInterface } from "node:readline";
|
|
14
15
|
const version$1 = z.literal(1);
|
|
15
16
|
const routeId = z.string().min(1);
|
|
16
17
|
const DeviceKind = z.enum([
|
|
@@ -64,7 +65,8 @@ const StatusMessage = z.object({
|
|
|
64
65
|
v: version$1,
|
|
65
66
|
type: z.literal("status"),
|
|
66
67
|
state: z.enum(["idle", "busy"]),
|
|
67
|
-
running: z.number().int().nonnegative().max(1e3).optional()
|
|
68
|
+
running: z.number().int().nonnegative().max(1e3).optional(),
|
|
69
|
+
runnerVersion: z.string().min(1).optional()
|
|
68
70
|
});
|
|
69
71
|
const JobUsage = z.object({
|
|
70
72
|
cpuP95: z.number().min(0).max(1),
|
|
@@ -184,7 +186,7 @@ function parse(version) {
|
|
|
184
186
|
] : null;
|
|
185
187
|
}
|
|
186
188
|
// version.ts
|
|
187
|
-
const cliVersion = "0.
|
|
189
|
+
const cliVersion = "0.12.0";
|
|
188
190
|
// paths.ts
|
|
189
191
|
function relayrunnerHome() {
|
|
190
192
|
return resolve(process.env.RELAYRUNNER_HOME || join(homedir(), ".relayrunner"));
|
|
@@ -221,12 +223,20 @@ async function connect(options) {
|
|
|
221
223
|
if (socket?.readyState === WebSocket.OPEN) socket.send(encodeMessage(message));
|
|
222
224
|
else if (message.type === "job") pending.push(message);
|
|
223
225
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
const runnerVersion = () => options.runnerVersion?.() ?? options.hello.runnerVersion;
|
|
227
|
+
let saidVersion = "";
|
|
228
|
+
const sendStatus = () => {
|
|
229
|
+
const version = runnerVersion();
|
|
230
|
+
const changed = version !== saidVersion && socket?.readyState === WebSocket.OPEN;
|
|
231
|
+
send({
|
|
232
|
+
v: 1,
|
|
233
|
+
type: "status",
|
|
234
|
+
state: busy.size > 0 ? "busy" : "idle",
|
|
235
|
+
running: busy.size,
|
|
236
|
+
...changed && { runnerVersion: version }
|
|
237
|
+
});
|
|
238
|
+
if (changed) saidVersion = version;
|
|
239
|
+
};
|
|
230
240
|
const saveToken = (next) => {
|
|
231
241
|
if (!options.saveToken) return;
|
|
232
242
|
try {
|
|
@@ -318,10 +328,12 @@ async function connect(options) {
|
|
|
318
328
|
opened = true;
|
|
319
329
|
emit({ type: "connected" });
|
|
320
330
|
const rotatesToken = options.saveToken ? true : void 0;
|
|
331
|
+
saidVersion = runnerVersion();
|
|
321
332
|
ws.send(encodeMessage({
|
|
322
333
|
v: 1,
|
|
323
334
|
type: "hello",
|
|
324
335
|
...options.hello,
|
|
336
|
+
runnerVersion: saidVersion,
|
|
325
337
|
slots,
|
|
326
338
|
rotatesToken
|
|
327
339
|
}));
|
|
@@ -1247,11 +1259,21 @@ function takeLock(lock) {
|
|
|
1247
1259
|
return true;
|
|
1248
1260
|
} catch (error) {
|
|
1249
1261
|
if (error.code !== "EEXIST") throw error;
|
|
1250
|
-
if (
|
|
1262
|
+
if (lockHolder(lock)) return false;
|
|
1251
1263
|
rmSync(lock, { force: true });
|
|
1252
1264
|
}
|
|
1253
1265
|
return false;
|
|
1254
1266
|
}
|
|
1267
|
+
/** The pid of the live process holding a lock taken with takeLock, or null. */
|
|
1268
|
+
function lockHolder(lock) {
|
|
1269
|
+
let pid;
|
|
1270
|
+
try {
|
|
1271
|
+
pid = Number(readlinkSync(lock));
|
|
1272
|
+
} catch {
|
|
1273
|
+
return null;
|
|
1274
|
+
}
|
|
1275
|
+
return isAlive(pid) ? pid : null;
|
|
1276
|
+
}
|
|
1255
1277
|
function isAlive(pid) {
|
|
1256
1278
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
1257
1279
|
try {
|
|
@@ -1470,7 +1492,7 @@ async function prepareIsolation(options) {
|
|
|
1470
1492
|
image
|
|
1471
1493
|
], debug, true) === 0;
|
|
1472
1494
|
const fail = (code, message) => new RunnerError(code, debug.path ? `${message} Details are in ${debug.path}.` : message);
|
|
1473
|
-
const latest = latestRunnerVersion(log);
|
|
1495
|
+
const latest = options.runnerVersion ? Promise.resolve(options.runnerVersion) : latestRunnerVersion(log);
|
|
1474
1496
|
latest.catch(() => {});
|
|
1475
1497
|
const [status] = await Promise.all([tool(["system", "status"]), tool(["--version"])]);
|
|
1476
1498
|
if (status === null) throw new RunnerError("ISOLATED_SETUP", `Running jobs in VMs needs Apple's container tool. Install it from ${RELEASES}, then run \`container system start\`.`);
|
|
@@ -1523,18 +1545,19 @@ async function prepareIsolation(options) {
|
|
|
1523
1545
|
await tool(["builder", "delete"]);
|
|
1524
1546
|
}
|
|
1525
1547
|
}
|
|
1526
|
-
await pruneImages(options.managed ?? managedImagesFile(), [
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1548
|
+
await pruneImages(options.managed ?? managedImagesFile(), [
|
|
1549
|
+
base,
|
|
1550
|
+
image,
|
|
1551
|
+
...options.keep ?? []
|
|
1552
|
+
], mine, tool, log);
|
|
1531
1553
|
return {
|
|
1532
1554
|
command,
|
|
1555
|
+
base,
|
|
1533
1556
|
image,
|
|
1534
1557
|
localNetwork,
|
|
1535
1558
|
debug,
|
|
1536
1559
|
runnerVersion,
|
|
1537
|
-
...size
|
|
1560
|
+
...vmSize(options.slots, options.size)
|
|
1538
1561
|
};
|
|
1539
1562
|
}
|
|
1540
1563
|
function managedImagesFile() {
|
|
@@ -1727,6 +1750,12 @@ const RATES = {
|
|
|
1727
1750
|
standard: "vcpu",
|
|
1728
1751
|
premium: "vcpu"
|
|
1729
1752
|
},
|
|
1753
|
+
boat: {
|
|
1754
|
+
"boat-small": "runner",
|
|
1755
|
+
boat: "runner",
|
|
1756
|
+
"boat-large": "runner",
|
|
1757
|
+
"boat-xlarge": "runner"
|
|
1758
|
+
},
|
|
1730
1759
|
github: {
|
|
1731
1760
|
"linux-1-core": "runner",
|
|
1732
1761
|
"linux-2-core": "runner",
|
|
@@ -1736,6 +1765,19 @@ const RATES = {
|
|
|
1736
1765
|
macos: "runner"
|
|
1737
1766
|
}
|
|
1738
1767
|
};
|
|
1768
|
+
/**
|
|
1769
|
+
* The `runs-on` label GitHub's docs give each standard runner, the name people know it by. Where
|
|
1770
|
+
* one runner has several labels (`ubuntu-latest`, `ubuntu-24.04`), this is the first one listed.
|
|
1771
|
+
* macOS has none: one rate covers several images (`macos-latest`, `macos-15-intel`), so it stays
|
|
1772
|
+
* "macOS". https://docs.github.com/en/actions/reference/runners/github-hosted-runners
|
|
1773
|
+
*/
|
|
1774
|
+
const GITHUB_LABELS = {
|
|
1775
|
+
"linux-1-core": "ubuntu-slim",
|
|
1776
|
+
"linux-2-core": "ubuntu-latest",
|
|
1777
|
+
"linux-arm-2-core": "ubuntu-24.04-arm",
|
|
1778
|
+
"windows-2-core": "windows-latest",
|
|
1779
|
+
"windows-arm-2-core": "windows-11-arm"
|
|
1780
|
+
};
|
|
1739
1781
|
/** The one rate a provider operators added has: a minute of any of its runners. */
|
|
1740
1782
|
const ADDED_RATE = "runner";
|
|
1741
1783
|
/**
|
|
@@ -1847,6 +1889,30 @@ const BASE_PRICES = [
|
|
|
1847
1889
|
usd: vcpu(.002, 2),
|
|
1848
1890
|
from: "2026-09-01"
|
|
1849
1891
|
},
|
|
1892
|
+
{
|
|
1893
|
+
provider: "boat",
|
|
1894
|
+
rate: "boat-small",
|
|
1895
|
+
usd: .018 / 60,
|
|
1896
|
+
from: "2026-11-16"
|
|
1897
|
+
},
|
|
1898
|
+
{
|
|
1899
|
+
provider: "boat",
|
|
1900
|
+
rate: "boat",
|
|
1901
|
+
usd: .036 / 60,
|
|
1902
|
+
from: "2026-11-16"
|
|
1903
|
+
},
|
|
1904
|
+
{
|
|
1905
|
+
provider: "boat",
|
|
1906
|
+
rate: "boat-large",
|
|
1907
|
+
usd: .072 / 60,
|
|
1908
|
+
from: "2026-11-16"
|
|
1909
|
+
},
|
|
1910
|
+
{
|
|
1911
|
+
provider: "boat",
|
|
1912
|
+
rate: "boat-xlarge",
|
|
1913
|
+
usd: .2 / 60,
|
|
1914
|
+
from: "2026-11-16"
|
|
1915
|
+
},
|
|
1850
1916
|
{
|
|
1851
1917
|
provider: "github",
|
|
1852
1918
|
rate: "linux-1-core",
|
|
@@ -1913,6 +1979,7 @@ function priceBook(rows) {
|
|
|
1913
1979
|
changes: [...changes].sort((a, b) => a - b)
|
|
1914
1980
|
};
|
|
1915
1981
|
}
|
|
1982
|
+
({ ...GITHUB_LABELS });
|
|
1916
1983
|
priceBook(BASE_PRICES);
|
|
1917
1984
|
// ../../packages/providers/src/index.ts
|
|
1918
1985
|
/**
|
|
@@ -1927,6 +1994,7 @@ const HOSTED_PROVIDER_IDS = [
|
|
|
1927
1994
|
"namespace",
|
|
1928
1995
|
"warpbuild",
|
|
1929
1996
|
"ubicloud",
|
|
1997
|
+
"boat",
|
|
1930
1998
|
"runs-on"
|
|
1931
1999
|
];
|
|
1932
2000
|
const LABEL_PREFIXES = {
|
|
@@ -1935,6 +2003,7 @@ const LABEL_PREFIXES = {
|
|
|
1935
2003
|
namespace: ["namespace-profile-", "nscloud-"],
|
|
1936
2004
|
warpbuild: ["warp-"],
|
|
1937
2005
|
ubicloud: ["ubicloud-"],
|
|
2006
|
+
boat: ["boat-", "boat/"],
|
|
1938
2007
|
"runs-on": ["runs-on=", "runs-on/"]
|
|
1939
2008
|
};
|
|
1940
2009
|
/** Whether a lowercase label starts with one of `prefixes`, or is the bare name one ends in `-`. */
|
|
@@ -1947,7 +2016,7 @@ function hostedProviderOf(label) {
|
|
|
1947
2016
|
}
|
|
1948
2017
|
// workflows.ts
|
|
1949
2018
|
/** The relay version `init` writes. Bump it with each relayrunner/actions release. */
|
|
1950
|
-
const RELAY_REF = "v1.0.0-beta.
|
|
2019
|
+
const RELAY_REF = "v1.0.0-beta.6";
|
|
1951
2020
|
const RELAY_WORKFLOW = "relayrunner/actions/.github/workflows/relay.yml";
|
|
1952
2021
|
const DEPLOY_SECRET = /\bsecrets\.(?!GITHUB_TOKEN\b)[A-Za-z_][A-Za-z0-9_]*/;
|
|
1953
2022
|
const LINUX_PACKAGE_MANAGER = /(^|[\s;&|(])(sudo\s+)?(apt-get|apt|yum|dnf|apk)\s+(install|update|add)\b/m;
|
|
@@ -2393,6 +2462,46 @@ async function defaultMachineName(run$1 = run, system = platform(), host = hostn
|
|
|
2393
2462
|
names.push(host.replace(/\.local$/i, ""));
|
|
2394
2463
|
return (names.find((name) => name?.trim()) ?? "").trim().slice(0, MAX_LENGTH);
|
|
2395
2464
|
}
|
|
2465
|
+
// runner-update.ts
|
|
2466
|
+
const RUNNER_CHECK_MS = 216e5;
|
|
2467
|
+
const BUSY_RETRY_MS = 6e5;
|
|
2468
|
+
const MAX_WAIT_MS = 864e5;
|
|
2469
|
+
function keepRunnerUpdated(options) {
|
|
2470
|
+
const checkMs = options.checkMs ?? RUNNER_CHECK_MS;
|
|
2471
|
+
const busyRetryMs = options.busyRetryMs ?? BUSY_RETRY_MS;
|
|
2472
|
+
const maxWaitMs = options.maxWaitMs ?? MAX_WAIT_MS;
|
|
2473
|
+
const latest = options.latest ?? (() => latestRunnerVersion());
|
|
2474
|
+
let dueAt = Date.now() + checkMs;
|
|
2475
|
+
let timer;
|
|
2476
|
+
let stopped = false;
|
|
2477
|
+
const schedule = (ms) => {
|
|
2478
|
+
if (stopped) return;
|
|
2479
|
+
timer = setTimeout(check, ms);
|
|
2480
|
+
timer.unref();
|
|
2481
|
+
};
|
|
2482
|
+
const check = async () => {
|
|
2483
|
+
if (options.running() > 0 && Date.now() - dueAt < maxWaitMs) return schedule(busyRetryMs);
|
|
2484
|
+
try {
|
|
2485
|
+
const version = await latest();
|
|
2486
|
+
const current = options.current();
|
|
2487
|
+
if (!stopped && isNewerVersion(version, current)) {
|
|
2488
|
+
options.log(`Updating the runner to actions/runner ${version}…`);
|
|
2489
|
+
await options.update(version);
|
|
2490
|
+
const running = options.running();
|
|
2491
|
+
options.log(running > 0 ? `New jobs run on actions/runner ${version}. Jobs already running finish on ${current}.` : `Jobs now run on actions/runner ${version}.`);
|
|
2492
|
+
}
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
options.log(`Couldn't update the runner (${error instanceof Error ? error.message : String(error)}). Trying again later.`);
|
|
2495
|
+
}
|
|
2496
|
+
dueAt = Date.now() + checkMs;
|
|
2497
|
+
schedule(checkMs);
|
|
2498
|
+
};
|
|
2499
|
+
schedule(checkMs);
|
|
2500
|
+
return () => {
|
|
2501
|
+
stopped = true;
|
|
2502
|
+
clearTimeout(timer);
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2396
2505
|
// live.ts
|
|
2397
2506
|
const INITIAL_STATE = {
|
|
2398
2507
|
link: "connecting",
|
|
@@ -2506,6 +2615,73 @@ function startLive(options) {
|
|
|
2506
2615
|
}
|
|
2507
2616
|
};
|
|
2508
2617
|
}
|
|
2618
|
+
// events.ts
|
|
2619
|
+
const EVENTS_VERSION = 1;
|
|
2620
|
+
let write = null;
|
|
2621
|
+
/** Sends stdout's writes to stderr from now on, and keeps stdout for emitEvent. */
|
|
2622
|
+
function startEvents() {
|
|
2623
|
+
if (write) return;
|
|
2624
|
+
const { stdout, stderr } = process;
|
|
2625
|
+
const toStdout = stdout.write.bind(stdout);
|
|
2626
|
+
write = (line) => void toStdout(line);
|
|
2627
|
+
stdout.write = stderr.write.bind(stderr);
|
|
2628
|
+
}
|
|
2629
|
+
/** Writes an event to stdout, when `connect` runs with --events. Otherwise does nothing. */
|
|
2630
|
+
function emitEvent(event, now) {
|
|
2631
|
+
if (!write) return;
|
|
2632
|
+
const at = (now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
2633
|
+
write(`${JSON.stringify({
|
|
2634
|
+
v: EVENTS_VERSION,
|
|
2635
|
+
at,
|
|
2636
|
+
...event
|
|
2637
|
+
})}\n`);
|
|
2638
|
+
}
|
|
2639
|
+
/** The command a line of stdin asks for, or null for anything else. */
|
|
2640
|
+
function parseCommand(line) {
|
|
2641
|
+
const word = line.trim().toLowerCase();
|
|
2642
|
+
return word === "pause" || word === "resume" ? word : null;
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* Reads commands from stdin until stop() is called. onClose runs when stdin closes first.
|
|
2646
|
+
*/
|
|
2647
|
+
function readCommands(options) {
|
|
2648
|
+
const lines = createInterface({
|
|
2649
|
+
input: options.input ?? process.stdin,
|
|
2650
|
+
terminal: false
|
|
2651
|
+
});
|
|
2652
|
+
lines.on("line", (line) => {
|
|
2653
|
+
if (!line.trim()) return;
|
|
2654
|
+
const command = parseCommand(line);
|
|
2655
|
+
if (command) options.onCommand(command);
|
|
2656
|
+
else emitEvent({
|
|
2657
|
+
type: "error",
|
|
2658
|
+
code: "UNKNOWN_COMMAND",
|
|
2659
|
+
message: "Commands are `pause` and `resume`.",
|
|
2660
|
+
command: line.trim()
|
|
2661
|
+
});
|
|
2662
|
+
});
|
|
2663
|
+
lines.once("close", options.onClose);
|
|
2664
|
+
return function stop() {
|
|
2665
|
+
lines.off("close", options.onClose);
|
|
2666
|
+
lines.close();
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
// connect-lock.ts
|
|
2670
|
+
/** Takes the lock, or throws ALREADY_CONNECTED. Returns the function that lets it go. */
|
|
2671
|
+
function lockConnect(home = relayrunnerHome()) {
|
|
2672
|
+
mkdirSync(home, {
|
|
2673
|
+
recursive: true,
|
|
2674
|
+
mode: 448
|
|
2675
|
+
});
|
|
2676
|
+
const lock = join(home, "connect.lock");
|
|
2677
|
+
if (!takeLock(lock)) {
|
|
2678
|
+
const pid = lockHolder(lock);
|
|
2679
|
+
throw new RunnerError("ALREADY_CONNECTED", `\`relayrunner connect\` is already running on this computer${pid ? ` (process ${pid})` : ""}. Stop that one first, or use it instead.`);
|
|
2680
|
+
}
|
|
2681
|
+
return () => {
|
|
2682
|
+
if (lockHolder(lock) === process.pid) rmSync(lock, { force: true });
|
|
2683
|
+
};
|
|
2684
|
+
}
|
|
2509
2685
|
// update-check.ts
|
|
2510
2686
|
const CHECK_INTERVAL_MS = 864e5;
|
|
2511
2687
|
const REGISTRY_URL = "https://registry.npmjs.org/relayrunner/latest";
|
|
@@ -3325,7 +3501,8 @@ async function whoami(options) {
|
|
|
3325
3501
|
const Choice = z.object({
|
|
3326
3502
|
id: z.string().min(1),
|
|
3327
3503
|
name: z.string(),
|
|
3328
|
-
slug: z.string().nullish()
|
|
3504
|
+
slug: z.string().nullish(),
|
|
3505
|
+
logo: z.string().nullish()
|
|
3329
3506
|
});
|
|
3330
3507
|
const MachineWorkspaces = z.object({
|
|
3331
3508
|
machine: z.object({
|
|
@@ -3642,9 +3819,14 @@ const connectCommand = defineCommand({
|
|
|
3642
3819
|
"local-network": {
|
|
3643
3820
|
type: "boolean",
|
|
3644
3821
|
description: "Let jobs in VMs reach this Mac and your local network. They can't by default."
|
|
3822
|
+
},
|
|
3823
|
+
events: {
|
|
3824
|
+
type: "boolean",
|
|
3825
|
+
description: "For apps that run connect: JSON events on stdout, one per line, and `pause` or `resume` on stdin"
|
|
3645
3826
|
}
|
|
3646
3827
|
},
|
|
3647
3828
|
async run({ args }) {
|
|
3829
|
+
if (args.events) startEvents();
|
|
3648
3830
|
clack.intro("RelayRunner");
|
|
3649
3831
|
let concurrency;
|
|
3650
3832
|
let size;
|
|
@@ -3653,11 +3835,12 @@ const connectCommand = defineCommand({
|
|
|
3653
3835
|
concurrency = args.concurrency ? parseConcurrency(args.concurrency) : slotsFor(size) ?? parseConcurrency(void 0);
|
|
3654
3836
|
checkFits(size, concurrency);
|
|
3655
3837
|
} catch (error) {
|
|
3656
|
-
|
|
3657
|
-
process.exitCode = 1;
|
|
3838
|
+
fail("USAGE", error.message);
|
|
3658
3839
|
return;
|
|
3659
3840
|
}
|
|
3841
|
+
let unlock;
|
|
3660
3842
|
try {
|
|
3843
|
+
unlock = lockConnect();
|
|
3661
3844
|
await connectMachine({
|
|
3662
3845
|
...args,
|
|
3663
3846
|
concurrency,
|
|
@@ -3665,11 +3848,21 @@ const connectCommand = defineCommand({
|
|
|
3665
3848
|
});
|
|
3666
3849
|
} catch (error) {
|
|
3667
3850
|
if (!(error instanceof LoginError || error instanceof RunnerError)) throw error;
|
|
3668
|
-
|
|
3669
|
-
|
|
3851
|
+
fail(error.code, error.message);
|
|
3852
|
+
} finally {
|
|
3853
|
+
unlock?.();
|
|
3670
3854
|
}
|
|
3671
3855
|
}
|
|
3672
3856
|
});
|
|
3857
|
+
function fail(code, message) {
|
|
3858
|
+
clack.log.error(message);
|
|
3859
|
+
emitEvent({
|
|
3860
|
+
type: "error",
|
|
3861
|
+
code,
|
|
3862
|
+
message
|
|
3863
|
+
});
|
|
3864
|
+
process.exitCode = 1;
|
|
3865
|
+
}
|
|
3673
3866
|
async function connectMachine(args) {
|
|
3674
3867
|
const share = shareArg(args.share);
|
|
3675
3868
|
const vmFlag = [
|
|
@@ -3703,6 +3896,13 @@ async function connectMachine(args) {
|
|
|
3703
3896
|
clack.log.info(`Machine ${credentials.machine.name} (${credentials.server})`);
|
|
3704
3897
|
if (share) await applySharing(credentials, share, null);
|
|
3705
3898
|
}
|
|
3899
|
+
const { id, name } = credentials.machine;
|
|
3900
|
+
emitEvent({
|
|
3901
|
+
type: "machine",
|
|
3902
|
+
id,
|
|
3903
|
+
name,
|
|
3904
|
+
server: credentials.server
|
|
3905
|
+
});
|
|
3706
3906
|
if (process.stdin.isTTY && process.stdout.isTTY) await offerSetup();
|
|
3707
3907
|
let updateTimer;
|
|
3708
3908
|
if (process.stdout.isTTY && !process.env.CI) {
|
|
@@ -3718,37 +3918,47 @@ async function connectMachine(args) {
|
|
|
3718
3918
|
const onHost = !isolated || args.macos ? ensureRunner({ log }) : void 0;
|
|
3719
3919
|
onHost?.catch(() => {});
|
|
3720
3920
|
let runnerVersion = "";
|
|
3921
|
+
let isolation;
|
|
3721
3922
|
let launchers = [];
|
|
3722
3923
|
let vmLauncher;
|
|
3723
3924
|
let isolatedOnly;
|
|
3724
3925
|
let vmSize;
|
|
3926
|
+
const useRunner = (runner) => {
|
|
3927
|
+
launchers = ensureSlots(runner, slots, log).map(hostLauncher);
|
|
3928
|
+
runnerVersion = runner.version;
|
|
3929
|
+
};
|
|
3930
|
+
const useIsolation = (next) => {
|
|
3931
|
+
const launcher = isolatedLauncher(next);
|
|
3932
|
+
if (args.macos) vmLauncher = launcher;
|
|
3933
|
+
else {
|
|
3934
|
+
launchers = Array.from({ length: slots }, () => isolatedOnly = launcher);
|
|
3935
|
+
runnerVersion = next.runnerVersion;
|
|
3936
|
+
}
|
|
3937
|
+
};
|
|
3938
|
+
const firewall = isolated && firewallInstalled();
|
|
3939
|
+
const isolationOptions = {
|
|
3940
|
+
slots,
|
|
3941
|
+
size: args.size,
|
|
3942
|
+
image: args.image,
|
|
3943
|
+
localNetwork: args["local-network"] && !firewall,
|
|
3944
|
+
log,
|
|
3945
|
+
debug: isolated ? debugLog() : void 0
|
|
3946
|
+
};
|
|
3725
3947
|
if (isolated) {
|
|
3726
|
-
const firewall = firewallInstalled();
|
|
3727
3948
|
if (firewall) log(args["local-network"] ? "The firewall on this Mac is on, so --local-network has no effect. Turn it off with `relayrunner firewall off`." : "The firewall on this Mac is on.");
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
size: args.size,
|
|
3731
|
-
image: args.image,
|
|
3732
|
-
localNetwork: args["local-network"] && !firewall,
|
|
3733
|
-
log,
|
|
3734
|
-
debug: debugLog()
|
|
3735
|
-
});
|
|
3736
|
-
runnerVersion = isolation.runnerVersion;
|
|
3949
|
+
isolation = await prepareIsolation(isolationOptions);
|
|
3950
|
+
useIsolation(isolation);
|
|
3737
3951
|
vmSize = {
|
|
3738
3952
|
cpus: isolation.cpus,
|
|
3739
3953
|
memoryGb: isolation.memoryGb
|
|
3740
3954
|
};
|
|
3741
|
-
|
|
3742
|
-
if (
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
log("Jobs run in a Linux VM on this Mac. To take macOS jobs too, run `relayrunner connect --macos`.");
|
|
3746
|
-
}
|
|
3955
|
+
log(`Each job runs in its own Linux VM with ${vmSize.cpus} CPUs and ${vmSize.memoryGb} GB of memory.`);
|
|
3956
|
+
if (isolation.localNetwork) log("Jobs can reach this Mac and your local network.");
|
|
3957
|
+
if (isolation.debug.path) log(`If something goes wrong, ${isolation.debug.path} has the details.`);
|
|
3958
|
+
if (!args.macos) log("Jobs run in a Linux VM on this Mac. To take macOS jobs too, run `relayrunner connect --macos`.");
|
|
3747
3959
|
}
|
|
3748
3960
|
if (onHost) {
|
|
3749
|
-
|
|
3750
|
-
runnerVersion = runner.version;
|
|
3751
|
-
launchers = ensureSlots(runner, slots, log).map(hostLauncher);
|
|
3961
|
+
useRunner(await onHost);
|
|
3752
3962
|
const hint = !isolated && state ? setupHint(state) : null;
|
|
3753
3963
|
if (hint) clack.log.warn(hint);
|
|
3754
3964
|
if (args.macos) clack.log.warn("Linux jobs run in a VM. macOS jobs run on this Mac itself, where they can read your files. Only take macOS jobs from repos you trust.");
|
|
@@ -3756,18 +3966,43 @@ async function connectMachine(args) {
|
|
|
3756
3966
|
}
|
|
3757
3967
|
clack.log.info(slots === 1 ? "Running 1 job at a time. Change with --concurrency." : `Running up to ${slots} jobs at once. Change with --concurrency.`);
|
|
3758
3968
|
const device = await detectDevice();
|
|
3969
|
+
let running = 0;
|
|
3970
|
+
const stopUpdating = onHost || isolation && !args.image ? keepRunnerUpdated({
|
|
3971
|
+
current: () => runnerVersion,
|
|
3972
|
+
running: () => running,
|
|
3973
|
+
log,
|
|
3974
|
+
update: async (version) => {
|
|
3975
|
+
const [vm, runner] = await Promise.all([isolation && !args.image && prepareIsolation({
|
|
3976
|
+
...isolationOptions,
|
|
3977
|
+
runnerVersion: version,
|
|
3978
|
+
keep: [isolation.base, isolation.image]
|
|
3979
|
+
}), onHost && ensureRunner({ log })]);
|
|
3980
|
+
if (vm) useIsolation(isolation = vm);
|
|
3981
|
+
if (runner) useRunner(runner);
|
|
3982
|
+
}
|
|
3983
|
+
}) : void 0;
|
|
3759
3984
|
const stop = new AbortController();
|
|
3760
3985
|
const enrolled = credentials;
|
|
3761
3986
|
let toggling = false;
|
|
3987
|
+
const setPaused = async (paused) => {
|
|
3988
|
+
if (toggling || stop.signal.aborted) return;
|
|
3989
|
+
toggling = true;
|
|
3990
|
+
const result = await pauseMachine(enrolled, paused);
|
|
3991
|
+
toggling = false;
|
|
3992
|
+
if (result.status !== "failed") return;
|
|
3993
|
+
const command = paused ? "pause" : "resume";
|
|
3994
|
+
const message = `Couldn't ${command}: ${result.reason}.`;
|
|
3995
|
+
clack.log.error(message);
|
|
3996
|
+
emitEvent({
|
|
3997
|
+
type: "error",
|
|
3998
|
+
code: "PAUSE_FAILED",
|
|
3999
|
+
message,
|
|
4000
|
+
command
|
|
4001
|
+
});
|
|
4002
|
+
};
|
|
3762
4003
|
const live = startLive({
|
|
3763
4004
|
machine: enrolled.machine.name,
|
|
3764
|
-
onTogglePause:
|
|
3765
|
-
if (toggling || stop.signal.aborted) return;
|
|
3766
|
-
toggling = true;
|
|
3767
|
-
const result = await pauseMachine(enrolled, !paused);
|
|
3768
|
-
toggling = false;
|
|
3769
|
-
if (result.status === "failed") clack.log.error(`Couldn't ${paused ? "resume" : "pause"}: ${result.reason}.`);
|
|
3770
|
-
}
|
|
4005
|
+
onTogglePause: ({ paused }) => void setPaused(!paused)
|
|
3771
4006
|
});
|
|
3772
4007
|
const onInterrupt = () => {
|
|
3773
4008
|
if (stop.signal.aborted) {
|
|
@@ -3777,6 +4012,10 @@ async function connectMachine(args) {
|
|
|
3777
4012
|
stop.abort();
|
|
3778
4013
|
};
|
|
3779
4014
|
process.on("SIGINT", onInterrupt);
|
|
4015
|
+
const stopCommands = args.events ? readCommands({
|
|
4016
|
+
onCommand: (command) => void setPaused(command === "pause"),
|
|
4017
|
+
onClose: onInterrupt
|
|
4018
|
+
}) : void 0;
|
|
3780
4019
|
let online = false;
|
|
3781
4020
|
let end;
|
|
3782
4021
|
try {
|
|
@@ -3791,6 +4030,7 @@ async function connectMachine(args) {
|
|
|
3791
4030
|
device,
|
|
3792
4031
|
...vmSize && { vm: vmSize }
|
|
3793
4032
|
},
|
|
4033
|
+
runnerVersion: () => runnerVersion,
|
|
3794
4034
|
slots,
|
|
3795
4035
|
runJob: async (run, slot, report) => {
|
|
3796
4036
|
const prefixed = slots > 1 ? prefixLines(`[slot ${slot}] `, (chunk, stream) => (stream === "stdout" ? process.stdout : process.stderr).write(chunk)) : void 0;
|
|
@@ -3804,16 +4044,24 @@ async function connectMachine(args) {
|
|
|
3804
4044
|
report(update);
|
|
3805
4045
|
return update;
|
|
3806
4046
|
}
|
|
4047
|
+
running++;
|
|
3807
4048
|
try {
|
|
3808
4049
|
return await runJob(run, {
|
|
3809
4050
|
launcher,
|
|
3810
4051
|
report,
|
|
3811
4052
|
output: prefixed?.output,
|
|
3812
4053
|
onChecked: (target) => {
|
|
3813
|
-
if (target)
|
|
4054
|
+
if (!target) return;
|
|
4055
|
+
clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId}${slots > 1 ? ` (slot ${slot})` : ""} is from ${target}`);
|
|
4056
|
+
emitEvent({
|
|
4057
|
+
type: "job-repo",
|
|
4058
|
+
routeId: run.routeId,
|
|
4059
|
+
repo: target
|
|
4060
|
+
});
|
|
3814
4061
|
}
|
|
3815
4062
|
});
|
|
3816
4063
|
} finally {
|
|
4064
|
+
running--;
|
|
3817
4065
|
prefixed?.flush();
|
|
3818
4066
|
}
|
|
3819
4067
|
},
|
|
@@ -3821,15 +4069,27 @@ async function connectMachine(args) {
|
|
|
3821
4069
|
onEvent: (event) => {
|
|
3822
4070
|
if (event.type === "connected") online = true;
|
|
3823
4071
|
show(event, slots > 1);
|
|
4072
|
+
const before = live.state;
|
|
3824
4073
|
live.onEvent(event);
|
|
4074
|
+
emitEvent(event);
|
|
4075
|
+
if (live.state !== before) emitEvent({
|
|
4076
|
+
type: "state",
|
|
4077
|
+
...live.state
|
|
4078
|
+
});
|
|
3825
4079
|
},
|
|
3826
4080
|
signal: stop.signal
|
|
3827
4081
|
});
|
|
3828
4082
|
} finally {
|
|
3829
4083
|
clearInterval(updateTimer);
|
|
4084
|
+
stopUpdating?.();
|
|
3830
4085
|
live.end();
|
|
4086
|
+
stopCommands?.();
|
|
3831
4087
|
process.off("SIGINT", onInterrupt);
|
|
3832
4088
|
}
|
|
4089
|
+
emitEvent({
|
|
4090
|
+
type: "offline",
|
|
4091
|
+
...end
|
|
4092
|
+
});
|
|
3833
4093
|
switch (end.reason) {
|
|
3834
4094
|
case "stopped":
|
|
3835
4095
|
clack.outro("Offline.");
|
|
@@ -3980,6 +4240,11 @@ async function signIn(server, name, platform) {
|
|
|
3980
4240
|
platform,
|
|
3981
4241
|
onCode: ({ userCode, url }) => {
|
|
3982
4242
|
clack.note(`${url}\n\nConfirm the code ${userCode} matches the one in your browser.`, "Sign in");
|
|
4243
|
+
emitEvent({
|
|
4244
|
+
type: "sign-in",
|
|
4245
|
+
url,
|
|
4246
|
+
code: userCode
|
|
4247
|
+
});
|
|
3983
4248
|
openBrowser(url);
|
|
3984
4249
|
waiting.start("Waiting for approval in the browser");
|
|
3985
4250
|
}
|