@kvbox/cli 0.5.35 → 0.5.37
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/dist/kvbox.js +449 -133
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/program.ts
|
|
152
|
-
import { Command as
|
|
152
|
+
import { Command as Command76 } from "commander";
|
|
153
153
|
|
|
154
154
|
// ../shared/src/version.ts
|
|
155
155
|
import { createRequire } from "module";
|
|
@@ -164,10 +164,10 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.37" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
|
-
import { Command as
|
|
170
|
+
import { Command as Command37 } from "commander";
|
|
171
171
|
|
|
172
172
|
// src/commands/vm/connect.ts
|
|
173
173
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
@@ -241,6 +241,8 @@ function paths(home = kvboxHome()) {
|
|
|
241
241
|
env: join(dir, "env.json"),
|
|
242
242
|
/** The box's writable layer, stacked on the read-only base image inside the guest. */
|
|
243
243
|
overlay: join(dir, "overlay.ext4"),
|
|
244
|
+
/** A restore's disk while it downloads (a backup's chunks), renamed over `overlay` once complete. */
|
|
245
|
+
restoring: join(dir, "overlay.ext4.restore"),
|
|
244
246
|
/**
|
|
245
247
|
* The box's memory as of its last snapshot (a hard link to that snapshot's `mem`, never modified).
|
|
246
248
|
* The next snapshot is a diff of the pages dirtied since, merged onto this. Absent after a boot.
|
|
@@ -279,6 +281,16 @@ function paths(home = kvboxHome()) {
|
|
|
279
281
|
/** Each owner's environment variables as the control plane last sent them (#88): env/<owner>.json, mode 600. */
|
|
280
282
|
env: join(home, "env"),
|
|
281
283
|
ownerEnv: (owner) => join(home, "env", `${owner}.json`),
|
|
284
|
+
/**
|
|
285
|
+
* Backups in progress (decision "Backups: encrypted 4 MiB chunks in object storage"): backups/<id>/ holds the
|
|
286
|
+
* copy of the box's disk being uploaded and its chunk list, gone once the upload ends. Nothing here outlives
|
|
287
|
+
* a daemon restart.
|
|
288
|
+
*/
|
|
289
|
+
backups: join(home, "backups"),
|
|
290
|
+
backup: (id) => {
|
|
291
|
+
const dir = join(home, "backups", id);
|
|
292
|
+
return { dir, disk: join(dir, "disk.ext4"), chunks: join(dir, "chunks.json") };
|
|
293
|
+
},
|
|
282
294
|
snapshot: (owner, name) => {
|
|
283
295
|
const dir = join(home, "snapshots", owner, name);
|
|
284
296
|
return {
|
|
@@ -486,6 +498,52 @@ var WakeHookCallSchema = z2.object({
|
|
|
486
498
|
action: z2.enum(["wake", "resume", "none"]),
|
|
487
499
|
reason: z2.string().optional()
|
|
488
500
|
});
|
|
501
|
+
var BACKUP_STATUSES = ["running", "ready", "failed"];
|
|
502
|
+
var BackupSchema = z2.object({
|
|
503
|
+
id: z2.string(),
|
|
504
|
+
owner: z2.string(),
|
|
505
|
+
box: z2.string(),
|
|
506
|
+
status: z2.enum(BACKUP_STATUSES),
|
|
507
|
+
/** Why it failed; null otherwise. */
|
|
508
|
+
error: z2.string().nullable(),
|
|
509
|
+
/** The image version the disk stacks on (a restore needs it on the host), and the image (absent: base). */
|
|
510
|
+
base: z2.string().nullable(),
|
|
511
|
+
image: z2.string().optional(),
|
|
512
|
+
vcpu: z2.number().int().nullable(),
|
|
513
|
+
memMib: z2.number().int().nullable(),
|
|
514
|
+
/** The disk's size. */
|
|
515
|
+
diskBytes: z2.number().int().nullable(),
|
|
516
|
+
/** What it holds: the slots that are not all zeros. */
|
|
517
|
+
dataBytes: z2.number().int().nullable(),
|
|
518
|
+
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
519
|
+
uploadedBytes: z2.number().int().nullable(),
|
|
520
|
+
createdBy: z2.string().nullable(),
|
|
521
|
+
createdAt: z2.string(),
|
|
522
|
+
finishedAt: z2.string().nullable()
|
|
523
|
+
});
|
|
524
|
+
var HostBackupRequest = z2.object({ id: z2.string(), key: z2.string() });
|
|
525
|
+
var HostBackupManifestSchema = z2.object({
|
|
526
|
+
id: z2.string(),
|
|
527
|
+
sizeBytes: z2.number().int(),
|
|
528
|
+
chunks: z2.array(z2.string().nullable()),
|
|
529
|
+
env: z2.string().nullable(),
|
|
530
|
+
base: z2.string(),
|
|
531
|
+
image: z2.string().optional(),
|
|
532
|
+
vcpu: z2.number().int(),
|
|
533
|
+
memMib: z2.number().int()
|
|
534
|
+
});
|
|
535
|
+
var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()) });
|
|
536
|
+
var HostUploadResultSchema = z2.object({ chunks: z2.number().int(), bytes: z2.number().int(), sizes: z2.record(z2.string(), z2.number().int()) });
|
|
537
|
+
var HostRestoreRequest = z2.object({
|
|
538
|
+
/** The backup's id: its variables were sealed under it. */
|
|
539
|
+
id: z2.string(),
|
|
540
|
+
key: z2.string(),
|
|
541
|
+
sizeBytes: z2.number().int().positive(),
|
|
542
|
+
base: z2.string(),
|
|
543
|
+
image: z2.string().optional(),
|
|
544
|
+
env: z2.string().nullable(),
|
|
545
|
+
chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() }))
|
|
546
|
+
});
|
|
489
547
|
var MachineSchema = z2.object({
|
|
490
548
|
/** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
|
|
491
549
|
id: z2.string(),
|
|
@@ -1118,7 +1176,7 @@ var ServerClient = class {
|
|
|
1118
1176
|
base;
|
|
1119
1177
|
autoStart;
|
|
1120
1178
|
startedOnce = false;
|
|
1121
|
-
async call(method, path, schema, body, org = this.target.kind === "cloud" ? this.target.org : void 0) {
|
|
1179
|
+
async call(method, path, schema, body, org = this.target.kind === "cloud" ? this.target.org : void 0, timeoutMs) {
|
|
1122
1180
|
const headers = {};
|
|
1123
1181
|
if (body !== void 0) headers["content-type"] = "application/json";
|
|
1124
1182
|
if (this.target.kind === "cloud" && this.target.token !== "") headers["authorization"] = `Bearer ${this.target.token}`;
|
|
@@ -1129,7 +1187,8 @@ var ServerClient = class {
|
|
|
1129
1187
|
dispatcher: this.dispatcher,
|
|
1130
1188
|
method,
|
|
1131
1189
|
headers,
|
|
1132
|
-
body: body === void 0 ? null : JSON.stringify(body)
|
|
1190
|
+
body: body === void 0 ? null : JSON.stringify(body),
|
|
1191
|
+
...timeoutMs !== void 0 ? { headersTimeout: timeoutMs, bodyTimeout: timeoutMs } : {}
|
|
1133
1192
|
});
|
|
1134
1193
|
} catch (err) {
|
|
1135
1194
|
const code = err.code ?? err.cause;
|
|
@@ -1137,7 +1196,7 @@ var ServerClient = class {
|
|
|
1137
1196
|
if (this.autoStart && !this.startedOnce) {
|
|
1138
1197
|
this.startedOnce = true;
|
|
1139
1198
|
await spin("starting kvbox-server\u2026", startLocalServer(paths(), 5e3));
|
|
1140
|
-
return this.call(method, path, schema, body);
|
|
1199
|
+
return this.call(method, path, schema, body, org, timeoutMs);
|
|
1141
1200
|
}
|
|
1142
1201
|
throw new KvboxError(`kvbox-server is not running (${String(code)}); start it with: kvbox server start`);
|
|
1143
1202
|
}
|
|
@@ -1224,6 +1283,21 @@ var ServerClient = class {
|
|
|
1224
1283
|
removeLink(name, req) {
|
|
1225
1284
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
|
|
1226
1285
|
}
|
|
1286
|
+
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
1287
|
+
boxBackups(name) {
|
|
1288
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z3.array(BackupSchema));
|
|
1289
|
+
}
|
|
1290
|
+
boxBackup(name, id) {
|
|
1291
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
1292
|
+
}
|
|
1293
|
+
/** Starts one; it runs in the background (`running`), `boxBackup` says how it ended. */
|
|
1294
|
+
createBoxBackup(name) {
|
|
1295
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/backups`, BackupSchema);
|
|
1296
|
+
}
|
|
1297
|
+
/** The box's disk becomes the backup's; a running box restarts. Waits for the whole download. */
|
|
1298
|
+
restoreBoxBackup(name, id) {
|
|
1299
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}/restore`, MachineSchema, {}, void 0, 2 * 36e5);
|
|
1300
|
+
}
|
|
1227
1301
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
1228
1302
|
boxHooks(name) {
|
|
1229
1303
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z3.array(WakeHookSchema));
|
|
@@ -1802,6 +1876,10 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1802
1876
|
info(` from another box once linked: kvbox vm link <box> ${displayName(box, user)} --port <port>`);
|
|
1803
1877
|
info(` its variables: kvbox env ls --box ${displayName(box, user)}`);
|
|
1804
1878
|
}
|
|
1879
|
+
if (box.image === "gh-runner") {
|
|
1880
|
+
info(` wake it on queued jobs: kvbox vm hook create ${displayName(box, user)}`);
|
|
1881
|
+
info(` then add it on GitHub: Settings \u2192 Webhooks \u2192 Add webhook (the hook's URL and secret, content type application/json, event Workflow jobs)`);
|
|
1882
|
+
}
|
|
1805
1883
|
} finally {
|
|
1806
1884
|
await client.close();
|
|
1807
1885
|
}
|
|
@@ -2571,9 +2649,136 @@ var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake
|
|
|
2571
2649
|
var hookCommand = new Command21("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
|
|
2572
2650
|
for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2573
2651
|
|
|
2652
|
+
// src/commands/vm/backup/index.ts
|
|
2653
|
+
import { Command as Command25 } from "commander";
|
|
2654
|
+
|
|
2655
|
+
// src/commands/vm/backup/create.ts
|
|
2656
|
+
import { Command as Command22 } from "commander";
|
|
2657
|
+
|
|
2658
|
+
// src/commands/vm/backup/shared.ts
|
|
2659
|
+
import { setTimeout as sleep2 } from "timers/promises";
|
|
2660
|
+
function requireCloud3(client) {
|
|
2661
|
+
if (client.target.kind !== "cloud") throw new KvboxError("backups need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
2662
|
+
}
|
|
2663
|
+
var POLL_MS = 2e3;
|
|
2664
|
+
var POLL_TRIES = 30;
|
|
2665
|
+
var WAIT_MS = 7 * 36e5;
|
|
2666
|
+
async function untilDone(client, box, id, opts = {}) {
|
|
2667
|
+
const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
|
|
2668
|
+
const until = Date.now() + waitMs;
|
|
2669
|
+
let failed = 0;
|
|
2670
|
+
for (; ; ) {
|
|
2671
|
+
try {
|
|
2672
|
+
const b = await client.boxBackup(box, id);
|
|
2673
|
+
if (b.status !== "running") return b;
|
|
2674
|
+
failed = 0;
|
|
2675
|
+
} catch (err) {
|
|
2676
|
+
failed += 1;
|
|
2677
|
+
if (failed >= tries) throw lostTrack(box, id, `could not ask how it is doing: ${err.message}`);
|
|
2678
|
+
}
|
|
2679
|
+
if (Date.now() >= until) throw lostTrack(box, id, "it is taking longer than a backup is given");
|
|
2680
|
+
await sleep2(pollMs);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
function lostTrack(box, id, why) {
|
|
2684
|
+
return new KvboxError(`stopped waiting for backup ${id} of box ${box} (${why}); it may still be running: kvbox vm backup ls ${box}`);
|
|
2685
|
+
}
|
|
2686
|
+
function sizeLine(b) {
|
|
2687
|
+
const data = b.dataBytes === null ? "?" : gb(b.dataBytes);
|
|
2688
|
+
const added = b.uploadedBytes === null ? "" : `, ${gb(b.uploadedBytes)} uploaded`;
|
|
2689
|
+
return `${data} of data${added}`;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
// src/commands/vm/backup/create.ts
|
|
2693
|
+
var createCommand2 = new Command22("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--no-wait", "start it and return; kvbox vm backup ls <box> shows when it is ready").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
2694
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2695
|
+
try {
|
|
2696
|
+
requireCloud3(client);
|
|
2697
|
+
const found = await findBox(client, name);
|
|
2698
|
+
const box = displayName(found, me(client));
|
|
2699
|
+
const started = await client.createBoxBackup(box);
|
|
2700
|
+
if (!opts.wait) {
|
|
2701
|
+
if (opts.json) json(started);
|
|
2702
|
+
else info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box)} started; kvbox vm backup ls ${box} shows when it is ready`);
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
const done = await spin(`backing up ${box}\u2026`, untilDone(client, box, started.id));
|
|
2706
|
+
if (opts.json) json(done);
|
|
2707
|
+
if (done.status === "failed") throw new KvboxError(`backup ${done.id} of box ${box} failed: ${done.error ?? "no reason given"}`);
|
|
2708
|
+
if (opts.json) return;
|
|
2709
|
+
info(`${color.green("\u2713")} backup ${done.id} of box ${color.bold(box)}: ${sizeLine(done)}`);
|
|
2710
|
+
if ((found.volumes?.length ?? 0) > 0) info(color.dim(` not included: volume${found.volumes.length > 1 ? "s" : ""} ${found.volumes.map((v) => v.name).join(", ")}`));
|
|
2711
|
+
info(color.dim(` restore with: kvbox vm backup restore ${box} ${done.id}`));
|
|
2712
|
+
} finally {
|
|
2713
|
+
await client.close();
|
|
2714
|
+
}
|
|
2715
|
+
});
|
|
2716
|
+
|
|
2717
|
+
// src/commands/vm/backup/ls.ts
|
|
2718
|
+
import { Command as Command23 } from "commander";
|
|
2719
|
+
var lsCommand4 = new Command23("ls").alias("list").description("list a box's backups").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2720
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2721
|
+
try {
|
|
2722
|
+
requireCloud3(client);
|
|
2723
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2724
|
+
const list = await client.boxBackups(box);
|
|
2725
|
+
if (opts.json) {
|
|
2726
|
+
json(list);
|
|
2727
|
+
return;
|
|
2728
|
+
}
|
|
2729
|
+
if (list.length === 0) {
|
|
2730
|
+
info(`box ${box} has no backups; make one with: kvbox vm backup create ${box}`);
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
table(
|
|
2734
|
+
list.map((b) => ({
|
|
2735
|
+
id: b.id,
|
|
2736
|
+
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
2737
|
+
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
2738
|
+
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
2739
|
+
disk: b.diskBytes === null ? "-" : gbShort(b.diskBytes),
|
|
2740
|
+
by: b.createdBy ?? "-",
|
|
2741
|
+
taken: age(b.createdAt),
|
|
2742
|
+
...b.error !== null ? { error: b.error } : {}
|
|
2743
|
+
}))
|
|
2744
|
+
);
|
|
2745
|
+
} finally {
|
|
2746
|
+
await client.close();
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
|
|
2750
|
+
// src/commands/vm/backup/restore.ts
|
|
2751
|
+
import { Command as Command24 } from "commander";
|
|
2752
|
+
var restoreCommand = new Command24("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
|
|
2753
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2754
|
+
try {
|
|
2755
|
+
requireCloud3(client);
|
|
2756
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2757
|
+
const backup = await client.boxBackup(box, id);
|
|
2758
|
+
const question = `Restore box ${box} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)})? Everything written to its disk since is lost, and a running box restarts.`;
|
|
2759
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
2760
|
+
info("cancelled");
|
|
2761
|
+
process.exitCode = 1;
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
const machine = await spin(`restoring ${box} from ${backup.id}\u2026`, client.restoreBoxBackup(box, id));
|
|
2765
|
+
if (opts.json) {
|
|
2766
|
+
json(machine);
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
info(`${color.green("\u2713")} box ${color.bold(box)} restored from backup ${backup.id}; it is ${machine.status}`);
|
|
2770
|
+
} finally {
|
|
2771
|
+
await client.close();
|
|
2772
|
+
}
|
|
2773
|
+
});
|
|
2774
|
+
|
|
2775
|
+
// src/commands/vm/backup/index.ts
|
|
2776
|
+
var backupCommand = new Command25("backup").description("back up a box's disk to the kvbox cloud, list backups, restore one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand);
|
|
2777
|
+
for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2778
|
+
|
|
2574
2779
|
// src/commands/vm/rescale.ts
|
|
2575
|
-
import { Command as
|
|
2576
|
-
var rescaleCommand = new
|
|
2780
|
+
import { Command as Command26, Option as Option3 } from "commander";
|
|
2781
|
+
var rescaleCommand = new Command26("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2577
2782
|
const req = {
|
|
2578
2783
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
2579
2784
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -2619,8 +2824,8 @@ function parseGib(flag, text2) {
|
|
|
2619
2824
|
}
|
|
2620
2825
|
|
|
2621
2826
|
// src/commands/vm/resume.ts
|
|
2622
|
-
import { Command as
|
|
2623
|
-
var resumeCommand = new
|
|
2827
|
+
import { Command as Command27 } from "commander";
|
|
2828
|
+
var resumeCommand = new Command27("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2624
2829
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2625
2830
|
try {
|
|
2626
2831
|
const box = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
|
|
@@ -2632,8 +2837,8 @@ var resumeCommand = new Command23("resume").description("continue a box that is
|
|
|
2632
2837
|
});
|
|
2633
2838
|
|
|
2634
2839
|
// src/commands/vm/rm.ts
|
|
2635
|
-
import { Command as
|
|
2636
|
-
var rmCommand3 = new
|
|
2840
|
+
import { Command as Command28 } from "commander";
|
|
2841
|
+
var rmCommand3 = new Command28("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
2637
2842
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2638
2843
|
try {
|
|
2639
2844
|
const box = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2653,29 +2858,140 @@ var rmCommand3 = new Command24("rm").description("destroy a box (its disk is del
|
|
|
2653
2858
|
});
|
|
2654
2859
|
|
|
2655
2860
|
// src/commands/vm/set.ts
|
|
2656
|
-
import { Command as
|
|
2657
|
-
|
|
2658
|
-
|
|
2861
|
+
import { Command as Command29 } from "commander";
|
|
2862
|
+
|
|
2863
|
+
// src/swap.ts
|
|
2864
|
+
import { spawn as spawn3 } from "child_process";
|
|
2865
|
+
var SWAP_FILE = "/rom/overlay/swapfile";
|
|
2866
|
+
var SWAP_KEEP_FREE_MIB = 1024;
|
|
2867
|
+
var SWAP_MIN_MIB = 256;
|
|
2868
|
+
function parseSwap(text2) {
|
|
2869
|
+
const t = text2.trim().toLowerCase();
|
|
2870
|
+
if (t === "off" || t === "none" || t === "0") return 0;
|
|
2871
|
+
const mib = parseMib(t);
|
|
2872
|
+
if (mib === void 0 || mib < SWAP_MIN_MIB) throw new KvboxError(`--swap ${text2}: give a size of at least ${SWAP_MIN_MIB}M (2G, 512M), or off`);
|
|
2873
|
+
return mib;
|
|
2874
|
+
}
|
|
2875
|
+
function swapScript() {
|
|
2876
|
+
return [
|
|
2877
|
+
"set -eu",
|
|
2878
|
+
'mib="$1"',
|
|
2879
|
+
"disk=/rom/overlay",
|
|
2880
|
+
`f=${SWAP_FILE}`,
|
|
2881
|
+
"zs=/sys/module/zswap/parameters/enabled",
|
|
2882
|
+
'mountpoint -q "$disk" || { echo "this box has no separate box disk at $disk (an image older than the overlay one)" >&2; exit 3; }',
|
|
2883
|
+
'active() { grep -q "^$f " /proc/swaps; }',
|
|
2884
|
+
'have=0; [ -f "$f" ] && have=$(( $(stat -c %s "$f") / 1048576 ))',
|
|
2885
|
+
'if [ "$mib" -gt 0 ] && ! { [ "$have" -eq "$mib" ] && active; }; then',
|
|
2886
|
+
' free=$(( $(stat -f -c %a "$disk") * $(stat -f -c %S "$disk") / 1048576 + have ))',
|
|
2887
|
+
` if [ $(( free - mib )) -lt ${SWAP_KEEP_FREE_MIB} ]; then echo "the box disk has $free MiB free; $mib MiB of swap would leave less than ${SWAP_KEEP_FREE_MIB} MiB" >&2; exit 5; fi`,
|
|
2888
|
+
"fi",
|
|
2889
|
+
'if [ "$mib" -eq 0 ] || ! { [ "$have" -eq "$mib" ] && active; }; then',
|
|
2890
|
+
' if active; then swapoff "$f" || { echo "swapoff failed: what is in swap does not fit back in RAM; stop something first" >&2; exit 4; }; fi',
|
|
2891
|
+
' rm -f "$f"',
|
|
2892
|
+
' if [ "$mib" -gt 0 ]; then',
|
|
2893
|
+
' fallocate -l "${mib}M" "$f"',
|
|
2894
|
+
' chmod 600 "$f"',
|
|
2895
|
+
' mkswap "$f" >/dev/null',
|
|
2896
|
+
' swapon "$f"',
|
|
2897
|
+
" fi",
|
|
2898
|
+
"fi",
|
|
2899
|
+
"touch /etc/fstab",
|
|
2900
|
+
'sed -i "\\#^$f #d" /etc/fstab',
|
|
2901
|
+
'if [ "$mib" -gt 0 ]; then',
|
|
2902
|
+
' echo "$f none swap sw 0 0" >> /etc/fstab',
|
|
2903
|
+
" printf 'vm.swappiness = 10\\n' > /etc/sysctl.d/90-kvbox-swap.conf",
|
|
2904
|
+
" sysctl -q vm.swappiness=10",
|
|
2905
|
+
" printf 'w /sys/module/zswap/parameters/enabled - - - - 1\\n' > /etc/tmpfiles.d/kvbox-swap.conf",
|
|
2906
|
+
' echo 1 > "$zs" 2>/dev/null || true',
|
|
2907
|
+
"else",
|
|
2908
|
+
" rm -f /etc/sysctl.d/90-kvbox-swap.conf /etc/tmpfiles.d/kvbox-swap.conf",
|
|
2909
|
+
" sysctl -q vm.swappiness=60",
|
|
2910
|
+
' echo 0 > "$zs" 2>/dev/null || true',
|
|
2911
|
+
"fi",
|
|
2912
|
+
'line=$(grep "^$f " /proc/swaps || true)',
|
|
2913
|
+
"set -- $line",
|
|
2914
|
+
'echo "kvbox-swap ${3:-0} ${4:-0} $(cat "$zs" 2>/dev/null || echo N)"'
|
|
2915
|
+
].join("\n");
|
|
2916
|
+
}
|
|
2917
|
+
function swapCommand(mib) {
|
|
2918
|
+
return `sudo -n sh -c ${shellQuote(swapScript())} kvbox-swap ${mib}`;
|
|
2919
|
+
}
|
|
2920
|
+
function parseSwapReport(output) {
|
|
2921
|
+
const m = /^kvbox-swap (\d+) (\d+) (\S+)\s*$/m.exec(output);
|
|
2922
|
+
if (!m) return void 0;
|
|
2923
|
+
return { sizeMib: Math.round(Number(m[1]) / 1024), usedMib: Math.round(Number(m[2]) / 1024), zswap: m[3] === "Y" || m[3] === "1" };
|
|
2924
|
+
}
|
|
2925
|
+
function runSwap(ep, mib) {
|
|
2926
|
+
const child = spawn3("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
|
|
2927
|
+
const chunks = [];
|
|
2928
|
+
child.stdout.on("data", (c) => chunks.push(c));
|
|
2929
|
+
child.stderr.on("data", (c) => chunks.push(c));
|
|
2930
|
+
return new Promise((resolve3, reject) => {
|
|
2931
|
+
child.once("error", (err) => reject(new KvboxError(`could not run ssh: ${err.message}`)));
|
|
2932
|
+
child.once("close", (code) => resolve3({ status: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
// src/commands/vm/set.ts
|
|
2937
|
+
var setCommand = new Command29("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2938
|
+
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
|
|
2939
|
+
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
|
|
2940
|
+
}
|
|
2659
2941
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
2660
2942
|
const idleCheck = opts.idleCheck === void 0 ? void 0 : parseIdleCheck(opts.idleCheck);
|
|
2943
|
+
const swapMib = opts.swap === void 0 ? void 0 : parseSwap(opts.swap);
|
|
2944
|
+
const hostSettings = autoHibernateSec !== void 0 || idleCheck !== void 0;
|
|
2661
2945
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2662
2946
|
try {
|
|
2663
2947
|
const found = pickRef(await boxesFor(client, name), name, me(client));
|
|
2664
2948
|
if (!found) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2949
|
+
if (swapMib !== void 0 && found.status === "stopped") throw new KvboxError(`box ${name} is stopped; --swap is set up inside the box (kvbox start ${name})`);
|
|
2950
|
+
let box = found;
|
|
2951
|
+
if (hostSettings) {
|
|
2952
|
+
box = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { ...autoHibernateSec !== void 0 ? { autoHibernateSec } : {}, ...idleCheck !== void 0 ? { idleCheck } : {} }));
|
|
2953
|
+
if (!idleCheckKept(idleCheck, box)) {
|
|
2954
|
+
throw new KvboxError(`box ${name}: its host runs a kvbox-server too old for --idle-check; it needs updating first${autoHibernateSec !== void 0 ? " (--auto-hibernate was applied)" : ""}`);
|
|
2955
|
+
}
|
|
2668
2956
|
}
|
|
2957
|
+
const swap = swapMib === void 0 ? void 0 : await setSwap(client, box, name, swapMib, cmd);
|
|
2669
2958
|
if (opts.json) {
|
|
2670
|
-
json(box);
|
|
2959
|
+
json(swap === void 0 ? box : { ...box, swap });
|
|
2671
2960
|
return;
|
|
2672
2961
|
}
|
|
2673
|
-
info(`${color.green("\u2713")} box ${color.bold(name)}: ${autoHibernateText(box.autoHibernateSec, box.idleCheck)}`);
|
|
2962
|
+
if (hostSettings) info(`${color.green("\u2713")} box ${color.bold(name)}: ${autoHibernateText(box.autoHibernateSec, box.idleCheck)}`);
|
|
2674
2963
|
if (idleCheck && !box.autoHibernateSec) info(color.dim(` the idle check is used once auto-hibernate is on: kvbox vm set ${name} --auto-hibernate 10m`));
|
|
2964
|
+
if (swap) info(`${color.green("\u2713")} box ${color.bold(name)}: ${swapText(swap)}`);
|
|
2675
2965
|
} finally {
|
|
2676
2966
|
await client.close();
|
|
2677
2967
|
}
|
|
2678
2968
|
});
|
|
2969
|
+
async function setSwap(client, found, name, mib, cmd) {
|
|
2970
|
+
const cert = await ensureCert(client, void 0, void 0, { owner: found.owner });
|
|
2971
|
+
const wasRunning = found.status === "running";
|
|
2972
|
+
const box = wasRunning ? found : await wakeUp(client, found, displayName(found, me(client)));
|
|
2973
|
+
const ep = sshEndpoint(box, client.target);
|
|
2974
|
+
if (!wasRunning) await spin(`waiting for ${name} to accept SSH\u2026`, waitForSsh(ep));
|
|
2975
|
+
const what = mib === 0 ? `removing ${name}'s swap\u2026` : `setting up ${mib >= 1024 ? `${mib / 1024}G` : `${mib}M`} of swap in ${name}\u2026`;
|
|
2976
|
+
let result = await spin(what, runSwap(ep, mib));
|
|
2977
|
+
if (result.status === 255) {
|
|
2978
|
+
const again = await clientFor(cmd.optsWithGlobals());
|
|
2979
|
+
if (await renewAfterRefusal(again, cert, found.owner).finally(() => again.close())) result = await spin(what, runSwap(ep, mib));
|
|
2980
|
+
}
|
|
2981
|
+
const report = parseSwapReport(result.output);
|
|
2982
|
+
if (result.status !== 0 || !report) {
|
|
2983
|
+
const said = result.output.split("\n").filter((l) => l.trim() !== "" && !l.startsWith("kvbox-swap ")).join("\n ");
|
|
2984
|
+
if (result.status === 255) throw new KvboxError(`box ${name}: could not reach it over SSH${said ? `
|
|
2985
|
+
${said}` : ""}`, 255);
|
|
2986
|
+
throw new KvboxError(`box ${name}: --swap failed${said ? `: ${said}` : ""}`);
|
|
2987
|
+
}
|
|
2988
|
+
return report;
|
|
2989
|
+
}
|
|
2990
|
+
function swapText(s) {
|
|
2991
|
+
if (s.sizeMib === 0) return "no swap";
|
|
2992
|
+
const size = s.sizeMib % 1024 === 0 ? `${s.sizeMib / 1024} GB` : `${s.sizeMib} MB`;
|
|
2993
|
+
return `${size} swap (${s.usedMib} MB used, zswap ${s.zswap ? "on" : "off"})`;
|
|
2994
|
+
}
|
|
2679
2995
|
function idleCheckKept(asked, box) {
|
|
2680
2996
|
return asked === void 0 || (box.idleCheck ?? "") === asked;
|
|
2681
2997
|
}
|
|
@@ -2687,8 +3003,8 @@ function parseIdleCheck(text2) {
|
|
|
2687
3003
|
}
|
|
2688
3004
|
|
|
2689
3005
|
// src/commands/vm/start.ts
|
|
2690
|
-
import { Command as
|
|
2691
|
-
var startCommand = new
|
|
3006
|
+
import { Command as Command30 } from "commander";
|
|
3007
|
+
var startCommand = new Command30("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2692
3008
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2693
3009
|
try {
|
|
2694
3010
|
const box = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
|
|
@@ -2700,8 +3016,8 @@ var startCommand = new Command26("start").description("boot a stopped box again
|
|
|
2700
3016
|
});
|
|
2701
3017
|
|
|
2702
3018
|
// src/commands/vm/stop.ts
|
|
2703
|
-
import { Command as
|
|
2704
|
-
var stopCommand = new
|
|
3019
|
+
import { Command as Command31 } from "commander";
|
|
3020
|
+
var stopCommand = new Command31("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2705
3021
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2706
3022
|
try {
|
|
2707
3023
|
const box = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
|
|
@@ -2713,8 +3029,8 @@ var stopCommand = new Command27("stop").description("shut a box down (its disk i
|
|
|
2713
3029
|
});
|
|
2714
3030
|
|
|
2715
3031
|
// src/commands/vm/top.ts
|
|
2716
|
-
import { Command as
|
|
2717
|
-
var topCommand = new
|
|
3032
|
+
import { Command as Command32 } from "commander";
|
|
3033
|
+
var topCommand = new Command32("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2718
3034
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2719
3035
|
try {
|
|
2720
3036
|
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
@@ -2774,8 +3090,8 @@ function topRows(entries, cloud) {
|
|
|
2774
3090
|
}
|
|
2775
3091
|
|
|
2776
3092
|
// src/commands/vm/unlink.ts
|
|
2777
|
-
import { Command as
|
|
2778
|
-
var unlinkCommand = new
|
|
3093
|
+
import { Command as Command33 } from "commander";
|
|
3094
|
+
var unlinkCommand = new Command33("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
|
|
2779
3095
|
const port = parseLinkPort(opts.port);
|
|
2780
3096
|
if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
|
|
2781
3097
|
info("cancelled");
|
|
@@ -2796,8 +3112,8 @@ var unlinkCommand = new Command29("unlink").description("take a link away (kvbox
|
|
|
2796
3112
|
});
|
|
2797
3113
|
|
|
2798
3114
|
// src/commands/vm/update.ts
|
|
2799
|
-
import { Command as
|
|
2800
|
-
var updateCommand = new
|
|
3115
|
+
import { Command as Command34 } from "commander";
|
|
3116
|
+
var updateCommand = new Command34("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2801
3117
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2802
3118
|
try {
|
|
2803
3119
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2819,8 +3135,8 @@ var updateCommand = new Command30("update").description("move a box onto the cur
|
|
|
2819
3135
|
});
|
|
2820
3136
|
|
|
2821
3137
|
// src/commands/vm/usage.ts
|
|
2822
|
-
import { Command as
|
|
2823
|
-
var usageCommand = new
|
|
3138
|
+
import { Command as Command35 } from "commander";
|
|
3139
|
+
var usageCommand = new Command35("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2824
3140
|
let since;
|
|
2825
3141
|
if (opts.since !== void 0) {
|
|
2826
3142
|
const t = Date.parse(opts.since);
|
|
@@ -2867,8 +3183,8 @@ function block(u) {
|
|
|
2867
3183
|
}
|
|
2868
3184
|
|
|
2869
3185
|
// src/commands/vm/wake.ts
|
|
2870
|
-
import { Command as
|
|
2871
|
-
var wakeCommand = new
|
|
3186
|
+
import { Command as Command36 } from "commander";
|
|
3187
|
+
var wakeCommand = new Command36("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2872
3188
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2873
3189
|
try {
|
|
2874
3190
|
const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
|
|
@@ -2880,20 +3196,20 @@ var wakeCommand = new Command32("wake").description("continue a hibernated box w
|
|
|
2880
3196
|
});
|
|
2881
3197
|
|
|
2882
3198
|
// src/commands/vm/index.ts
|
|
2883
|
-
var vmCommand = new
|
|
2884
|
-
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
3199
|
+
var vmCommand = new Command37("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand3);
|
|
3200
|
+
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand && cmd !== backupCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2885
3201
|
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
|
|
2886
3202
|
|
|
2887
3203
|
// src/commands/server/index.ts
|
|
2888
|
-
import { Command as
|
|
3204
|
+
import { Command as Command45 } from "commander";
|
|
2889
3205
|
|
|
2890
3206
|
// src/commands/server/join.ts
|
|
2891
|
-
import { Command as
|
|
3207
|
+
import { Command as Command38 } from "commander";
|
|
2892
3208
|
|
|
2893
3209
|
// src/commands/server/daemon.ts
|
|
2894
|
-
import { spawn as
|
|
3210
|
+
import { spawn as spawn4 } from "child_process";
|
|
2895
3211
|
import { readFile as readFile4 } from "fs/promises";
|
|
2896
|
-
import { setTimeout as
|
|
3212
|
+
import { setTimeout as sleep3 } from "timers/promises";
|
|
2897
3213
|
async function runningPid(p = paths()) {
|
|
2898
3214
|
let pid;
|
|
2899
3215
|
try {
|
|
@@ -2916,7 +3232,7 @@ async function stopLocalServer(pid, timeoutMs = 1e4) {
|
|
|
2916
3232
|
const deadline = Date.now() + timeoutMs;
|
|
2917
3233
|
while (alive(pid)) {
|
|
2918
3234
|
if (Date.now() > deadline) throw new KvboxError(`kvbox-server (pid ${pid}) did not stop within ${timeoutMs / 1e3}s`);
|
|
2919
|
-
await
|
|
3235
|
+
await sleep3(100);
|
|
2920
3236
|
}
|
|
2921
3237
|
}
|
|
2922
3238
|
async function restartLocalServer(p = paths()) {
|
|
@@ -2926,7 +3242,7 @@ async function restartLocalServer(p = paths()) {
|
|
|
2926
3242
|
}
|
|
2927
3243
|
function runKvboxServer(args) {
|
|
2928
3244
|
return new Promise((resolve3, reject) => {
|
|
2929
|
-
const child =
|
|
3245
|
+
const child = spawn4("kvbox-server", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
2930
3246
|
let out = "";
|
|
2931
3247
|
let err = "";
|
|
2932
3248
|
child.stdout.on("data", (chunk) => out += chunk.toString());
|
|
@@ -2942,7 +3258,7 @@ function runKvboxServer(args) {
|
|
|
2942
3258
|
}
|
|
2943
3259
|
|
|
2944
3260
|
// src/commands/server/join.ts
|
|
2945
|
-
var joinCommand = new
|
|
3261
|
+
var joinCommand = new Command38("join").description("put this machine behind a control plane (needs a one-time token minted there) and restart its server").argument("<control-plane-url>", "the control plane, e.g. https://api.kvbox.sh").requiredOption("--token <token>", "one-time join token from the control plane").option("--advertise <host-or-ip>", "address the control plane reaches this machine at (default: its default-route address)").option("--name <name>", "how the control plane lists this machine (default: hostname)").action(async (url, opts) => {
|
|
2946
3262
|
const args = ["join", url, "--token", opts.token];
|
|
2947
3263
|
if (opts.advertise !== void 0) args.push("--advertise", opts.advertise);
|
|
2948
3264
|
if (opts.name !== void 0) args.push("--name", opts.name);
|
|
@@ -2952,8 +3268,8 @@ var joinCommand = new Command34("join").description("put this machine behind a c
|
|
|
2952
3268
|
});
|
|
2953
3269
|
|
|
2954
3270
|
// src/commands/server/leave.ts
|
|
2955
|
-
import { Command as
|
|
2956
|
-
var leaveCommand = new
|
|
3271
|
+
import { Command as Command39 } from "commander";
|
|
3272
|
+
var leaveCommand = new Command39("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
|
|
2957
3273
|
const p = paths();
|
|
2958
3274
|
for (const line of (await runKvboxServer(["leave"])).split("\n")) info(line);
|
|
2959
3275
|
if (await runningPid(p) === null) return;
|
|
@@ -2962,14 +3278,14 @@ var leaveCommand = new Command35("leave").description("take this machine out fro
|
|
|
2962
3278
|
});
|
|
2963
3279
|
|
|
2964
3280
|
// src/commands/server/relay.ts
|
|
2965
|
-
import { Command as
|
|
2966
|
-
var relayCommand = new
|
|
3281
|
+
import { Command as Command40 } from "commander";
|
|
3282
|
+
var relayCommand = new Command40("relay").description("reach the internet through a relay (paste what `kvbox-relay add` printed on the relay VM); `off` takes the tunnel down").argument("<join-string>", "the line `kvbox-relay add` printed, or `off`").action(async (joinString) => {
|
|
2967
3283
|
for (const line of (await runKvboxServer(["relay", joinString])).split("\n")) info(line);
|
|
2968
3284
|
});
|
|
2969
3285
|
|
|
2970
3286
|
// src/commands/server/start.ts
|
|
2971
|
-
import { Command as
|
|
2972
|
-
var startCommand2 = new
|
|
3287
|
+
import { Command as Command41 } from "commander";
|
|
3288
|
+
var startCommand2 = new Command41("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
|
|
2973
3289
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true }, { autoStart: false });
|
|
2974
3290
|
try {
|
|
2975
3291
|
const health = await client.health();
|
|
@@ -2985,8 +3301,8 @@ var startCommand2 = new Command37("start").description("start the local kvbox-se
|
|
|
2985
3301
|
});
|
|
2986
3302
|
|
|
2987
3303
|
// src/commands/server/status.ts
|
|
2988
|
-
import { Command as
|
|
2989
|
-
var statusCommand = new
|
|
3304
|
+
import { Command as Command42 } from "commander";
|
|
3305
|
+
var statusCommand = new Command42("status").description("show whether this machine's server is running, its control plane and which base image new boxes get").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2990
3306
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
2991
3307
|
try {
|
|
2992
3308
|
const health = await client.health();
|
|
@@ -3018,8 +3334,8 @@ var statusCommand = new Command38("status").description("show whether this machi
|
|
|
3018
3334
|
});
|
|
3019
3335
|
|
|
3020
3336
|
// src/commands/server/stop.ts
|
|
3021
|
-
import { Command as
|
|
3022
|
-
var stopCommand2 = new
|
|
3337
|
+
import { Command as Command43 } from "commander";
|
|
3338
|
+
var stopCommand2 = new Command43("stop").description("stop the local server (running boxes are not affected)").action(async () => {
|
|
3023
3339
|
const pid = await runningPid(paths());
|
|
3024
3340
|
if (pid === null) throw new KvboxError("kvbox-server is not running");
|
|
3025
3341
|
await stopLocalServer(pid);
|
|
@@ -3027,8 +3343,8 @@ var stopCommand2 = new Command39("stop").description("stop the local server (run
|
|
|
3027
3343
|
});
|
|
3028
3344
|
|
|
3029
3345
|
// src/commands/server/trust-ca.ts
|
|
3030
|
-
import { Command as
|
|
3031
|
-
var trustCaCommand = new
|
|
3346
|
+
import { Command as Command44 } from "commander";
|
|
3347
|
+
var trustCaCommand = new Command44("trust-ca").description("make every cloud box on this machine trust a new SSH CA (after `ca rotate` on the control plane)").argument("[public-key]", "the CA public key (or its cert-authority line); or --from-cloud").option("--from-cloud", "ask the control plane this host joined for its current CA, show the fingerprint, then ask").option("-y, --yes", "do not ask for confirmation").option("--json", "print the report as JSON").action(async (publicKey, opts, cmd) => {
|
|
3032
3348
|
if (publicKey === void 0 && !opts.fromCloud) throw new KvboxError("give the CA public key, or --from-cloud to fetch it from the control plane this host joined");
|
|
3033
3349
|
if (publicKey !== void 0 && opts.fromCloud) throw new KvboxError("either a public key or --from-cloud, not both");
|
|
3034
3350
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
@@ -3066,7 +3382,7 @@ function describeReport(report) {
|
|
|
3066
3382
|
}
|
|
3067
3383
|
|
|
3068
3384
|
// src/commands/server/index.ts
|
|
3069
|
-
var serverCommand = new
|
|
3385
|
+
var serverCommand = new Command45("server").description("run or manage the kvbox server").addCommand(startCommand2).addCommand(statusCommand).addCommand(stopCommand2).addCommand(joinCommand).addCommand(leaveCommand).addCommand(relayCommand).addCommand(trustCaCommand);
|
|
3070
3386
|
|
|
3071
3387
|
// src/commands/login.ts
|
|
3072
3388
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
@@ -3074,8 +3390,8 @@ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from
|
|
|
3074
3390
|
import { hostname as osHostname } from "os";
|
|
3075
3391
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
3076
3392
|
import { Writable } from "stream";
|
|
3077
|
-
import { Command as
|
|
3078
|
-
var loginCommand = new
|
|
3393
|
+
import { Command as Command46 } from "commander";
|
|
3394
|
+
var loginCommand = new Command46("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
|
|
3079
3395
|
const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
|
|
3080
3396
|
const creds = await readCredentials(opts);
|
|
3081
3397
|
const session = await runLogin(url, creds, paths());
|
|
@@ -3155,8 +3471,8 @@ async function firstLine(stream) {
|
|
|
3155
3471
|
}
|
|
3156
3472
|
|
|
3157
3473
|
// src/commands/logout.ts
|
|
3158
|
-
import { Command as
|
|
3159
|
-
var logoutCommand = new
|
|
3474
|
+
import { Command as Command47 } from "commander";
|
|
3475
|
+
var logoutCommand = new Command47("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
|
|
3160
3476
|
const p = paths();
|
|
3161
3477
|
const session = await readSession(p).catch(() => null);
|
|
3162
3478
|
switch (await runLogout(p)) {
|
|
@@ -3193,8 +3509,8 @@ async function runLogout(p = paths()) {
|
|
|
3193
3509
|
}
|
|
3194
3510
|
|
|
3195
3511
|
// src/commands/whoami.ts
|
|
3196
|
-
import { Command as
|
|
3197
|
-
var whoamiCommand = new
|
|
3512
|
+
import { Command as Command48 } from "commander";
|
|
3513
|
+
var whoamiCommand = new Command48("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
|
|
3198
3514
|
const session = await readSession();
|
|
3199
3515
|
if (opts.json) {
|
|
3200
3516
|
json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
|
|
@@ -3210,11 +3526,11 @@ function describeSession(session) {
|
|
|
3210
3526
|
}
|
|
3211
3527
|
|
|
3212
3528
|
// src/commands/snapshots/index.ts
|
|
3213
|
-
import { Command as
|
|
3529
|
+
import { Command as Command52 } from "commander";
|
|
3214
3530
|
|
|
3215
3531
|
// src/commands/snapshots/ls.ts
|
|
3216
|
-
import { Command as
|
|
3217
|
-
var
|
|
3532
|
+
import { Command as Command49 } from "commander";
|
|
3533
|
+
var lsCommand5 = new Command49("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3218
3534
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3219
3535
|
try {
|
|
3220
3536
|
const cloud = client.target.kind === "cloud";
|
|
@@ -3245,8 +3561,8 @@ var lsCommand4 = new Command45("ls").description("list snapshots (yours and your
|
|
|
3245
3561
|
});
|
|
3246
3562
|
|
|
3247
3563
|
// src/commands/snapshots/new.ts
|
|
3248
|
-
import { Command as
|
|
3249
|
-
var newCommand2 = new
|
|
3564
|
+
import { Command as Command50 } from "commander";
|
|
3565
|
+
var newCommand2 = new Command50("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
|
|
3250
3566
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3251
3567
|
try {
|
|
3252
3568
|
const req = { box, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -3259,8 +3575,8 @@ var newCommand2 = new Command46("new").description("freeze a running box (memory
|
|
|
3259
3575
|
});
|
|
3260
3576
|
|
|
3261
3577
|
// src/commands/snapshots/rm.ts
|
|
3262
|
-
import { Command as
|
|
3263
|
-
var rmCommand4 = new
|
|
3578
|
+
import { Command as Command51 } from "commander";
|
|
3579
|
+
var rmCommand4 = new Command51("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
3264
3580
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
3265
3581
|
info("cancelled");
|
|
3266
3582
|
process.exitCode = 1;
|
|
@@ -3276,14 +3592,14 @@ var rmCommand4 = new Command47("rm").description("delete a snapshot (boxes made
|
|
|
3276
3592
|
});
|
|
3277
3593
|
|
|
3278
3594
|
// src/commands/snapshots/index.ts
|
|
3279
|
-
var snapshotsCommand = new
|
|
3595
|
+
var snapshotsCommand = new Command52("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand5).addCommand(rmCommand4);
|
|
3280
3596
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
3281
3597
|
|
|
3282
3598
|
// src/commands/org/index.ts
|
|
3283
|
-
import { Command as
|
|
3599
|
+
import { Command as Command58 } from "commander";
|
|
3284
3600
|
|
|
3285
3601
|
// src/commands/org/ls.ts
|
|
3286
|
-
import { Command as
|
|
3602
|
+
import { Command as Command53 } from "commander";
|
|
3287
3603
|
|
|
3288
3604
|
// src/commands/org/context.ts
|
|
3289
3605
|
var NOT_LOGGED_IN = "orgs live on the control plane: kvbox login first";
|
|
@@ -3303,7 +3619,7 @@ function orgFor(opts, target) {
|
|
|
3303
3619
|
}
|
|
3304
3620
|
|
|
3305
3621
|
// src/commands/org/ls.ts
|
|
3306
|
-
var
|
|
3622
|
+
var lsCommand6 = new Command53("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3307
3623
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3308
3624
|
try {
|
|
3309
3625
|
const orgs = await client.listOrgs();
|
|
@@ -3325,8 +3641,8 @@ function orgRows(orgs) {
|
|
|
3325
3641
|
}
|
|
3326
3642
|
|
|
3327
3643
|
// src/commands/org/members.ts
|
|
3328
|
-
import { Command as
|
|
3329
|
-
var
|
|
3644
|
+
import { Command as Command54, Option as Option4 } from "commander";
|
|
3645
|
+
var lsCommand7 = new Command54("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3330
3646
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3331
3647
|
try {
|
|
3332
3648
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -3340,7 +3656,7 @@ var lsCommand6 = new Command50("ls").description("list an org's members and thei
|
|
|
3340
3656
|
await client.close();
|
|
3341
3657
|
}
|
|
3342
3658
|
});
|
|
3343
|
-
var addCommand2 = new
|
|
3659
|
+
var addCommand2 = new Command54("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
|
|
3344
3660
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3345
3661
|
try {
|
|
3346
3662
|
const slug = orgFor(opts, client.target);
|
|
@@ -3350,7 +3666,7 @@ var addCommand2 = new Command50("add").description("add a user to an org (admins
|
|
|
3350
3666
|
await client.close();
|
|
3351
3667
|
}
|
|
3352
3668
|
});
|
|
3353
|
-
var rmCommand5 = new
|
|
3669
|
+
var rmCommand5 = new Command54("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
|
|
3354
3670
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3355
3671
|
try {
|
|
3356
3672
|
const slug = orgFor(opts, client.target);
|
|
@@ -3366,11 +3682,11 @@ var rmCommand5 = new Command50("rm").description("remove a member (or leave: rem
|
|
|
3366
3682
|
await client.close();
|
|
3367
3683
|
}
|
|
3368
3684
|
});
|
|
3369
|
-
var membersCommand = new
|
|
3685
|
+
var membersCommand = new Command54("members").description("who is in an org and what they may do").addCommand(lsCommand7).addCommand(addCommand2).addCommand(rmCommand5);
|
|
3370
3686
|
|
|
3371
3687
|
// src/commands/org/new.ts
|
|
3372
|
-
import { Command as
|
|
3373
|
-
var newCommand3 = new
|
|
3688
|
+
import { Command as Command55 } from "commander";
|
|
3689
|
+
var newCommand3 = new Command55("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
|
|
3374
3690
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3375
3691
|
try {
|
|
3376
3692
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -3386,8 +3702,8 @@ var newCommand3 = new Command51("new").description("create an org; you become it
|
|
|
3386
3702
|
});
|
|
3387
3703
|
|
|
3388
3704
|
// src/commands/org/rm.ts
|
|
3389
|
-
import { Command as
|
|
3390
|
-
var rmCommand6 = new
|
|
3705
|
+
import { Command as Command56 } from "commander";
|
|
3706
|
+
var rmCommand6 = new Command56("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
|
|
3391
3707
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
3392
3708
|
info("cancelled");
|
|
3393
3709
|
process.exitCode = 1;
|
|
@@ -3403,8 +3719,8 @@ var rmCommand6 = new Command52("rm").description("delete an org (owners only; re
|
|
|
3403
3719
|
});
|
|
3404
3720
|
|
|
3405
3721
|
// src/commands/org/role.ts
|
|
3406
|
-
import { Argument, Command as
|
|
3407
|
-
var roleCommand = new
|
|
3722
|
+
import { Argument, Command as Command57 } from "commander";
|
|
3723
|
+
var roleCommand = new Command57("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
|
|
3408
3724
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3409
3725
|
try {
|
|
3410
3726
|
const slug = orgFor(opts, client.target);
|
|
@@ -3416,10 +3732,10 @@ var roleCommand = new Command53("role").description("change a member's role (own
|
|
|
3416
3732
|
});
|
|
3417
3733
|
|
|
3418
3734
|
// src/commands/org/index.ts
|
|
3419
|
-
var orgCommand = new
|
|
3735
|
+
var orgCommand = new Command58("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand6).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand6);
|
|
3420
3736
|
|
|
3421
3737
|
// src/commands/usage.ts
|
|
3422
|
-
import { Command as
|
|
3738
|
+
import { Command as Command59 } from "commander";
|
|
3423
3739
|
|
|
3424
3740
|
// ../shared/src/usage.ts
|
|
3425
3741
|
import { z as z4 } from "zod";
|
|
@@ -3457,7 +3773,7 @@ function sumUsage(items, pricing) {
|
|
|
3457
3773
|
}
|
|
3458
3774
|
|
|
3459
3775
|
// src/commands/usage.ts
|
|
3460
|
-
var usageCommand2 = new
|
|
3776
|
+
var usageCommand2 = new Command59("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3461
3777
|
for (const [name, value] of [
|
|
3462
3778
|
["since", opts.since],
|
|
3463
3779
|
["until", opts.until]
|
|
@@ -3603,8 +3919,8 @@ function userRows(r) {
|
|
|
3603
3919
|
}
|
|
3604
3920
|
|
|
3605
3921
|
// src/commands/credit.ts
|
|
3606
|
-
import { Command as
|
|
3607
|
-
var creditCommand = new
|
|
3922
|
+
import { Command as Command60 } from "commander";
|
|
3923
|
+
var creditCommand = new Command60("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3608
3924
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
3609
3925
|
try {
|
|
3610
3926
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -3634,7 +3950,7 @@ function creditRow(b, me2) {
|
|
|
3634
3950
|
// src/commands/deploy/index.ts
|
|
3635
3951
|
import { readFile as readFile7 } from "fs/promises";
|
|
3636
3952
|
import { basename, resolve as resolve2 } from "path";
|
|
3637
|
-
import { Command as
|
|
3953
|
+
import { Command as Command61, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
3638
3954
|
|
|
3639
3955
|
// src/commands/deploy/config.ts
|
|
3640
3956
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -3780,7 +4096,7 @@ var nodeTemplate = {
|
|
|
3780
4096
|
};
|
|
3781
4097
|
|
|
3782
4098
|
// src/commands/deploy/templates/react.ts
|
|
3783
|
-
import { spawn as
|
|
4099
|
+
import { spawn as spawn5 } from "child_process";
|
|
3784
4100
|
import { access as access2 } from "fs/promises";
|
|
3785
4101
|
import { join as join3 } from "path";
|
|
3786
4102
|
var OUT_DIRS = ["dist", "build"];
|
|
@@ -3788,7 +4104,7 @@ async function runBuild(dir, pm) {
|
|
|
3788
4104
|
const args = runScript(pm, "build");
|
|
3789
4105
|
info(`${color.dim("$")} ${pm} ${args.join(" ")}`);
|
|
3790
4106
|
const status2 = await new Promise((resolve3, reject) => {
|
|
3791
|
-
const child =
|
|
4107
|
+
const child = spawn5(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
|
|
3792
4108
|
child.once("error", (err) => reject(new KvboxError(`could not run ${pm}: ${err.message}`)));
|
|
3793
4109
|
child.once("close", (code) => resolve3(code ?? 1));
|
|
3794
4110
|
});
|
|
@@ -3910,7 +4226,7 @@ function subdomainFor(name) {
|
|
|
3910
4226
|
}
|
|
3911
4227
|
|
|
3912
4228
|
// src/commands/deploy/ship.ts
|
|
3913
|
-
import { spawn as
|
|
4229
|
+
import { spawn as spawn6 } from "child_process";
|
|
3914
4230
|
import { readdir, stat as stat2 } from "fs/promises";
|
|
3915
4231
|
import { join as join5 } from "path";
|
|
3916
4232
|
var IMAGE_TOO_OLD = 3;
|
|
@@ -3932,8 +4248,8 @@ async function measure(dir, exclude = []) {
|
|
|
3932
4248
|
return total;
|
|
3933
4249
|
}
|
|
3934
4250
|
async function ship(ep, dir, remote, exclude = []) {
|
|
3935
|
-
const tar =
|
|
3936
|
-
const ssh =
|
|
4251
|
+
const tar = spawn6("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
|
|
4252
|
+
const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
|
|
3937
4253
|
tar.stdout.pipe(ssh.stdin);
|
|
3938
4254
|
const chunks = [];
|
|
3939
4255
|
ssh.stdout.on("data", (c) => chunks.push(c));
|
|
@@ -3963,7 +4279,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
3963
4279
|
var shipping = { ship, measure, waitForSsh };
|
|
3964
4280
|
|
|
3965
4281
|
// src/commands/deploy/index.ts
|
|
3966
|
-
var deployCommand = new
|
|
4282
|
+
var deployCommand = new Command61("deploy").description("put the app in this directory (React, Next.js or a Node server) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the port a Next.js app or Node server listens on (default 3000; saved to kvbox.json)", parsePort).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
3967
4283
|
const dir = resolve2(dirArg ?? ".");
|
|
3968
4284
|
const pkg = await readPackageJson(dir);
|
|
3969
4285
|
const saved = await readConfig(dir);
|
|
@@ -4167,15 +4483,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
4167
4483
|
}
|
|
4168
4484
|
|
|
4169
4485
|
// src/commands/volume/index.ts
|
|
4170
|
-
import { Command as
|
|
4486
|
+
import { Command as Command67 } from "commander";
|
|
4171
4487
|
|
|
4172
4488
|
// src/commands/volume/attach.ts
|
|
4173
|
-
import { Command as
|
|
4489
|
+
import { Command as Command62 } from "commander";
|
|
4174
4490
|
function describeMount(machine, volume, box) {
|
|
4175
4491
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
4176
4492
|
return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
|
|
4177
4493
|
}
|
|
4178
|
-
var attachCommand = new
|
|
4494
|
+
var attachCommand = new Command62("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
4179
4495
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
4180
4496
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4181
4497
|
try {
|
|
@@ -4194,7 +4510,7 @@ var attachCommand = new Command58("attach").description("attach a volume to a bo
|
|
|
4194
4510
|
});
|
|
4195
4511
|
|
|
4196
4512
|
// src/commands/volume/create.ts
|
|
4197
|
-
import { Command as
|
|
4513
|
+
import { Command as Command63 } from "commander";
|
|
4198
4514
|
function parseGib2(text2) {
|
|
4199
4515
|
const mib = parseMib(text2);
|
|
4200
4516
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -4210,7 +4526,7 @@ function sizeProblem(answer) {
|
|
|
4210
4526
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
4211
4527
|
}
|
|
4212
4528
|
}
|
|
4213
|
-
var
|
|
4529
|
+
var createCommand3 = new Command63("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
|
|
4214
4530
|
const ask = interactive();
|
|
4215
4531
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
4216
4532
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -4243,8 +4559,8 @@ var createCommand2 = new Command59("create").alias("new").description("create a
|
|
|
4243
4559
|
});
|
|
4244
4560
|
|
|
4245
4561
|
// src/commands/volume/detach.ts
|
|
4246
|
-
import { Command as
|
|
4247
|
-
var detachCommand = new
|
|
4562
|
+
import { Command as Command64 } from "commander";
|
|
4563
|
+
var detachCommand = new Command64("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
4248
4564
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
4249
4565
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4250
4566
|
try {
|
|
@@ -4269,8 +4585,8 @@ var detachCommand = new Command60("detach").description("detach a volume from a
|
|
|
4269
4585
|
});
|
|
4270
4586
|
|
|
4271
4587
|
// src/commands/volume/ls.ts
|
|
4272
|
-
import { Command as
|
|
4273
|
-
var
|
|
4588
|
+
import { Command as Command65 } from "commander";
|
|
4589
|
+
var lsCommand8 = new Command65("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4274
4590
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4275
4591
|
try {
|
|
4276
4592
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4301,8 +4617,8 @@ var lsCommand7 = new Command61("ls").alias("list").description("list volumes: si
|
|
|
4301
4617
|
});
|
|
4302
4618
|
|
|
4303
4619
|
// src/commands/volume/rm.ts
|
|
4304
|
-
import { Command as
|
|
4305
|
-
var rmCommand7 = new
|
|
4620
|
+
import { Command as Command66 } from "commander";
|
|
4621
|
+
var rmCommand7 = new Command66("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4306
4622
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
4307
4623
|
info("cancelled");
|
|
4308
4624
|
process.exitCode = 1;
|
|
@@ -4318,17 +4634,17 @@ var rmCommand7 = new Command62("rm").alias("remove").description("delete a volum
|
|
|
4318
4634
|
});
|
|
4319
4635
|
|
|
4320
4636
|
// src/commands/volume/index.ts
|
|
4321
|
-
var volumeCommand = new
|
|
4637
|
+
var volumeCommand = new Command67("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand7);
|
|
4322
4638
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
4323
4639
|
|
|
4324
4640
|
// src/commands/env/index.ts
|
|
4325
|
-
import { Command as
|
|
4641
|
+
import { Command as Command71 } from "commander";
|
|
4326
4642
|
|
|
4327
4643
|
// src/commands/env/ls.ts
|
|
4328
|
-
import { Command as
|
|
4644
|
+
import { Command as Command68 } from "commander";
|
|
4329
4645
|
|
|
4330
4646
|
// src/commands/env/shared.ts
|
|
4331
|
-
function
|
|
4647
|
+
function requireCloud4(client) {
|
|
4332
4648
|
if (client.target.kind === "local") throw new KvboxError("kvbox env needs kvbox.sh: kvbox login first");
|
|
4333
4649
|
return client.target.org ?? client.target.user ?? "you";
|
|
4334
4650
|
}
|
|
@@ -4352,7 +4668,7 @@ function firstBootHint(box, name) {
|
|
|
4352
4668
|
}
|
|
4353
4669
|
|
|
4354
4670
|
// src/commands/env/ls.ts
|
|
4355
|
-
var
|
|
4671
|
+
var lsCommand9 = new Command68("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4356
4672
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4357
4673
|
try {
|
|
4358
4674
|
if (opts.box !== void 0) {
|
|
@@ -4374,7 +4690,7 @@ var lsCommand8 = new Command64("ls").alias("list").description("list the variabl
|
|
|
4374
4690
|
table([...own.vars.map((v) => row(v, "box")), ...inherited.map((v) => row(v, color.dim(slug)))]);
|
|
4375
4691
|
return;
|
|
4376
4692
|
}
|
|
4377
|
-
const owner =
|
|
4693
|
+
const owner = requireCloud4(client);
|
|
4378
4694
|
const vars = await client.listEnv();
|
|
4379
4695
|
if (opts.json) {
|
|
4380
4696
|
json(vars);
|
|
@@ -4391,12 +4707,12 @@ var lsCommand8 = new Command64("ls").alias("list").description("list the variabl
|
|
|
4391
4707
|
});
|
|
4392
4708
|
|
|
4393
4709
|
// src/commands/env/rm.ts
|
|
4394
|
-
import { Command as
|
|
4395
|
-
var rmCommand8 = new
|
|
4710
|
+
import { Command as Command69 } from "commander";
|
|
4711
|
+
var rmCommand8 = new Command69("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names, opts, cmd) => {
|
|
4396
4712
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4397
4713
|
try {
|
|
4398
4714
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4399
|
-
const owner = target === void 0 ?
|
|
4715
|
+
const owner = target === void 0 ? requireCloud4(client) : `box ${target.ref}`;
|
|
4400
4716
|
if (!await confirm(`Remove ${names.join(", ")} from ${owner}'s variables?`, opts.yes ?? false)) {
|
|
4401
4717
|
info("cancelled");
|
|
4402
4718
|
process.exitCode = 1;
|
|
@@ -4429,11 +4745,11 @@ var rmCommand8 = new Command65("rm").alias("remove").description("remove variabl
|
|
|
4429
4745
|
});
|
|
4430
4746
|
|
|
4431
4747
|
// src/commands/env/set.ts
|
|
4432
|
-
import { Command as
|
|
4433
|
-
var setCommand2 = new
|
|
4748
|
+
import { Command as Command70 } from "commander";
|
|
4749
|
+
var setCommand2 = new Command70("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
|
|
4434
4750
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4435
4751
|
try {
|
|
4436
|
-
const owner = opts.box === void 0 ?
|
|
4752
|
+
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
4437
4753
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4438
4754
|
const ask = interactive();
|
|
4439
4755
|
if ((nameArg === void 0 || valueArg === void 0) && !ask) throw new KvboxError("give the name and the value: kvbox env set NAME VALUE (or run it in a terminal to be asked)");
|
|
@@ -4467,17 +4783,17 @@ var setCommand2 = new Command66("set").description("add or change a variable; bo
|
|
|
4467
4783
|
});
|
|
4468
4784
|
|
|
4469
4785
|
// src/commands/env/index.ts
|
|
4470
|
-
var envCommand = new
|
|
4786
|
+
var envCommand = new Command71("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand9, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand8);
|
|
4471
4787
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
4472
4788
|
|
|
4473
4789
|
// src/commands/domain/index.ts
|
|
4474
|
-
import { Command as
|
|
4790
|
+
import { Command as Command75 } from "commander";
|
|
4475
4791
|
|
|
4476
4792
|
// src/commands/domain/add.ts
|
|
4477
|
-
import { Command as
|
|
4793
|
+
import { Command as Command72 } from "commander";
|
|
4478
4794
|
|
|
4479
4795
|
// src/commands/domain/shared.ts
|
|
4480
|
-
function
|
|
4796
|
+
function requireCloud5(client) {
|
|
4481
4797
|
if (client.target.kind !== "cloud") throw new KvboxError("custom domains need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
4482
4798
|
}
|
|
4483
4799
|
var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.box}` : d.box;
|
|
@@ -4494,12 +4810,12 @@ function hostIn(name, zone) {
|
|
|
4494
4810
|
}
|
|
4495
4811
|
|
|
4496
4812
|
// src/commands/domain/add.ts
|
|
4497
|
-
var addCommand3 = new
|
|
4813
|
+
var addCommand3 = new Command72("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
|
|
4498
4814
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
4499
4815
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
4500
4816
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4501
4817
|
try {
|
|
4502
|
-
|
|
4818
|
+
requireCloud5(client);
|
|
4503
4819
|
const user = me(client);
|
|
4504
4820
|
const box = displayName(await findBox(client, name), user);
|
|
4505
4821
|
const d = await spin(`adding ${domain}\u2026`, client.addDomain(box, { domain, ...port !== void 0 ? { port } : {} }));
|
|
@@ -4530,11 +4846,11 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
4530
4846
|
});
|
|
4531
4847
|
|
|
4532
4848
|
// src/commands/domain/ls.ts
|
|
4533
|
-
import { Command as
|
|
4534
|
-
var
|
|
4849
|
+
import { Command as Command73 } from "commander";
|
|
4850
|
+
var lsCommand10 = new Command73("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4535
4851
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4536
4852
|
try {
|
|
4537
|
-
|
|
4853
|
+
requireCloud5(client);
|
|
4538
4854
|
const user = me(client);
|
|
4539
4855
|
const domains = await client.listDomains();
|
|
4540
4856
|
if (opts.json) {
|
|
@@ -4560,12 +4876,12 @@ var lsCommand9 = new Command69("ls").alias("list").description("list your custom
|
|
|
4560
4876
|
});
|
|
4561
4877
|
|
|
4562
4878
|
// src/commands/domain/rm.ts
|
|
4563
|
-
import { Command as
|
|
4564
|
-
var rmCommand9 = new
|
|
4879
|
+
import { Command as Command74 } from "commander";
|
|
4880
|
+
var rmCommand9 = new Command74("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
|
|
4565
4881
|
const domain = domainArg.trim().toLowerCase();
|
|
4566
4882
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4567
4883
|
try {
|
|
4568
|
-
|
|
4884
|
+
requireCloud5(client);
|
|
4569
4885
|
const found = (await client.listDomains()).find((d) => d.domain === domain);
|
|
4570
4886
|
if (!found) throw new KvboxError(`domain ${domain}: not found (kvbox domain ls)`);
|
|
4571
4887
|
const box = boxOf2(found, me(client));
|
|
@@ -4582,12 +4898,12 @@ var rmCommand9 = new Command70("rm").alias("remove").description("stop serving a
|
|
|
4582
4898
|
});
|
|
4583
4899
|
|
|
4584
4900
|
// src/commands/domain/index.ts
|
|
4585
|
-
var domainCommand = new
|
|
4901
|
+
var domainCommand = new Command75("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand10).addCommand(rmCommand9);
|
|
4586
4902
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4587
4903
|
|
|
4588
4904
|
// src/program.ts
|
|
4589
4905
|
function buildProgram() {
|
|
4590
|
-
const program = new
|
|
4906
|
+
const program = new Command76("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
|
|
4591
4907
|
program.addCommand(vmCommand);
|
|
4592
4908
|
program.addCommand(snapshotsCommand);
|
|
4593
4909
|
program.addCommand(volumeCommand);
|