@kvbox/server 0.6.9 → 0.6.10
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-server.js +57 -7
- package/dist/kvbox-server.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox-server.js
CHANGED
|
@@ -74,6 +74,8 @@ function paths(home = kvboxHome()) {
|
|
|
74
74
|
},
|
|
75
75
|
assets: join(home, "assets"),
|
|
76
76
|
kernel: join(home, "assets", "vmlinux"),
|
|
77
|
+
/** A kernel an image asks for by name in its image.json (`"kernel": "android"`): assets/vmlinux-<name>, put there by install-server.sh. */
|
|
78
|
+
namedKernel: (name) => join(home, "assets", `vmlinux-${name}`),
|
|
77
79
|
/** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
|
|
78
80
|
rootfs: join(home, "assets", "rootfs.ext4"),
|
|
79
81
|
baseImage: (version) => join(home, "assets", `rootfs-${version}.ext4`),
|
|
@@ -211,7 +213,12 @@ var PricingSchema = z.object({
|
|
|
211
213
|
storageGibHour: z.number().nonnegative().default(0),
|
|
212
214
|
storageIncludedGib: z.number().int().nonnegative().default(0),
|
|
213
215
|
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
214
|
-
cronHour: z.number().nonnegative().default(0)
|
|
216
|
+
cronHour: z.number().nonnegative().default(0),
|
|
217
|
+
/**
|
|
218
|
+
* One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
|
|
219
|
+
* costs a flat price…"); a failed one and a scheduled one cost nothing. A price list from before it charges nothing.
|
|
220
|
+
*/
|
|
221
|
+
backup: z.number().nonnegative().default(0)
|
|
215
222
|
});
|
|
216
223
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z.number().nonnegative() });
|
|
217
224
|
var HOUR_MS = 36e5;
|
|
@@ -926,7 +933,7 @@ async function boot(spec, disks, tap, cfg, p) {
|
|
|
926
933
|
const pid = await spawnFirecracker(spec, cfg, p);
|
|
927
934
|
try {
|
|
928
935
|
await withClient(spec, p, async (fc) => {
|
|
929
|
-
await fc.bootSource(
|
|
936
|
+
await fc.bootSource(disks.kernel, bootArgs(spec.name, spec.ip, cfg, disks.pubkeyB64));
|
|
930
937
|
await fc.rootDrive(disks.root);
|
|
931
938
|
await fc.overlayDrive(OVERLAY_REL);
|
|
932
939
|
for (const v of disks.volumes) await fc.volumeDrive(v.id, v.path);
|
|
@@ -1650,7 +1657,13 @@ var ImageManifestSchema = z4.object({
|
|
|
1650
1657
|
* Scripts in the box the host may run by name through kvbox-agent (#173): `status`, `password`, …
|
|
1651
1658
|
* The host knows the names only; what each does and answers is the image's.
|
|
1652
1659
|
*/
|
|
1653
|
-
scripts: z4.record(z4.string(), z4.string().startsWith("/")).optional()
|
|
1660
|
+
scripts: z4.record(z4.string(), z4.string().startsWith("/")).optional(),
|
|
1661
|
+
/**
|
|
1662
|
+
* The kernel a box of this image boots, by name (`android`: assets/vmlinux-android), instead of the
|
|
1663
|
+
* host's one. Lets one image have what the others must not (binder for Redroid) without changing
|
|
1664
|
+
* every box's kernel. Only a cold boot reads it: a restored box keeps the kernel in its memory image.
|
|
1665
|
+
*/
|
|
1666
|
+
kernel: z4.string().regex(IMAGE_RE, "a kernel name like android").optional()
|
|
1654
1667
|
});
|
|
1655
1668
|
var manifests = /* @__PURE__ */ new Map();
|
|
1656
1669
|
async function imageManifest(file) {
|
|
@@ -1668,6 +1681,12 @@ async function imageManifest(file) {
|
|
|
1668
1681
|
manifests.set(file, manifest);
|
|
1669
1682
|
return manifest;
|
|
1670
1683
|
}
|
|
1684
|
+
function kernelFor(manifest, cfg, p) {
|
|
1685
|
+
if (manifest.kernel === void 0) return cfg.kernel;
|
|
1686
|
+
const file = p.namedKernel(manifest.kernel);
|
|
1687
|
+
if (!existsSync4(file)) throw new KvboxError(`this image boots the ${manifest.kernel} kernel, which this host does not have at ${file}; install-server.sh --update installs it`);
|
|
1688
|
+
return file;
|
|
1689
|
+
}
|
|
1671
1690
|
function expand(text, vars) {
|
|
1672
1691
|
return text.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_, name) => vars.get(name) ?? "");
|
|
1673
1692
|
}
|
|
@@ -1831,6 +1850,12 @@ var BackupSchema = z5.object({
|
|
|
1831
1850
|
createdAt: z5.string(),
|
|
1832
1851
|
finishedAt: z5.string().nullable()
|
|
1833
1852
|
});
|
|
1853
|
+
var BackupLimitSchema = z5.object({
|
|
1854
|
+
perDay: z5.number().int(),
|
|
1855
|
+
used: z5.number().int(),
|
|
1856
|
+
nextAt: z5.string().nullable()
|
|
1857
|
+
});
|
|
1858
|
+
var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner: z5.string(), name: z5.string() });
|
|
1834
1859
|
var HostBackupRequest = z5.object({ id: z5.string(), key: z5.string() });
|
|
1835
1860
|
var HostBackupManifestSchema = z5.object({
|
|
1836
1861
|
id: z5.string(),
|
|
@@ -1873,6 +1898,16 @@ var VolumeBackupSchema = z5.object({
|
|
|
1873
1898
|
createdAt: z5.string(),
|
|
1874
1899
|
finishedAt: z5.string().nullable()
|
|
1875
1900
|
});
|
|
1901
|
+
var BackupScheduleSchema = z5.object({
|
|
1902
|
+
enabled: z5.boolean(),
|
|
1903
|
+
/** 0-23, UTC. Kept while it is off, so turning it on again keeps the hour. */
|
|
1904
|
+
hour: z5.number().int().min(0).max(23),
|
|
1905
|
+
nextAt: z5.string().nullable(),
|
|
1906
|
+
lastAt: z5.string().nullable(),
|
|
1907
|
+
lastBackup: z5.string().nullable(),
|
|
1908
|
+
lastError: z5.string().nullable()
|
|
1909
|
+
});
|
|
1910
|
+
var SetBackupScheduleRequest = z5.object({ enabled: z5.boolean().optional(), hour: z5.number().int().min(0).max(23).optional() });
|
|
1876
1911
|
var HostVolumeBackupManifestSchema = z5.object({ id: z5.string(), sizeBytes: z5.number().int(), chunks: z5.array(z5.string().nullable()) });
|
|
1877
1912
|
var HostVolumeRestoreRequest = z5.object({
|
|
1878
1913
|
id: z5.string(),
|
|
@@ -2402,6 +2437,16 @@ var CronUsageSchema = z5.object({
|
|
|
2402
2437
|
/** When it was made. */
|
|
2403
2438
|
historyFrom: z5.string().nullable()
|
|
2404
2439
|
});
|
|
2440
|
+
var BackupUsageSchema = z5.object({
|
|
2441
|
+
id: z5.string(),
|
|
2442
|
+
kind: z5.string(),
|
|
2443
|
+
name: z5.string(),
|
|
2444
|
+
owner: z5.string(),
|
|
2445
|
+
ownerKind: z5.enum(["user", "org"]).optional(),
|
|
2446
|
+
/** How many paid backups turned ready in the window. */
|
|
2447
|
+
count: z5.number().int(),
|
|
2448
|
+
cost: z5.object({ amount: z5.number(), currency: z5.string() })
|
|
2449
|
+
});
|
|
2405
2450
|
var UsageDayItemSchema = z5.object({
|
|
2406
2451
|
id: z5.string(),
|
|
2407
2452
|
name: z5.string(),
|
|
@@ -2422,7 +2467,9 @@ var UsageDaySchema = z5.object({
|
|
|
2422
2467
|
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
2423
2468
|
storage: z5.array(UsageDayItemSchema).optional(),
|
|
2424
2469
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
2425
|
-
cron: z5.array(UsageDayItemSchema).optional()
|
|
2470
|
+
cron: z5.array(UsageDayItemSchema).optional(),
|
|
2471
|
+
/** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
|
|
2472
|
+
backups: z5.array(UsageDayItemSchema).optional()
|
|
2426
2473
|
});
|
|
2427
2474
|
var UsageReportSchema = z5.object({
|
|
2428
2475
|
window: z5.object({ from: z5.string(), to: z5.string() }),
|
|
@@ -2437,6 +2484,8 @@ var UsageReportSchema = z5.object({
|
|
|
2437
2484
|
storage: z5.array(VolumeUsageSchema).optional(),
|
|
2438
2485
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
2439
2486
|
cron: z5.array(CronUsageSchema).optional(),
|
|
2487
|
+
/** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
|
|
2488
|
+
backups: z5.array(BackupUsageSchema).optional(),
|
|
2440
2489
|
/** With `?by=day` only, oldest day first. */
|
|
2441
2490
|
days: z5.array(UsageDaySchema).optional(),
|
|
2442
2491
|
totals: z5.object({
|
|
@@ -2446,7 +2495,7 @@ var UsageReportSchema = z5.object({
|
|
|
2446
2495
|
diskGibHours: z5.number(),
|
|
2447
2496
|
volumeHours: z5.number().optional(),
|
|
2448
2497
|
volumeGibHours: z5.number().optional(),
|
|
2449
|
-
/** Boxes, volumes, object storage
|
|
2498
|
+
/** Boxes, volumes, object storage, cron services and paid backups together. */
|
|
2450
2499
|
cost: z5.object({ amount: z5.number(), currency: z5.string() }).optional()
|
|
2451
2500
|
})
|
|
2452
2501
|
});
|
|
@@ -3750,8 +3799,9 @@ async function getMachine(ref, p = paths()) {
|
|
|
3750
3799
|
// src/core/machines/boot.ts
|
|
3751
3800
|
async function launch(spec, nic, cfg, pubkeyB64, p) {
|
|
3752
3801
|
const root = imageFileFor(spec, p);
|
|
3802
|
+
const kernel = kernelFor(await imageManifest(root), cfg, p);
|
|
3753
3803
|
const volumes = (await placeVolumeDrives(spec, p)).map((v) => ({ id: volumeDriveId(v.name), path: volumeDriveRel(v.name) }));
|
|
3754
|
-
return driver().vm.boot(spec, { root, volumes, pubkeyB64 }, nic, cfg, p);
|
|
3804
|
+
return driver().vm.boot(spec, { kernel, root, volumes, pubkeyB64 }, nic, cfg, p);
|
|
3755
3805
|
}
|
|
3756
3806
|
async function loadSnapshot(spec, image, nic, cfg, p) {
|
|
3757
3807
|
return driver().vm.restore(spec, { vmstate: image.vmstate, mem: image.mem }, nic, cfg, p);
|
|
@@ -6362,7 +6412,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
6362
6412
|
}
|
|
6363
6413
|
|
|
6364
6414
|
// src/version.ts
|
|
6365
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
6415
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.10" : void 0);
|
|
6366
6416
|
|
|
6367
6417
|
// src/caller.ts
|
|
6368
6418
|
import { createHash as createHash3, timingSafeEqual } from "node:crypto";
|