@kvbox/cli 0.5.36 → 0.5.38
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 +345 -123
- 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.38" : 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(),
|
|
@@ -524,6 +582,11 @@ var MachineSchema = z2.object({
|
|
|
524
582
|
ports: z2.array(PortForwardSchema).optional(),
|
|
525
583
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /machines`. */
|
|
526
584
|
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
585
|
+
/**
|
|
586
|
+
* The name of the host the box runs on. Only the control plane fills it in, on `GET /machines`: a box
|
|
587
|
+
* links to, and a volume attaches to, only a box on the same host.
|
|
588
|
+
*/
|
|
589
|
+
host: z2.string().optional(),
|
|
527
590
|
/** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
|
|
528
591
|
autoHibernateSec: z2.number().int().positive().optional(),
|
|
529
592
|
/** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
|
|
@@ -551,7 +614,9 @@ var VolumeSchema = z2.object({
|
|
|
551
614
|
attachedTo: z2.string().nullable(),
|
|
552
615
|
createdAt: z2.string(),
|
|
553
616
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /volumes`. */
|
|
554
|
-
ownerKind: z2.enum(["user", "org"]).optional()
|
|
617
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
618
|
+
/** The name of the host the volume lives on; only the control plane fills it in. It attaches only to a box there. */
|
|
619
|
+
host: z2.string().optional()
|
|
555
620
|
});
|
|
556
621
|
var MAX_VOLUME_GIB = 4096;
|
|
557
622
|
var VOLUME_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
@@ -700,6 +765,7 @@ var CapacitySchema = z2.object({
|
|
|
700
765
|
*/
|
|
701
766
|
images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional()
|
|
702
767
|
});
|
|
768
|
+
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
703
769
|
var RecoveryReportSchema = z2.object({
|
|
704
770
|
at: z2.string(),
|
|
705
771
|
booted: z2.array(z2.string()),
|
|
@@ -1118,7 +1184,7 @@ var ServerClient = class {
|
|
|
1118
1184
|
base;
|
|
1119
1185
|
autoStart;
|
|
1120
1186
|
startedOnce = false;
|
|
1121
|
-
async call(method, path, schema, body, org = this.target.kind === "cloud" ? this.target.org : void 0) {
|
|
1187
|
+
async call(method, path, schema, body, org = this.target.kind === "cloud" ? this.target.org : void 0, timeoutMs) {
|
|
1122
1188
|
const headers = {};
|
|
1123
1189
|
if (body !== void 0) headers["content-type"] = "application/json";
|
|
1124
1190
|
if (this.target.kind === "cloud" && this.target.token !== "") headers["authorization"] = `Bearer ${this.target.token}`;
|
|
@@ -1129,7 +1195,8 @@ var ServerClient = class {
|
|
|
1129
1195
|
dispatcher: this.dispatcher,
|
|
1130
1196
|
method,
|
|
1131
1197
|
headers,
|
|
1132
|
-
body: body === void 0 ? null : JSON.stringify(body)
|
|
1198
|
+
body: body === void 0 ? null : JSON.stringify(body),
|
|
1199
|
+
...timeoutMs !== void 0 ? { headersTimeout: timeoutMs, bodyTimeout: timeoutMs } : {}
|
|
1133
1200
|
});
|
|
1134
1201
|
} catch (err) {
|
|
1135
1202
|
const code = err.code ?? err.cause;
|
|
@@ -1137,7 +1204,7 @@ var ServerClient = class {
|
|
|
1137
1204
|
if (this.autoStart && !this.startedOnce) {
|
|
1138
1205
|
this.startedOnce = true;
|
|
1139
1206
|
await spin("starting kvbox-server\u2026", startLocalServer(paths(), 5e3));
|
|
1140
|
-
return this.call(method, path, schema, body);
|
|
1207
|
+
return this.call(method, path, schema, body, org, timeoutMs);
|
|
1141
1208
|
}
|
|
1142
1209
|
throw new KvboxError(`kvbox-server is not running (${String(code)}); start it with: kvbox server start`);
|
|
1143
1210
|
}
|
|
@@ -1224,6 +1291,24 @@ var ServerClient = class {
|
|
|
1224
1291
|
removeLink(name, req) {
|
|
1225
1292
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
|
|
1226
1293
|
}
|
|
1294
|
+
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
1295
|
+
listBackups() {
|
|
1296
|
+
return this.call("GET", "/backups", z3.array(BackupSchema));
|
|
1297
|
+
}
|
|
1298
|
+
boxBackups(name) {
|
|
1299
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z3.array(BackupSchema));
|
|
1300
|
+
}
|
|
1301
|
+
boxBackup(name, id) {
|
|
1302
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
1303
|
+
}
|
|
1304
|
+
/** Starts one; it runs in the background (`running`), `boxBackup` says how it ended. */
|
|
1305
|
+
createBoxBackup(name) {
|
|
1306
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/backups`, BackupSchema);
|
|
1307
|
+
}
|
|
1308
|
+
/** The box's disk becomes the backup's; a running box restarts. Waits for the whole download. */
|
|
1309
|
+
restoreBoxBackup(name, id) {
|
|
1310
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}/restore`, MachineSchema, {}, void 0, 2 * 36e5);
|
|
1311
|
+
}
|
|
1227
1312
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
1228
1313
|
boxHooks(name) {
|
|
1229
1314
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z3.array(WakeHookSchema));
|
|
@@ -2035,7 +2120,11 @@ function addressOf(b) {
|
|
|
2035
2120
|
var lsCommand = new Command5("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2036
2121
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2037
2122
|
try {
|
|
2038
|
-
const
|
|
2123
|
+
const cloud = client.target.kind === "cloud";
|
|
2124
|
+
const [boxes, admin] = await spin(
|
|
2125
|
+
"listing boxes\u2026",
|
|
2126
|
+
Promise.all([client.listMachines({ all: opts.all }), cloud && !opts.json ? client.me().then((u) => u.role === "admin", () => false) : Promise.resolve(false)])
|
|
2127
|
+
);
|
|
2039
2128
|
if (opts.json) {
|
|
2040
2129
|
json(boxes);
|
|
2041
2130
|
return;
|
|
@@ -2046,7 +2135,7 @@ var lsCommand = new Command5("ls").description("list boxes with status and addre
|
|
|
2046
2135
|
return;
|
|
2047
2136
|
}
|
|
2048
2137
|
if (org !== void 0) info(`boxes of ${org}`);
|
|
2049
|
-
table(lsRows(boxes,
|
|
2138
|
+
table(lsRows(boxes, cloud ? { me: me(client), showHost: admin } : void 0));
|
|
2050
2139
|
} finally {
|
|
2051
2140
|
await client.close();
|
|
2052
2141
|
}
|
|
@@ -2056,6 +2145,7 @@ function lsRows(boxes, cloud) {
|
|
|
2056
2145
|
...cloud ? { owner: ownerCell(b, cloud.me) } : {},
|
|
2057
2146
|
name: boxName(b.name),
|
|
2058
2147
|
status: status(b.status),
|
|
2148
|
+
...cloud?.showHost ? { host: b.host ?? "-" } : {},
|
|
2059
2149
|
address: addressOf(b),
|
|
2060
2150
|
size: b.status === "unknown" ? "-" : `${shape(b.vcpu, b.memMib, b.diskBytes)} ${color.dim(`(${gbShort(b.diskUsedBytes)} used)`)}`,
|
|
2061
2151
|
created: age(b.createdAt),
|
|
@@ -2575,9 +2665,141 @@ var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake
|
|
|
2575
2665
|
var hookCommand = new Command21("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
|
|
2576
2666
|
for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2577
2667
|
|
|
2668
|
+
// src/commands/vm/backup/index.ts
|
|
2669
|
+
import { Command as Command25 } from "commander";
|
|
2670
|
+
|
|
2671
|
+
// src/commands/vm/backup/create.ts
|
|
2672
|
+
import { Command as Command22 } from "commander";
|
|
2673
|
+
|
|
2674
|
+
// src/commands/vm/backup/shared.ts
|
|
2675
|
+
import { setTimeout as sleep2 } from "timers/promises";
|
|
2676
|
+
function requireCloud3(client) {
|
|
2677
|
+
if (client.target.kind !== "cloud") throw new KvboxError("backups need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
2678
|
+
}
|
|
2679
|
+
var POLL_MS = 2e3;
|
|
2680
|
+
var POLL_TRIES = 30;
|
|
2681
|
+
var WAIT_MS = 7 * 36e5;
|
|
2682
|
+
async function untilDone(client, box, id, opts = {}) {
|
|
2683
|
+
const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
|
|
2684
|
+
const until = Date.now() + waitMs;
|
|
2685
|
+
let failed = 0;
|
|
2686
|
+
for (; ; ) {
|
|
2687
|
+
try {
|
|
2688
|
+
const b = await client.boxBackup(box, id);
|
|
2689
|
+
if (b.status !== "running") return b;
|
|
2690
|
+
failed = 0;
|
|
2691
|
+
} catch (err) {
|
|
2692
|
+
failed += 1;
|
|
2693
|
+
if (failed >= tries) throw lostTrack(box, id, `could not ask how it is doing: ${err.message}`);
|
|
2694
|
+
}
|
|
2695
|
+
if (Date.now() >= until) throw lostTrack(box, id, "it is taking longer than a backup is given");
|
|
2696
|
+
await sleep2(pollMs);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
function lostTrack(box, id, why) {
|
|
2700
|
+
return new KvboxError(`stopped waiting for backup ${id} of box ${box} (${why}); it may still be running: kvbox vm backup ls ${box}`);
|
|
2701
|
+
}
|
|
2702
|
+
function sizeLine(b) {
|
|
2703
|
+
const data = b.dataBytes === null ? "?" : gb(b.dataBytes);
|
|
2704
|
+
const added = b.uploadedBytes === null ? "" : `, ${gb(b.uploadedBytes)} uploaded`;
|
|
2705
|
+
return `${data} of data${added}`;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// src/commands/vm/backup/create.ts
|
|
2709
|
+
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("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
2710
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2711
|
+
try {
|
|
2712
|
+
requireCloud3(client);
|
|
2713
|
+
const found = await findBox(client, name);
|
|
2714
|
+
const box = displayName(found, me(client));
|
|
2715
|
+
const started = await client.createBoxBackup(box);
|
|
2716
|
+
if (!opts.wait) {
|
|
2717
|
+
if (opts.json) json(started);
|
|
2718
|
+
else {
|
|
2719
|
+
info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box)} started; it runs in the background`);
|
|
2720
|
+
info(color.dim(` status: kvbox vm backup ls ${box}`));
|
|
2721
|
+
}
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
const done = await spin(`backing up ${box}\u2026`, untilDone(client, box, started.id));
|
|
2725
|
+
if (opts.json) json(done);
|
|
2726
|
+
if (done.status === "failed") throw new KvboxError(`backup ${done.id} of box ${box} failed: ${done.error ?? "no reason given"}`);
|
|
2727
|
+
if (opts.json) return;
|
|
2728
|
+
info(`${color.green("\u2713")} backup ${done.id} of box ${color.bold(box)}: ${sizeLine(done)}`);
|
|
2729
|
+
if ((found.volumes?.length ?? 0) > 0) info(color.dim(` not included: volume${found.volumes.length > 1 ? "s" : ""} ${found.volumes.map((v) => v.name).join(", ")}`));
|
|
2730
|
+
info(color.dim(` restore with: kvbox vm backup restore ${box} ${done.id}`));
|
|
2731
|
+
} finally {
|
|
2732
|
+
await client.close();
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
|
|
2736
|
+
// src/commands/vm/backup/ls.ts
|
|
2737
|
+
import { Command as Command23 } from "commander";
|
|
2738
|
+
var lsCommand4 = new Command23("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2739
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2740
|
+
try {
|
|
2741
|
+
requireCloud3(client);
|
|
2742
|
+
const box = name === void 0 ? void 0 : displayName(await findBox(client, name), me(client));
|
|
2743
|
+
const list = box === void 0 ? await client.listBackups() : await client.boxBackups(box);
|
|
2744
|
+
if (opts.json) {
|
|
2745
|
+
json(list);
|
|
2746
|
+
return;
|
|
2747
|
+
}
|
|
2748
|
+
if (list.length === 0) {
|
|
2749
|
+
info(box === void 0 ? "no backups yet; make one with: kvbox vm backup create <box>" : `box ${box} has no backups; make one with: kvbox vm backup create ${box}`);
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
const anyError = list.some((b) => b.error !== null);
|
|
2753
|
+
table(
|
|
2754
|
+
list.map((b) => ({
|
|
2755
|
+
id: b.id,
|
|
2756
|
+
...box === void 0 ? { box: b.owner === me(client) ? b.box : `${b.owner}/${b.box}` } : {},
|
|
2757
|
+
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
2758
|
+
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
2759
|
+
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
2760
|
+
disk: b.diskBytes === null ? "-" : gbShort(b.diskBytes),
|
|
2761
|
+
by: b.createdBy ?? "-",
|
|
2762
|
+
taken: age(b.createdAt),
|
|
2763
|
+
...anyError ? { error: b.error ?? "" } : {}
|
|
2764
|
+
}))
|
|
2765
|
+
);
|
|
2766
|
+
} finally {
|
|
2767
|
+
await client.close();
|
|
2768
|
+
}
|
|
2769
|
+
});
|
|
2770
|
+
|
|
2771
|
+
// src/commands/vm/backup/restore.ts
|
|
2772
|
+
import { Command as Command24 } from "commander";
|
|
2773
|
+
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) => {
|
|
2774
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2775
|
+
try {
|
|
2776
|
+
requireCloud3(client);
|
|
2777
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2778
|
+
const backup = await client.boxBackup(box, id);
|
|
2779
|
+
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.`;
|
|
2780
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
2781
|
+
info("cancelled");
|
|
2782
|
+
process.exitCode = 1;
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
const machine = await spin(`restoring ${box} from ${backup.id}\u2026`, client.restoreBoxBackup(box, id));
|
|
2786
|
+
if (opts.json) {
|
|
2787
|
+
json(machine);
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
info(`${color.green("\u2713")} box ${color.bold(box)} restored from backup ${backup.id}; it is ${machine.status}`);
|
|
2791
|
+
} finally {
|
|
2792
|
+
await client.close();
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
|
|
2796
|
+
// src/commands/vm/backup/index.ts
|
|
2797
|
+
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);
|
|
2798
|
+
for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2799
|
+
|
|
2578
2800
|
// src/commands/vm/rescale.ts
|
|
2579
|
-
import { Command as
|
|
2580
|
-
var rescaleCommand = new
|
|
2801
|
+
import { Command as Command26, Option as Option3 } from "commander";
|
|
2802
|
+
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) => {
|
|
2581
2803
|
const req = {
|
|
2582
2804
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
2583
2805
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -2623,8 +2845,8 @@ function parseGib(flag, text2) {
|
|
|
2623
2845
|
}
|
|
2624
2846
|
|
|
2625
2847
|
// src/commands/vm/resume.ts
|
|
2626
|
-
import { Command as
|
|
2627
|
-
var resumeCommand = new
|
|
2848
|
+
import { Command as Command27 } from "commander";
|
|
2849
|
+
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) => {
|
|
2628
2850
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2629
2851
|
try {
|
|
2630
2852
|
const box = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
|
|
@@ -2636,8 +2858,8 @@ var resumeCommand = new Command23("resume").description("continue a box that is
|
|
|
2636
2858
|
});
|
|
2637
2859
|
|
|
2638
2860
|
// src/commands/vm/rm.ts
|
|
2639
|
-
import { Command as
|
|
2640
|
-
var rmCommand3 = new
|
|
2861
|
+
import { Command as Command28 } from "commander";
|
|
2862
|
+
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) => {
|
|
2641
2863
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2642
2864
|
try {
|
|
2643
2865
|
const box = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2657,7 +2879,7 @@ var rmCommand3 = new Command24("rm").description("destroy a box (its disk is del
|
|
|
2657
2879
|
});
|
|
2658
2880
|
|
|
2659
2881
|
// src/commands/vm/set.ts
|
|
2660
|
-
import { Command as
|
|
2882
|
+
import { Command as Command29 } from "commander";
|
|
2661
2883
|
|
|
2662
2884
|
// src/swap.ts
|
|
2663
2885
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -2733,7 +2955,7 @@ function runSwap(ep, mib) {
|
|
|
2733
2955
|
}
|
|
2734
2956
|
|
|
2735
2957
|
// src/commands/vm/set.ts
|
|
2736
|
-
var setCommand = new
|
|
2958
|
+
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) => {
|
|
2737
2959
|
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
|
|
2738
2960
|
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
|
|
2739
2961
|
}
|
|
@@ -2802,8 +3024,8 @@ function parseIdleCheck(text2) {
|
|
|
2802
3024
|
}
|
|
2803
3025
|
|
|
2804
3026
|
// src/commands/vm/start.ts
|
|
2805
|
-
import { Command as
|
|
2806
|
-
var startCommand = new
|
|
3027
|
+
import { Command as Command30 } from "commander";
|
|
3028
|
+
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) => {
|
|
2807
3029
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2808
3030
|
try {
|
|
2809
3031
|
const box = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
|
|
@@ -2815,8 +3037,8 @@ var startCommand = new Command26("start").description("boot a stopped box again
|
|
|
2815
3037
|
});
|
|
2816
3038
|
|
|
2817
3039
|
// src/commands/vm/stop.ts
|
|
2818
|
-
import { Command as
|
|
2819
|
-
var stopCommand = new
|
|
3040
|
+
import { Command as Command31 } from "commander";
|
|
3041
|
+
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) => {
|
|
2820
3042
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2821
3043
|
try {
|
|
2822
3044
|
const box = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
|
|
@@ -2828,8 +3050,8 @@ var stopCommand = new Command27("stop").description("shut a box down (its disk i
|
|
|
2828
3050
|
});
|
|
2829
3051
|
|
|
2830
3052
|
// src/commands/vm/top.ts
|
|
2831
|
-
import { Command as
|
|
2832
|
-
var topCommand = new
|
|
3053
|
+
import { Command as Command32 } from "commander";
|
|
3054
|
+
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) => {
|
|
2833
3055
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2834
3056
|
try {
|
|
2835
3057
|
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
@@ -2889,8 +3111,8 @@ function topRows(entries, cloud) {
|
|
|
2889
3111
|
}
|
|
2890
3112
|
|
|
2891
3113
|
// src/commands/vm/unlink.ts
|
|
2892
|
-
import { Command as
|
|
2893
|
-
var unlinkCommand = new
|
|
3114
|
+
import { Command as Command33 } from "commander";
|
|
3115
|
+
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) => {
|
|
2894
3116
|
const port = parseLinkPort(opts.port);
|
|
2895
3117
|
if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
|
|
2896
3118
|
info("cancelled");
|
|
@@ -2911,8 +3133,8 @@ var unlinkCommand = new Command29("unlink").description("take a link away (kvbox
|
|
|
2911
3133
|
});
|
|
2912
3134
|
|
|
2913
3135
|
// src/commands/vm/update.ts
|
|
2914
|
-
import { Command as
|
|
2915
|
-
var updateCommand = new
|
|
3136
|
+
import { Command as Command34 } from "commander";
|
|
3137
|
+
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) => {
|
|
2916
3138
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2917
3139
|
try {
|
|
2918
3140
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2934,8 +3156,8 @@ var updateCommand = new Command30("update").description("move a box onto the cur
|
|
|
2934
3156
|
});
|
|
2935
3157
|
|
|
2936
3158
|
// src/commands/vm/usage.ts
|
|
2937
|
-
import { Command as
|
|
2938
|
-
var usageCommand = new
|
|
3159
|
+
import { Command as Command35 } from "commander";
|
|
3160
|
+
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) => {
|
|
2939
3161
|
let since;
|
|
2940
3162
|
if (opts.since !== void 0) {
|
|
2941
3163
|
const t = Date.parse(opts.since);
|
|
@@ -2982,8 +3204,8 @@ function block(u) {
|
|
|
2982
3204
|
}
|
|
2983
3205
|
|
|
2984
3206
|
// src/commands/vm/wake.ts
|
|
2985
|
-
import { Command as
|
|
2986
|
-
var wakeCommand = new
|
|
3207
|
+
import { Command as Command36 } from "commander";
|
|
3208
|
+
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) => {
|
|
2987
3209
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2988
3210
|
try {
|
|
2989
3211
|
const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
|
|
@@ -2995,20 +3217,20 @@ var wakeCommand = new Command32("wake").description("continue a hibernated box w
|
|
|
2995
3217
|
});
|
|
2996
3218
|
|
|
2997
3219
|
// src/commands/vm/index.ts
|
|
2998
|
-
var vmCommand = new
|
|
2999
|
-
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
3220
|
+
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);
|
|
3221
|
+
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)");
|
|
3000
3222
|
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
|
|
3001
3223
|
|
|
3002
3224
|
// src/commands/server/index.ts
|
|
3003
|
-
import { Command as
|
|
3225
|
+
import { Command as Command45 } from "commander";
|
|
3004
3226
|
|
|
3005
3227
|
// src/commands/server/join.ts
|
|
3006
|
-
import { Command as
|
|
3228
|
+
import { Command as Command38 } from "commander";
|
|
3007
3229
|
|
|
3008
3230
|
// src/commands/server/daemon.ts
|
|
3009
3231
|
import { spawn as spawn4 } from "child_process";
|
|
3010
3232
|
import { readFile as readFile4 } from "fs/promises";
|
|
3011
|
-
import { setTimeout as
|
|
3233
|
+
import { setTimeout as sleep3 } from "timers/promises";
|
|
3012
3234
|
async function runningPid(p = paths()) {
|
|
3013
3235
|
let pid;
|
|
3014
3236
|
try {
|
|
@@ -3031,7 +3253,7 @@ async function stopLocalServer(pid, timeoutMs = 1e4) {
|
|
|
3031
3253
|
const deadline = Date.now() + timeoutMs;
|
|
3032
3254
|
while (alive(pid)) {
|
|
3033
3255
|
if (Date.now() > deadline) throw new KvboxError(`kvbox-server (pid ${pid}) did not stop within ${timeoutMs / 1e3}s`);
|
|
3034
|
-
await
|
|
3256
|
+
await sleep3(100);
|
|
3035
3257
|
}
|
|
3036
3258
|
}
|
|
3037
3259
|
async function restartLocalServer(p = paths()) {
|
|
@@ -3057,7 +3279,7 @@ function runKvboxServer(args) {
|
|
|
3057
3279
|
}
|
|
3058
3280
|
|
|
3059
3281
|
// src/commands/server/join.ts
|
|
3060
|
-
var joinCommand = new
|
|
3282
|
+
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) => {
|
|
3061
3283
|
const args = ["join", url, "--token", opts.token];
|
|
3062
3284
|
if (opts.advertise !== void 0) args.push("--advertise", opts.advertise);
|
|
3063
3285
|
if (opts.name !== void 0) args.push("--name", opts.name);
|
|
@@ -3067,8 +3289,8 @@ var joinCommand = new Command34("join").description("put this machine behind a c
|
|
|
3067
3289
|
});
|
|
3068
3290
|
|
|
3069
3291
|
// src/commands/server/leave.ts
|
|
3070
|
-
import { Command as
|
|
3071
|
-
var leaveCommand = new
|
|
3292
|
+
import { Command as Command39 } from "commander";
|
|
3293
|
+
var leaveCommand = new Command39("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
|
|
3072
3294
|
const p = paths();
|
|
3073
3295
|
for (const line of (await runKvboxServer(["leave"])).split("\n")) info(line);
|
|
3074
3296
|
if (await runningPid(p) === null) return;
|
|
@@ -3077,14 +3299,14 @@ var leaveCommand = new Command35("leave").description("take this machine out fro
|
|
|
3077
3299
|
});
|
|
3078
3300
|
|
|
3079
3301
|
// src/commands/server/relay.ts
|
|
3080
|
-
import { Command as
|
|
3081
|
-
var relayCommand = new
|
|
3302
|
+
import { Command as Command40 } from "commander";
|
|
3303
|
+
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) => {
|
|
3082
3304
|
for (const line of (await runKvboxServer(["relay", joinString])).split("\n")) info(line);
|
|
3083
3305
|
});
|
|
3084
3306
|
|
|
3085
3307
|
// src/commands/server/start.ts
|
|
3086
|
-
import { Command as
|
|
3087
|
-
var startCommand2 = new
|
|
3308
|
+
import { Command as Command41 } from "commander";
|
|
3309
|
+
var startCommand2 = new Command41("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
|
|
3088
3310
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true }, { autoStart: false });
|
|
3089
3311
|
try {
|
|
3090
3312
|
const health = await client.health();
|
|
@@ -3100,8 +3322,8 @@ var startCommand2 = new Command37("start").description("start the local kvbox-se
|
|
|
3100
3322
|
});
|
|
3101
3323
|
|
|
3102
3324
|
// src/commands/server/status.ts
|
|
3103
|
-
import { Command as
|
|
3104
|
-
var statusCommand = new
|
|
3325
|
+
import { Command as Command42 } from "commander";
|
|
3326
|
+
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) => {
|
|
3105
3327
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
3106
3328
|
try {
|
|
3107
3329
|
const health = await client.health();
|
|
@@ -3133,8 +3355,8 @@ var statusCommand = new Command38("status").description("show whether this machi
|
|
|
3133
3355
|
});
|
|
3134
3356
|
|
|
3135
3357
|
// src/commands/server/stop.ts
|
|
3136
|
-
import { Command as
|
|
3137
|
-
var stopCommand2 = new
|
|
3358
|
+
import { Command as Command43 } from "commander";
|
|
3359
|
+
var stopCommand2 = new Command43("stop").description("stop the local server (running boxes are not affected)").action(async () => {
|
|
3138
3360
|
const pid = await runningPid(paths());
|
|
3139
3361
|
if (pid === null) throw new KvboxError("kvbox-server is not running");
|
|
3140
3362
|
await stopLocalServer(pid);
|
|
@@ -3142,8 +3364,8 @@ var stopCommand2 = new Command39("stop").description("stop the local server (run
|
|
|
3142
3364
|
});
|
|
3143
3365
|
|
|
3144
3366
|
// src/commands/server/trust-ca.ts
|
|
3145
|
-
import { Command as
|
|
3146
|
-
var trustCaCommand = new
|
|
3367
|
+
import { Command as Command44 } from "commander";
|
|
3368
|
+
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) => {
|
|
3147
3369
|
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");
|
|
3148
3370
|
if (publicKey !== void 0 && opts.fromCloud) throw new KvboxError("either a public key or --from-cloud, not both");
|
|
3149
3371
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
@@ -3181,7 +3403,7 @@ function describeReport(report) {
|
|
|
3181
3403
|
}
|
|
3182
3404
|
|
|
3183
3405
|
// src/commands/server/index.ts
|
|
3184
|
-
var serverCommand = new
|
|
3406
|
+
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);
|
|
3185
3407
|
|
|
3186
3408
|
// src/commands/login.ts
|
|
3187
3409
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
@@ -3189,8 +3411,8 @@ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from
|
|
|
3189
3411
|
import { hostname as osHostname } from "os";
|
|
3190
3412
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
3191
3413
|
import { Writable } from "stream";
|
|
3192
|
-
import { Command as
|
|
3193
|
-
var loginCommand = new
|
|
3414
|
+
import { Command as Command46 } from "commander";
|
|
3415
|
+
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) => {
|
|
3194
3416
|
const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
|
|
3195
3417
|
const creds = await readCredentials(opts);
|
|
3196
3418
|
const session = await runLogin(url, creds, paths());
|
|
@@ -3270,8 +3492,8 @@ async function firstLine(stream) {
|
|
|
3270
3492
|
}
|
|
3271
3493
|
|
|
3272
3494
|
// src/commands/logout.ts
|
|
3273
|
-
import { Command as
|
|
3274
|
-
var logoutCommand = new
|
|
3495
|
+
import { Command as Command47 } from "commander";
|
|
3496
|
+
var logoutCommand = new Command47("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
|
|
3275
3497
|
const p = paths();
|
|
3276
3498
|
const session = await readSession(p).catch(() => null);
|
|
3277
3499
|
switch (await runLogout(p)) {
|
|
@@ -3308,8 +3530,8 @@ async function runLogout(p = paths()) {
|
|
|
3308
3530
|
}
|
|
3309
3531
|
|
|
3310
3532
|
// src/commands/whoami.ts
|
|
3311
|
-
import { Command as
|
|
3312
|
-
var whoamiCommand = new
|
|
3533
|
+
import { Command as Command48 } from "commander";
|
|
3534
|
+
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) => {
|
|
3313
3535
|
const session = await readSession();
|
|
3314
3536
|
if (opts.json) {
|
|
3315
3537
|
json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
|
|
@@ -3325,11 +3547,11 @@ function describeSession(session) {
|
|
|
3325
3547
|
}
|
|
3326
3548
|
|
|
3327
3549
|
// src/commands/snapshots/index.ts
|
|
3328
|
-
import { Command as
|
|
3550
|
+
import { Command as Command52 } from "commander";
|
|
3329
3551
|
|
|
3330
3552
|
// src/commands/snapshots/ls.ts
|
|
3331
|
-
import { Command as
|
|
3332
|
-
var
|
|
3553
|
+
import { Command as Command49 } from "commander";
|
|
3554
|
+
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) => {
|
|
3333
3555
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3334
3556
|
try {
|
|
3335
3557
|
const cloud = client.target.kind === "cloud";
|
|
@@ -3360,8 +3582,8 @@ var lsCommand4 = new Command45("ls").description("list snapshots (yours and your
|
|
|
3360
3582
|
});
|
|
3361
3583
|
|
|
3362
3584
|
// src/commands/snapshots/new.ts
|
|
3363
|
-
import { Command as
|
|
3364
|
-
var newCommand2 = new
|
|
3585
|
+
import { Command as Command50 } from "commander";
|
|
3586
|
+
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) => {
|
|
3365
3587
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3366
3588
|
try {
|
|
3367
3589
|
const req = { box, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -3374,8 +3596,8 @@ var newCommand2 = new Command46("new").description("freeze a running box (memory
|
|
|
3374
3596
|
});
|
|
3375
3597
|
|
|
3376
3598
|
// src/commands/snapshots/rm.ts
|
|
3377
|
-
import { Command as
|
|
3378
|
-
var rmCommand4 = new
|
|
3599
|
+
import { Command as Command51 } from "commander";
|
|
3600
|
+
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) => {
|
|
3379
3601
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
3380
3602
|
info("cancelled");
|
|
3381
3603
|
process.exitCode = 1;
|
|
@@ -3391,14 +3613,14 @@ var rmCommand4 = new Command47("rm").description("delete a snapshot (boxes made
|
|
|
3391
3613
|
});
|
|
3392
3614
|
|
|
3393
3615
|
// src/commands/snapshots/index.ts
|
|
3394
|
-
var snapshotsCommand = new
|
|
3616
|
+
var snapshotsCommand = new Command52("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand5).addCommand(rmCommand4);
|
|
3395
3617
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
3396
3618
|
|
|
3397
3619
|
// src/commands/org/index.ts
|
|
3398
|
-
import { Command as
|
|
3620
|
+
import { Command as Command58 } from "commander";
|
|
3399
3621
|
|
|
3400
3622
|
// src/commands/org/ls.ts
|
|
3401
|
-
import { Command as
|
|
3623
|
+
import { Command as Command53 } from "commander";
|
|
3402
3624
|
|
|
3403
3625
|
// src/commands/org/context.ts
|
|
3404
3626
|
var NOT_LOGGED_IN = "orgs live on the control plane: kvbox login first";
|
|
@@ -3418,7 +3640,7 @@ function orgFor(opts, target) {
|
|
|
3418
3640
|
}
|
|
3419
3641
|
|
|
3420
3642
|
// src/commands/org/ls.ts
|
|
3421
|
-
var
|
|
3643
|
+
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) => {
|
|
3422
3644
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3423
3645
|
try {
|
|
3424
3646
|
const orgs = await client.listOrgs();
|
|
@@ -3440,8 +3662,8 @@ function orgRows(orgs) {
|
|
|
3440
3662
|
}
|
|
3441
3663
|
|
|
3442
3664
|
// src/commands/org/members.ts
|
|
3443
|
-
import { Command as
|
|
3444
|
-
var
|
|
3665
|
+
import { Command as Command54, Option as Option4 } from "commander";
|
|
3666
|
+
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) => {
|
|
3445
3667
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3446
3668
|
try {
|
|
3447
3669
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -3455,7 +3677,7 @@ var lsCommand6 = new Command50("ls").description("list an org's members and thei
|
|
|
3455
3677
|
await client.close();
|
|
3456
3678
|
}
|
|
3457
3679
|
});
|
|
3458
|
-
var addCommand2 = new
|
|
3680
|
+
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) => {
|
|
3459
3681
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3460
3682
|
try {
|
|
3461
3683
|
const slug = orgFor(opts, client.target);
|
|
@@ -3465,7 +3687,7 @@ var addCommand2 = new Command50("add").description("add a user to an org (admins
|
|
|
3465
3687
|
await client.close();
|
|
3466
3688
|
}
|
|
3467
3689
|
});
|
|
3468
|
-
var rmCommand5 = new
|
|
3690
|
+
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) => {
|
|
3469
3691
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3470
3692
|
try {
|
|
3471
3693
|
const slug = orgFor(opts, client.target);
|
|
@@ -3481,11 +3703,11 @@ var rmCommand5 = new Command50("rm").description("remove a member (or leave: rem
|
|
|
3481
3703
|
await client.close();
|
|
3482
3704
|
}
|
|
3483
3705
|
});
|
|
3484
|
-
var membersCommand = new
|
|
3706
|
+
var membersCommand = new Command54("members").description("who is in an org and what they may do").addCommand(lsCommand7).addCommand(addCommand2).addCommand(rmCommand5);
|
|
3485
3707
|
|
|
3486
3708
|
// src/commands/org/new.ts
|
|
3487
|
-
import { Command as
|
|
3488
|
-
var newCommand3 = new
|
|
3709
|
+
import { Command as Command55 } from "commander";
|
|
3710
|
+
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) => {
|
|
3489
3711
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3490
3712
|
try {
|
|
3491
3713
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -3501,8 +3723,8 @@ var newCommand3 = new Command51("new").description("create an org; you become it
|
|
|
3501
3723
|
});
|
|
3502
3724
|
|
|
3503
3725
|
// src/commands/org/rm.ts
|
|
3504
|
-
import { Command as
|
|
3505
|
-
var rmCommand6 = new
|
|
3726
|
+
import { Command as Command56 } from "commander";
|
|
3727
|
+
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) => {
|
|
3506
3728
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
3507
3729
|
info("cancelled");
|
|
3508
3730
|
process.exitCode = 1;
|
|
@@ -3518,8 +3740,8 @@ var rmCommand6 = new Command52("rm").description("delete an org (owners only; re
|
|
|
3518
3740
|
});
|
|
3519
3741
|
|
|
3520
3742
|
// src/commands/org/role.ts
|
|
3521
|
-
import { Argument, Command as
|
|
3522
|
-
var roleCommand = new
|
|
3743
|
+
import { Argument, Command as Command57 } from "commander";
|
|
3744
|
+
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) => {
|
|
3523
3745
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3524
3746
|
try {
|
|
3525
3747
|
const slug = orgFor(opts, client.target);
|
|
@@ -3531,10 +3753,10 @@ var roleCommand = new Command53("role").description("change a member's role (own
|
|
|
3531
3753
|
});
|
|
3532
3754
|
|
|
3533
3755
|
// src/commands/org/index.ts
|
|
3534
|
-
var orgCommand = new
|
|
3756
|
+
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);
|
|
3535
3757
|
|
|
3536
3758
|
// src/commands/usage.ts
|
|
3537
|
-
import { Command as
|
|
3759
|
+
import { Command as Command59 } from "commander";
|
|
3538
3760
|
|
|
3539
3761
|
// ../shared/src/usage.ts
|
|
3540
3762
|
import { z as z4 } from "zod";
|
|
@@ -3572,7 +3794,7 @@ function sumUsage(items, pricing) {
|
|
|
3572
3794
|
}
|
|
3573
3795
|
|
|
3574
3796
|
// src/commands/usage.ts
|
|
3575
|
-
var usageCommand2 = new
|
|
3797
|
+
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) => {
|
|
3576
3798
|
for (const [name, value] of [
|
|
3577
3799
|
["since", opts.since],
|
|
3578
3800
|
["until", opts.until]
|
|
@@ -3718,8 +3940,8 @@ function userRows(r) {
|
|
|
3718
3940
|
}
|
|
3719
3941
|
|
|
3720
3942
|
// src/commands/credit.ts
|
|
3721
|
-
import { Command as
|
|
3722
|
-
var creditCommand = new
|
|
3943
|
+
import { Command as Command60 } from "commander";
|
|
3944
|
+
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) => {
|
|
3723
3945
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
3724
3946
|
try {
|
|
3725
3947
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -3749,7 +3971,7 @@ function creditRow(b, me2) {
|
|
|
3749
3971
|
// src/commands/deploy/index.ts
|
|
3750
3972
|
import { readFile as readFile7 } from "fs/promises";
|
|
3751
3973
|
import { basename, resolve as resolve2 } from "path";
|
|
3752
|
-
import { Command as
|
|
3974
|
+
import { Command as Command61, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
3753
3975
|
|
|
3754
3976
|
// src/commands/deploy/config.ts
|
|
3755
3977
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -4078,7 +4300,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
4078
4300
|
var shipping = { ship, measure, waitForSsh };
|
|
4079
4301
|
|
|
4080
4302
|
// src/commands/deploy/index.ts
|
|
4081
|
-
var deployCommand = new
|
|
4303
|
+
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) => {
|
|
4082
4304
|
const dir = resolve2(dirArg ?? ".");
|
|
4083
4305
|
const pkg = await readPackageJson(dir);
|
|
4084
4306
|
const saved = await readConfig(dir);
|
|
@@ -4282,15 +4504,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
4282
4504
|
}
|
|
4283
4505
|
|
|
4284
4506
|
// src/commands/volume/index.ts
|
|
4285
|
-
import { Command as
|
|
4507
|
+
import { Command as Command67 } from "commander";
|
|
4286
4508
|
|
|
4287
4509
|
// src/commands/volume/attach.ts
|
|
4288
|
-
import { Command as
|
|
4510
|
+
import { Command as Command62 } from "commander";
|
|
4289
4511
|
function describeMount(machine, volume, box) {
|
|
4290
4512
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
4291
4513
|
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`;
|
|
4292
4514
|
}
|
|
4293
|
-
var attachCommand = new
|
|
4515
|
+
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) => {
|
|
4294
4516
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
4295
4517
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4296
4518
|
try {
|
|
@@ -4309,7 +4531,7 @@ var attachCommand = new Command58("attach").description("attach a volume to a bo
|
|
|
4309
4531
|
});
|
|
4310
4532
|
|
|
4311
4533
|
// src/commands/volume/create.ts
|
|
4312
|
-
import { Command as
|
|
4534
|
+
import { Command as Command63 } from "commander";
|
|
4313
4535
|
function parseGib2(text2) {
|
|
4314
4536
|
const mib = parseMib(text2);
|
|
4315
4537
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -4325,7 +4547,7 @@ function sizeProblem(answer) {
|
|
|
4325
4547
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
4326
4548
|
}
|
|
4327
4549
|
}
|
|
4328
|
-
var
|
|
4550
|
+
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) => {
|
|
4329
4551
|
const ask = interactive();
|
|
4330
4552
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
4331
4553
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -4358,8 +4580,8 @@ var createCommand2 = new Command59("create").alias("new").description("create a
|
|
|
4358
4580
|
});
|
|
4359
4581
|
|
|
4360
4582
|
// src/commands/volume/detach.ts
|
|
4361
|
-
import { Command as
|
|
4362
|
-
var detachCommand = new
|
|
4583
|
+
import { Command as Command64 } from "commander";
|
|
4584
|
+
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) => {
|
|
4363
4585
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
4364
4586
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4365
4587
|
try {
|
|
@@ -4384,8 +4606,8 @@ var detachCommand = new Command60("detach").description("detach a volume from a
|
|
|
4384
4606
|
});
|
|
4385
4607
|
|
|
4386
4608
|
// src/commands/volume/ls.ts
|
|
4387
|
-
import { Command as
|
|
4388
|
-
var
|
|
4609
|
+
import { Command as Command65 } from "commander";
|
|
4610
|
+
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) => {
|
|
4389
4611
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4390
4612
|
try {
|
|
4391
4613
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4416,8 +4638,8 @@ var lsCommand7 = new Command61("ls").alias("list").description("list volumes: si
|
|
|
4416
4638
|
});
|
|
4417
4639
|
|
|
4418
4640
|
// src/commands/volume/rm.ts
|
|
4419
|
-
import { Command as
|
|
4420
|
-
var rmCommand7 = new
|
|
4641
|
+
import { Command as Command66 } from "commander";
|
|
4642
|
+
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) => {
|
|
4421
4643
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
4422
4644
|
info("cancelled");
|
|
4423
4645
|
process.exitCode = 1;
|
|
@@ -4433,17 +4655,17 @@ var rmCommand7 = new Command62("rm").alias("remove").description("delete a volum
|
|
|
4433
4655
|
});
|
|
4434
4656
|
|
|
4435
4657
|
// src/commands/volume/index.ts
|
|
4436
|
-
var volumeCommand = new
|
|
4658
|
+
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);
|
|
4437
4659
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
4438
4660
|
|
|
4439
4661
|
// src/commands/env/index.ts
|
|
4440
|
-
import { Command as
|
|
4662
|
+
import { Command as Command71 } from "commander";
|
|
4441
4663
|
|
|
4442
4664
|
// src/commands/env/ls.ts
|
|
4443
|
-
import { Command as
|
|
4665
|
+
import { Command as Command68 } from "commander";
|
|
4444
4666
|
|
|
4445
4667
|
// src/commands/env/shared.ts
|
|
4446
|
-
function
|
|
4668
|
+
function requireCloud4(client) {
|
|
4447
4669
|
if (client.target.kind === "local") throw new KvboxError("kvbox env needs kvbox.sh: kvbox login first");
|
|
4448
4670
|
return client.target.org ?? client.target.user ?? "you";
|
|
4449
4671
|
}
|
|
@@ -4467,7 +4689,7 @@ function firstBootHint(box, name) {
|
|
|
4467
4689
|
}
|
|
4468
4690
|
|
|
4469
4691
|
// src/commands/env/ls.ts
|
|
4470
|
-
var
|
|
4692
|
+
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) => {
|
|
4471
4693
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4472
4694
|
try {
|
|
4473
4695
|
if (opts.box !== void 0) {
|
|
@@ -4489,7 +4711,7 @@ var lsCommand8 = new Command64("ls").alias("list").description("list the variabl
|
|
|
4489
4711
|
table([...own.vars.map((v) => row(v, "box")), ...inherited.map((v) => row(v, color.dim(slug)))]);
|
|
4490
4712
|
return;
|
|
4491
4713
|
}
|
|
4492
|
-
const owner =
|
|
4714
|
+
const owner = requireCloud4(client);
|
|
4493
4715
|
const vars = await client.listEnv();
|
|
4494
4716
|
if (opts.json) {
|
|
4495
4717
|
json(vars);
|
|
@@ -4506,12 +4728,12 @@ var lsCommand8 = new Command64("ls").alias("list").description("list the variabl
|
|
|
4506
4728
|
});
|
|
4507
4729
|
|
|
4508
4730
|
// src/commands/env/rm.ts
|
|
4509
|
-
import { Command as
|
|
4510
|
-
var rmCommand8 = new
|
|
4731
|
+
import { Command as Command69 } from "commander";
|
|
4732
|
+
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) => {
|
|
4511
4733
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4512
4734
|
try {
|
|
4513
4735
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4514
|
-
const owner = target === void 0 ?
|
|
4736
|
+
const owner = target === void 0 ? requireCloud4(client) : `box ${target.ref}`;
|
|
4515
4737
|
if (!await confirm(`Remove ${names.join(", ")} from ${owner}'s variables?`, opts.yes ?? false)) {
|
|
4516
4738
|
info("cancelled");
|
|
4517
4739
|
process.exitCode = 1;
|
|
@@ -4544,11 +4766,11 @@ var rmCommand8 = new Command65("rm").alias("remove").description("remove variabl
|
|
|
4544
4766
|
});
|
|
4545
4767
|
|
|
4546
4768
|
// src/commands/env/set.ts
|
|
4547
|
-
import { Command as
|
|
4548
|
-
var setCommand2 = new
|
|
4769
|
+
import { Command as Command70 } from "commander";
|
|
4770
|
+
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) => {
|
|
4549
4771
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4550
4772
|
try {
|
|
4551
|
-
const owner = opts.box === void 0 ?
|
|
4773
|
+
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
4552
4774
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4553
4775
|
const ask = interactive();
|
|
4554
4776
|
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)");
|
|
@@ -4582,17 +4804,17 @@ var setCommand2 = new Command66("set").description("add or change a variable; bo
|
|
|
4582
4804
|
});
|
|
4583
4805
|
|
|
4584
4806
|
// src/commands/env/index.ts
|
|
4585
|
-
var envCommand = new
|
|
4807
|
+
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);
|
|
4586
4808
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
4587
4809
|
|
|
4588
4810
|
// src/commands/domain/index.ts
|
|
4589
|
-
import { Command as
|
|
4811
|
+
import { Command as Command75 } from "commander";
|
|
4590
4812
|
|
|
4591
4813
|
// src/commands/domain/add.ts
|
|
4592
|
-
import { Command as
|
|
4814
|
+
import { Command as Command72 } from "commander";
|
|
4593
4815
|
|
|
4594
4816
|
// src/commands/domain/shared.ts
|
|
4595
|
-
function
|
|
4817
|
+
function requireCloud5(client) {
|
|
4596
4818
|
if (client.target.kind !== "cloud") throw new KvboxError("custom domains need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
4597
4819
|
}
|
|
4598
4820
|
var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.box}` : d.box;
|
|
@@ -4609,12 +4831,12 @@ function hostIn(name, zone) {
|
|
|
4609
4831
|
}
|
|
4610
4832
|
|
|
4611
4833
|
// src/commands/domain/add.ts
|
|
4612
|
-
var addCommand3 = new
|
|
4834
|
+
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) => {
|
|
4613
4835
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
4614
4836
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
4615
4837
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4616
4838
|
try {
|
|
4617
|
-
|
|
4839
|
+
requireCloud5(client);
|
|
4618
4840
|
const user = me(client);
|
|
4619
4841
|
const box = displayName(await findBox(client, name), user);
|
|
4620
4842
|
const d = await spin(`adding ${domain}\u2026`, client.addDomain(box, { domain, ...port !== void 0 ? { port } : {} }));
|
|
@@ -4645,11 +4867,11 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
4645
4867
|
});
|
|
4646
4868
|
|
|
4647
4869
|
// src/commands/domain/ls.ts
|
|
4648
|
-
import { Command as
|
|
4649
|
-
var
|
|
4870
|
+
import { Command as Command73 } from "commander";
|
|
4871
|
+
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) => {
|
|
4650
4872
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4651
4873
|
try {
|
|
4652
|
-
|
|
4874
|
+
requireCloud5(client);
|
|
4653
4875
|
const user = me(client);
|
|
4654
4876
|
const domains = await client.listDomains();
|
|
4655
4877
|
if (opts.json) {
|
|
@@ -4675,12 +4897,12 @@ var lsCommand9 = new Command69("ls").alias("list").description("list your custom
|
|
|
4675
4897
|
});
|
|
4676
4898
|
|
|
4677
4899
|
// src/commands/domain/rm.ts
|
|
4678
|
-
import { Command as
|
|
4679
|
-
var rmCommand9 = new
|
|
4900
|
+
import { Command as Command74 } from "commander";
|
|
4901
|
+
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) => {
|
|
4680
4902
|
const domain = domainArg.trim().toLowerCase();
|
|
4681
4903
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4682
4904
|
try {
|
|
4683
|
-
|
|
4905
|
+
requireCloud5(client);
|
|
4684
4906
|
const found = (await client.listDomains()).find((d) => d.domain === domain);
|
|
4685
4907
|
if (!found) throw new KvboxError(`domain ${domain}: not found (kvbox domain ls)`);
|
|
4686
4908
|
const box = boxOf2(found, me(client));
|
|
@@ -4697,12 +4919,12 @@ var rmCommand9 = new Command70("rm").alias("remove").description("stop serving a
|
|
|
4697
4919
|
});
|
|
4698
4920
|
|
|
4699
4921
|
// src/commands/domain/index.ts
|
|
4700
|
-
var domainCommand = new
|
|
4922
|
+
var domainCommand = new Command75("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand10).addCommand(rmCommand9);
|
|
4701
4923
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4702
4924
|
|
|
4703
4925
|
// src/program.ts
|
|
4704
4926
|
function buildProgram() {
|
|
4705
|
-
const program = new
|
|
4927
|
+
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();
|
|
4706
4928
|
program.addCommand(vmCommand);
|
|
4707
4929
|
program.addCommand(snapshotsCommand);
|
|
4708
4930
|
program.addCommand(volumeCommand);
|