gigadrive 2.10.1 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,7 @@ gigadrive vm cp vm:<id>:/app/dist ./dist # and out
36
36
  gigadrive vm shell <id> # interactive terminal
37
37
  gigadrive vm ls # running microVMs (--all includes stopped)
38
38
  gigadrive vm extend <id> 1h # stop it one hour from now
39
+ gigadrive vm network <id> --deny-egress # cut its internet while it runs
39
40
  gigadrive vm stop <id> && gigadrive vm rm <id>
40
41
  gigadrive vm images create py-ml --from python:3.13 --wait # custom images (or --dockerfile ./Dockerfile)
41
42
  ```
package/dist/index.cjs CHANGED
@@ -32,7 +32,7 @@ var import_effect31 = require("effect");
32
32
  // package.json
33
33
  var package_default = {
34
34
  name: "gigadrive",
35
- version: "2.10.1",
35
+ version: "2.12.0",
36
36
  repository: {
37
37
  type: "git",
38
38
  url: "https://github.com/Gigadrive/sdk.git",
@@ -3072,7 +3072,7 @@ var describeMicroVm = (vm, now = Date.now()) => {
3072
3072
  `Image: ${vm.image.name}`,
3073
3073
  `Size: ${vm.vcpus} vCPU, ${formatMemory(vm.memoryMb)} memory, ${formatMemory(vm.diskMb)} disk`,
3074
3074
  `Region: ${vm.region}`,
3075
- `Network: ${vm.network.egress === "deny" ? "outbound traffic blocked" : vm.network.allow && vm.network.allow.length > 0 ? `only ${vm.network.allow.join(", ")} (and DNS)` : "internet access"}`,
3075
+ `Network: ${vm.network.egress === "deny" ? "outbound traffic blocked" : vm.network.allow && vm.network.allow.length > 0 ? `only ${vm.network.allow.join(", ")}` : "internet access"}`,
3076
3076
  `Previews: ${vm.network.previews === "private" ? "private (preview token required)" : "public"}`,
3077
3077
  `Application: ${vm.applicationId}`,
3078
3078
  `Created: ${vm.createdAt}`
@@ -3333,27 +3333,32 @@ var withClient = (run) => import_effect24.Effect.gen(function* () {
3333
3333
  return yield* import_effect24.Effect.tryPromise({ try: () => run(client), catch: toApiRequestError });
3334
3334
  });
3335
3335
  var signalOnInterrupt = (signal) => (command, exit) => import_effect24.Exit.isInterrupted(exit) ? import_effect24.Effect.tryPromise(() => command.kill(signal)).pipe(import_effect24.Effect.timeout("2 seconds"), import_effect24.Effect.ignore) : import_effect24.Effect.void;
3336
- var createInput = (flags) => import_effect24.Effect.gen(function* () {
3337
- const env = yield* keyValues("--env", flags.env);
3338
- const metadata = yield* keyValues("--metadata", flags.metadata);
3339
- const timeoutMs = yield* import_effect24.Option.match(flags.timeout, {
3340
- onNone: () => import_effect24.Effect.succeed(void 0),
3341
- onSome: (text) => parseLifetime("--timeout", text)
3342
- });
3343
- if (flags.denyEgress && flags.allowEgress.length > 0) {
3336
+ var checkEgressFlags = (denyEgress, allowEgress) => import_effect24.Effect.gen(function* () {
3337
+ if (denyEgress && allowEgress.length > 0) {
3344
3338
  return yield* new InvalidMicroVmOptionsError({
3345
3339
  message: "--allow-egress cannot be combined with --deny-egress."
3346
3340
  });
3347
3341
  }
3348
- if (flags.allowEgress.length > 32) {
3349
- return yield* new InvalidMicroVmOptionsError({ message: "--allow-egress takes at most 32 networks." });
3342
+ if (allowEgress.length > 32) {
3343
+ return yield* new InvalidMicroVmOptionsError({ message: "--allow-egress takes at most 32 entries." });
3350
3344
  }
3351
- const badNetwork = flags.allowEgress.find((network) => !/^\d{1,3}(\.\d{1,3}){3}\/\d{1,2}$/.test(network.trim()));
3352
- if (badNetwork !== void 0) {
3345
+ const network = /^\d{1,3}(\.\d{1,3}){3}\/\d{1,2}$/;
3346
+ const domain = /^(\*\.)?([a-z0-9-]+\.)+[a-z0-9-]*[a-z][a-z0-9-]*\.?$/i;
3347
+ const badEntry = allowEgress.find((entry) => !network.test(entry.trim()) && !domain.test(entry.trim()));
3348
+ if (badEntry !== void 0) {
3353
3349
  return yield* new InvalidMicroVmOptionsError({
3354
- message: `--allow-egress must be an IPv4 network such as 140.82.112.0/20 (got ${badNetwork}).`
3350
+ message: `--allow-egress must be a domain name such as api.openai.com or *.github.com, or an IPv4 network such as 140.82.112.0/20 (got ${badEntry}).`
3355
3351
  });
3356
3352
  }
3353
+ });
3354
+ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3355
+ const env = yield* keyValues("--env", flags.env);
3356
+ const metadata = yield* keyValues("--metadata", flags.metadata);
3357
+ const timeoutMs = yield* import_effect24.Option.match(flags.timeout, {
3358
+ onNone: () => import_effect24.Effect.succeed(void 0),
3359
+ onSome: (text) => parseLifetime("--timeout", text)
3360
+ });
3361
+ yield* checkEgressFlags(flags.denyEgress, flags.allowEgress);
3357
3362
  const badPort = flags.ports.find((port) => !Number.isInteger(port) || port < 1 || port > 65535);
3358
3363
  if (badPort !== void 0) {
3359
3364
  return yield* new InvalidMicroVmOptionsError({ message: `--port must be between 1 and 65535 (got ${badPort}).` });
@@ -3369,6 +3374,8 @@ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3369
3374
  ...import_effect24.Option.match(flags.memory, { onNone: () => ({}), onSome: (memoryMb) => ({ memoryMb }) }),
3370
3375
  ...import_effect24.Option.match(flags.disk, { onNone: () => ({}), onSome: (diskMb) => ({ diskMb }) }),
3371
3376
  ...timeoutMs !== void 0 ? { timeoutMs } : {},
3377
+ ...flags.pauseOnTimeout ? { onTimeout: "pause" } : {},
3378
+ ...flags.autoResume ? { autoResume: true } : {},
3372
3379
  ...flags.ports.length > 0 ? { ports: [...flags.ports] } : {},
3373
3380
  ...env ? { env } : {},
3374
3381
  ...metadata ? { metadata } : {},
@@ -3376,7 +3383,7 @@ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3376
3383
  network: {
3377
3384
  egress: flags.denyEgress ? "deny" : "allow",
3378
3385
  ...flags.privatePreviews ? { previews: "private" } : {},
3379
- ...flags.allowEgress.length > 0 ? { allow: [...flags.allowEgress] } : {}
3386
+ ...flags.allowEgress.length > 0 ? { allow: flags.allowEgress.map((entry) => entry.trim()) } : {}
3380
3387
  }
3381
3388
  } : {},
3382
3389
  ...import_effect24.Option.match(flags.region, { onNone: () => ({}), onSome: (region) => ({ region }) })
@@ -3444,10 +3451,18 @@ var createCommand = import_cli12.Command.make(
3444
3451
  ),
3445
3452
  allowEgress: import_cli12.Options.text("allow-egress").pipe(
3446
3453
  import_cli12.Options.withDescription(
3447
- "Only reach this public IPv4 network, such as 140.82.112.0/20, besides DNS (repeatable, up to 32)"
3454
+ "Only reach this domain name (api.openai.com, *.github.com for every subdomain) or public IPv4 network (140.82.112.0/20) (repeatable, up to 32)"
3448
3455
  ),
3449
3456
  import_cli12.Options.repeated
3450
3457
  ),
3458
+ pauseOnTimeout: import_cli12.Options.boolean("pause-on-timeout").pipe(
3459
+ import_cli12.Options.withDescription("Pause the microVM when its timeout ends instead of stopping it")
3460
+ ),
3461
+ autoResume: import_cli12.Options.boolean("auto-resume").pipe(
3462
+ import_cli12.Options.withDescription(
3463
+ "Resume the paused microVM when a command, file call or public preview request reaches it"
3464
+ )
3465
+ ),
3451
3466
  region: import_cli12.Options.text("region").pipe(import_cli12.Options.withDescription("Region to place the microVM in"), import_cli12.Options.optional),
3452
3467
  json: jsonOption2
3453
3468
  },
@@ -3764,6 +3779,46 @@ var extendCommand = import_cli12.Command.make(
3764
3779
  },
3765
3780
  ({ microvmId, duration }) => extendMicroVm(microvmId, duration).pipe(import_effect24.Effect.asVoid, reportErrors2("extend the microVM"))
3766
3781
  ).pipe(import_cli12.Command.withDescription("Set how long a microVM keeps running, counted from now"));
3782
+ var updateMicroVmNetwork = (microvmId, flags) => import_effect24.Effect.gen(function* () {
3783
+ const chosen = [flags.denyEgress, flags.allowEgress.length > 0, flags.allowAllEgress].filter(Boolean).length;
3784
+ if (chosen !== 1) {
3785
+ return yield* new InvalidMicroVmOptionsError({
3786
+ message: "Pass exactly one of --deny-egress, --allow-egress or --allow-all-egress."
3787
+ });
3788
+ }
3789
+ yield* checkEgressFlags(flags.denyEgress, flags.allowEgress);
3790
+ const apiClient = yield* ApiClientService;
3791
+ const vm = yield* apiClient.request(
3792
+ (client) => client.microvms.updateNetwork(
3793
+ microvmId,
3794
+ flags.denyEgress ? { egress: "deny" } : flags.allowEgress.length > 0 ? { egress: "allow", allow: flags.allowEgress.map((entry) => entry.trim()) } : { egress: "allow" }
3795
+ )
3796
+ );
3797
+ const reach = vm.network.egress === "deny" ? "no outbound traffic" : vm.network.allow ? vm.network.allow.join(", ") : "the whole internet";
3798
+ yield* import_effect24.Console.log(`${vm.id} now reaches ${reach}.`);
3799
+ return vm;
3800
+ });
3801
+ var networkCommand = import_cli12.Command.make(
3802
+ "network",
3803
+ {
3804
+ microvmId: microvmIdArg,
3805
+ denyEgress: import_cli12.Options.boolean("deny-egress").pipe(import_cli12.Options.withDescription("Block all outbound network traffic")),
3806
+ allowEgress: import_cli12.Options.text("allow-egress").pipe(
3807
+ import_cli12.Options.withDescription(
3808
+ "Only reach this domain name (api.openai.com, *.github.com for every subdomain) or public IPv4 network (140.82.112.0/20) (repeatable, up to 32)"
3809
+ ),
3810
+ import_cli12.Options.repeated
3811
+ ),
3812
+ allowAllEgress: import_cli12.Options.boolean("allow-all-egress").pipe(
3813
+ import_cli12.Options.withDescription("Reach the whole internet again (private networks stay blocked)")
3814
+ )
3815
+ },
3816
+ ({ microvmId, ...flags }) => updateMicroVmNetwork(microvmId, flags).pipe(import_effect24.Effect.asVoid, reportErrors2("update the microVM network"))
3817
+ ).pipe(
3818
+ import_cli12.Command.withDescription(
3819
+ "Change what a running or paused microVM may reach; connections the new rules no longer allow are closed"
3820
+ )
3821
+ );
3767
3822
  var imagesListCommand = import_cli12.Command.make(
3768
3823
  "ls",
3769
3824
  { app: appOption6, json: jsonOption2 },
@@ -3870,6 +3925,7 @@ var SUBCOMMANDS = [
3870
3925
  stopCommand,
3871
3926
  removeCommand2,
3872
3927
  extendCommand,
3928
+ networkCommand,
3873
3929
  imagesCommand
3874
3930
  ];
3875
3931
  var microvmsCommand = import_cli12.Command.make("microvms", {}, () => import_effect24.Effect.void).pipe(