gigadrive 2.14.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +148 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +148 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { Effect as Effect29, Layer, LogLevel, Logger } from "effect";
|
|
|
9
9
|
// package.json
|
|
10
10
|
var package_default = {
|
|
11
11
|
name: "gigadrive",
|
|
12
|
-
version: "2.
|
|
12
|
+
version: "2.15.0",
|
|
13
13
|
repository: {
|
|
14
14
|
type: "git",
|
|
15
15
|
url: "https://github.com/Gigadrive/sdk.git",
|
|
@@ -3098,6 +3098,17 @@ var formatWebhookTable = (webhooks) => formatTable([
|
|
|
3098
3098
|
webhook.id
|
|
3099
3099
|
])
|
|
3100
3100
|
]);
|
|
3101
|
+
var formatVolumeTable = (volumes) => formatTable([
|
|
3102
|
+
["NAME", "SIZE", "STORED", "STATUS", "LAST SAVED", "ID"],
|
|
3103
|
+
...volumes.map((volume) => [
|
|
3104
|
+
volume.name,
|
|
3105
|
+
`${String(volume.sizeMb)} MiB`,
|
|
3106
|
+
volume.storedBytes === null ? "-" : formatBytes(volume.storedBytes),
|
|
3107
|
+
volume.attachedMicrovmId ? `${volume.status} (${volume.attachedMicrovmId})` : volume.status,
|
|
3108
|
+
volume.lastSaveError ? `failed: ${volume.lastSaveError}` : volume.lastSavedAt ?? "never",
|
|
3109
|
+
volume.id
|
|
3110
|
+
])
|
|
3111
|
+
]);
|
|
3101
3112
|
var formatDeliveryTable = (deliveries) => formatTable([
|
|
3102
3113
|
["CREATED", "EVENT", "STATUS", "ATTEMPTS", "RESPONSE", "MICROVM"],
|
|
3103
3114
|
...deliveries.map((delivery) => [
|
|
@@ -3343,6 +3354,25 @@ var withClient = (run) => Effect22.gen(function* () {
|
|
|
3343
3354
|
return yield* Effect22.tryPromise({ try: () => run(client), catch: toApiRequestError });
|
|
3344
3355
|
});
|
|
3345
3356
|
var signalOnInterrupt = (signal) => (command, exit) => Exit.isInterrupted(exit) ? Effect22.tryPromise(() => command.kill(signal)).pipe(Effect22.timeout("2 seconds"), Effect22.ignore) : Effect22.void;
|
|
3357
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3358
|
+
var parseVolumeFlags = (values) => Effect22.gen(function* () {
|
|
3359
|
+
if (values.length > 4) {
|
|
3360
|
+
return yield* new InvalidMicroVmOptionsError({ message: "--volume takes at most 4 volumes." });
|
|
3361
|
+
}
|
|
3362
|
+
const volumes = [];
|
|
3363
|
+
for (const value of values) {
|
|
3364
|
+
const separator = value.indexOf(":");
|
|
3365
|
+
const volumeId = separator > 0 ? value.slice(0, separator) : "";
|
|
3366
|
+
const mountPath = separator > 0 ? value.slice(separator + 1) : "";
|
|
3367
|
+
if (volumeId === "" || !mountPath.startsWith("/")) {
|
|
3368
|
+
return yield* new InvalidMicroVmOptionsError({
|
|
3369
|
+
message: `--volume must be VOLUME:PATH with an absolute path, such as cache:/cache (got ${value}).`
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
volumes.push({ volumeId, mountPath });
|
|
3373
|
+
}
|
|
3374
|
+
return volumes;
|
|
3375
|
+
});
|
|
3346
3376
|
var checkEgressFlags = (denyEgress, allowEgress) => Effect22.gen(function* () {
|
|
3347
3377
|
if (denyEgress && allowEgress.length > 0) {
|
|
3348
3378
|
return yield* new InvalidMicroVmOptionsError({
|
|
@@ -3373,6 +3403,10 @@ var createInput = (flags) => Effect22.gen(function* () {
|
|
|
3373
3403
|
if (badPort !== void 0) {
|
|
3374
3404
|
return yield* new InvalidMicroVmOptionsError({ message: `--port must be between 1 and 65535 (got ${badPort}).` });
|
|
3375
3405
|
}
|
|
3406
|
+
const volumes = yield* parseVolumeFlags(flags.volumes);
|
|
3407
|
+
if (volumes.length > 0 && flags.pauseOnTimeout) {
|
|
3408
|
+
return yield* new InvalidMicroVmOptionsError({ message: "--volume cannot be combined with --pause-on-timeout." });
|
|
3409
|
+
}
|
|
3376
3410
|
const applicationId = yield* resolveApplicationId(flags.app);
|
|
3377
3411
|
const input = {
|
|
3378
3412
|
...applicationId ? { applicationId } : {},
|
|
@@ -3389,6 +3423,7 @@ var createInput = (flags) => Effect22.gen(function* () {
|
|
|
3389
3423
|
...flags.ports.length > 0 ? { ports: [...flags.ports] } : {},
|
|
3390
3424
|
...env ? { env } : {},
|
|
3391
3425
|
...metadata ? { metadata } : {},
|
|
3426
|
+
...volumes.length > 0 ? { volumes } : {},
|
|
3392
3427
|
...flags.denyEgress || flags.privatePreviews || flags.allowEgress.length > 0 ? {
|
|
3393
3428
|
network: {
|
|
3394
3429
|
egress: flags.denyEgress ? "deny" : "allow",
|
|
@@ -3402,7 +3437,26 @@ var createInput = (flags) => Effect22.gen(function* () {
|
|
|
3402
3437
|
});
|
|
3403
3438
|
var createMicroVm = (flags) => Effect22.gen(function* () {
|
|
3404
3439
|
const apiClient = yield* ApiClientService;
|
|
3405
|
-
const
|
|
3440
|
+
const parsed = yield* createInput(flags);
|
|
3441
|
+
const named = (parsed.volumes ?? []).filter((volume) => !UUID.test(volume.volumeId));
|
|
3442
|
+
const known = named.length > 0 ? yield* apiClient.request(
|
|
3443
|
+
(client) => client.microvms.volumes.list({ ...parsed.applicationId ? { applicationId: parsed.applicationId } : {} })
|
|
3444
|
+
) : [];
|
|
3445
|
+
const volumes = [];
|
|
3446
|
+
for (const volume of parsed.volumes ?? []) {
|
|
3447
|
+
if (UUID.test(volume.volumeId)) {
|
|
3448
|
+
volumes.push(volume);
|
|
3449
|
+
continue;
|
|
3450
|
+
}
|
|
3451
|
+
const match = known.find((entry) => entry.name === volume.volumeId);
|
|
3452
|
+
if (match === void 0) {
|
|
3453
|
+
return yield* new InvalidMicroVmOptionsError({
|
|
3454
|
+
message: `No volume is named ${volume.volumeId}. Create it with "gigadrive microvms volumes create ${volume.volumeId}".`
|
|
3455
|
+
});
|
|
3456
|
+
}
|
|
3457
|
+
volumes.push({ volumeId: match.id, mountPath: volume.mountPath });
|
|
3458
|
+
}
|
|
3459
|
+
const input = volumes.length > 0 ? { ...parsed, volumes } : parsed;
|
|
3406
3460
|
if (!flags.json) yield* Console12.error(`Creating a microVM from ${input.image ?? "node22"}...`);
|
|
3407
3461
|
const vm = yield* apiClient.request((client) => client.microvms.create(input));
|
|
3408
3462
|
if (flags.json) {
|
|
@@ -3473,6 +3527,13 @@ var createCommand = Command12.make(
|
|
|
3473
3527
|
"Resume the paused microVM when a command, file call or public preview request reaches it"
|
|
3474
3528
|
)
|
|
3475
3529
|
),
|
|
3530
|
+
volumes: Options7.text("volume").pipe(
|
|
3531
|
+
Options7.withAlias("v"),
|
|
3532
|
+
Options7.withDescription(
|
|
3533
|
+
"Attach a volume as VOLUME:PATH, by ID or name, such as cache:/cache (repeatable, up to 4; saved when the microVM stops)"
|
|
3534
|
+
),
|
|
3535
|
+
Options7.repeated
|
|
3536
|
+
),
|
|
3476
3537
|
region: Options7.text("region").pipe(Options7.withDescription("Region to place the microVM in"), Options7.optional),
|
|
3477
3538
|
json: jsonOption2
|
|
3478
3539
|
},
|
|
@@ -3955,6 +4016,90 @@ var imagesCommand = Command12.make("images", {}, () => Effect22.void).pipe(
|
|
|
3955
4016
|
Command12.withDescription("Built-in and custom microVM images"),
|
|
3956
4017
|
Command12.withSubcommands([imagesListCommand, imagesCreateCommand, imagesRemoveCommand])
|
|
3957
4018
|
);
|
|
4019
|
+
var volumeIdArg = Args5.text({ name: "volume-id" }).pipe(Args5.withDescription("The volume ID"));
|
|
4020
|
+
var volumesListCommand = Command12.make(
|
|
4021
|
+
"ls",
|
|
4022
|
+
{ app: appOption6, json: jsonOption2 },
|
|
4023
|
+
({ app, json }) => Effect22.gen(function* () {
|
|
4024
|
+
const apiClient = yield* ApiClientService;
|
|
4025
|
+
const applicationId = yield* resolveApplicationId(app);
|
|
4026
|
+
const volumes = yield* apiClient.request((client) => client.microvms.volumes.list({ applicationId }));
|
|
4027
|
+
if (json) return yield* Console12.log(JSON.stringify(volumes, null, 2));
|
|
4028
|
+
if (volumes.length === 0)
|
|
4029
|
+
return yield* Console12.log('No volumes yet. Create one with "gigadrive microvms volumes create <name>".');
|
|
4030
|
+
for (const line of formatVolumeTable(volumes)) yield* Console12.log(line);
|
|
4031
|
+
}).pipe(reportErrors2("list volumes"))
|
|
4032
|
+
).pipe(Command12.withDescription("List the application's volumes"));
|
|
4033
|
+
var createVolume = (flags) => Effect22.gen(function* () {
|
|
4034
|
+
const apiClient = yield* ApiClientService;
|
|
4035
|
+
const applicationId = yield* resolveApplicationId(flags.app);
|
|
4036
|
+
const volume = yield* apiClient.request(
|
|
4037
|
+
(client) => client.microvms.volumes.create({
|
|
4038
|
+
name: flags.name,
|
|
4039
|
+
...Option14.match(flags.size, { onNone: () => ({}), onSome: (sizeMb) => ({ sizeMb }) }),
|
|
4040
|
+
...applicationId ? { applicationId } : {}
|
|
4041
|
+
})
|
|
4042
|
+
);
|
|
4043
|
+
if (flags.json) {
|
|
4044
|
+
yield* Console12.log(JSON.stringify(volume, null, 2));
|
|
4045
|
+
} else {
|
|
4046
|
+
yield* Console12.log(`Created volume ${volume.name} (${String(volume.sizeMb)} MiB, ${volume.id}).`);
|
|
4047
|
+
yield* Console12.log(`Attach it: gigadrive microvms create --volume ${volume.name}:/data`);
|
|
4048
|
+
}
|
|
4049
|
+
return volume;
|
|
4050
|
+
});
|
|
4051
|
+
var volumesCreateCommand = Command12.make(
|
|
4052
|
+
"create",
|
|
4053
|
+
{
|
|
4054
|
+
name: Args5.text({ name: "name" }).pipe(
|
|
4055
|
+
Args5.withDescription("Lowercase letters, digits and -, unique per application")
|
|
4056
|
+
),
|
|
4057
|
+
size: Options7.integer("size").pipe(
|
|
4058
|
+
Options7.withDescription("Size in MiB, 1024 to 51200 (default: 10240)"),
|
|
4059
|
+
Options7.optional
|
|
4060
|
+
),
|
|
4061
|
+
app: appOption6,
|
|
4062
|
+
json: jsonOption2
|
|
4063
|
+
},
|
|
4064
|
+
(flags) => createVolume(flags).pipe(Effect22.asVoid, reportErrors2("create the volume"))
|
|
4065
|
+
).pipe(Command12.withDescription("Create an empty volume"));
|
|
4066
|
+
var volumesRenameCommand = Command12.make(
|
|
4067
|
+
"rename",
|
|
4068
|
+
{ volumeId: volumeIdArg, name: Args5.text({ name: "name" }).pipe(Args5.withDescription("The new name")) },
|
|
4069
|
+
({ volumeId, name }) => Effect22.gen(function* () {
|
|
4070
|
+
const apiClient = yield* ApiClientService;
|
|
4071
|
+
const volume = yield* apiClient.request((client) => client.microvms.volumes.rename(volumeId, name));
|
|
4072
|
+
yield* Console12.log(`Renamed the volume to ${volume.name}.`);
|
|
4073
|
+
}).pipe(reportErrors2("rename the volume"))
|
|
4074
|
+
).pipe(Command12.withDescription("Rename a volume"));
|
|
4075
|
+
var volumesSaveCommand = Command12.make(
|
|
4076
|
+
"save",
|
|
4077
|
+
{ microvmId: Args5.text({ name: "microvm-id" }).pipe(Args5.withDescription("A running microVM with volumes")) },
|
|
4078
|
+
({ microvmId }) => Effect22.gen(function* () {
|
|
4079
|
+
const apiClient = yield* ApiClientService;
|
|
4080
|
+
yield* apiClient.request((client) => client.microvms.saveVolumes(microvmId));
|
|
4081
|
+
yield* Console12.log(`Saved the volumes of ${microvmId}.`);
|
|
4082
|
+
}).pipe(reportErrors2("save the volumes"))
|
|
4083
|
+
).pipe(Command12.withDescription("Save a running microVM's volumes without stopping it"));
|
|
4084
|
+
var volumesRemoveCommand = Command12.make(
|
|
4085
|
+
"rm",
|
|
4086
|
+
{ volumeId: volumeIdArg },
|
|
4087
|
+
({ volumeId }) => Effect22.gen(function* () {
|
|
4088
|
+
const apiClient = yield* ApiClientService;
|
|
4089
|
+
yield* apiClient.request((client) => client.microvms.volumes.delete(volumeId));
|
|
4090
|
+
yield* Console12.log(`Deleted volume ${volumeId}.`);
|
|
4091
|
+
}).pipe(reportErrors2("delete the volume"))
|
|
4092
|
+
).pipe(Command12.withDescription("Delete a volume and its contents (it must not be attached)"));
|
|
4093
|
+
var volumesCommand = Command12.make("volumes", {}, () => Effect22.void).pipe(
|
|
4094
|
+
Command12.withDescription("Persistent filesystems that outlive the microVMs they are attached to"),
|
|
4095
|
+
Command12.withSubcommands([
|
|
4096
|
+
volumesListCommand,
|
|
4097
|
+
volumesCreateCommand,
|
|
4098
|
+
volumesRenameCommand,
|
|
4099
|
+
volumesSaveCommand,
|
|
4100
|
+
volumesRemoveCommand
|
|
4101
|
+
])
|
|
4102
|
+
);
|
|
3958
4103
|
var WEBHOOK_EVENTS = [
|
|
3959
4104
|
"microvm.created",
|
|
3960
4105
|
"microvm.running",
|
|
@@ -4083,6 +4228,7 @@ var SUBCOMMANDS = [
|
|
|
4083
4228
|
extendCommand,
|
|
4084
4229
|
networkCommand,
|
|
4085
4230
|
imagesCommand,
|
|
4231
|
+
volumesCommand,
|
|
4086
4232
|
webhooksCommand
|
|
4087
4233
|
];
|
|
4088
4234
|
var microvmsCommand = Command12.make("microvms", {}, () => Effect22.void).pipe(
|