koigrid 0.11.0 → 0.13.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/CHANGELOG.md +19 -0
- package/dist/commands/db.js +13 -1
- package/dist/commands/registry.js +9 -0
- package/dist/commands/sandboxes.js +195 -1
- package/dist/manifest.js +2 -2
- package/dist/vm-run.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,10 +4,29 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.13.0] — 2026-11-27
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `koigrid registry signing-key`: the public key koigrid signs the images it builds with, and the `cosign verify` command to check one.
|
|
12
|
+
- `koigrid sandboxes vm ports ls|expose|public|private|rm|url|urls|revoke`: expose a VM port over HTTPS (private by default), make it public, or create a signed URL for one port that expires (default 1 h, max 7 days) and can be revoked. The API answers 503 `vm_ports_unavailable` until the feature is switched on.
|
|
13
|
+
|
|
14
|
+
## [0.12.0] — 2026-11-27
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `koigrid db ext <id>`: the extensions installed in each database (also those created with `CREATE EXTENSION` outside the API) and the preloaded libraries, read live from a running member; says why when no member answers instead of printing an empty list.
|
|
19
|
+
|
|
7
20
|
## [0.11.0] — 2026-11-26
|
|
8
21
|
|
|
9
22
|
### Added
|
|
10
23
|
|
|
24
|
+
- `koigrid sandboxes vm create <name> --from <snapshot>`: a VM born from a named snapshot (template), with its disk, memory and size.
|
|
25
|
+
- `koigrid sandboxes vm snapshots` (no VM): the named snapshots of the project, also of deleted VMs; `vm snapshot-rm <snapshot>` deletes one. A named snapshot now outlives its VM.
|
|
26
|
+
- `koigrid sandboxes vm snapshot-ls <snapshot> [path]` and `snapshot-cat <snapshot> <path>`: read the snapshot disk without booting it.
|
|
27
|
+
- `koigrid sandboxes vm run [--dir LOCAL] [--size S] [--from SNAPSHOT] [--keep] -- <command>`: one go — creates a VM, uploads the folder to /root/work, runs the command with live output (exits with its code), prints the cost and deletes the VM.
|
|
28
|
+
- `koigrid sandboxes vm history <vm>`: the commands run in the VM (direct and background), newest first, kept 90 days; `vm ps <vm>`: the processes running now.
|
|
29
|
+
- `koigrid sandboxes vm snapshot-share <snapshot> [--expires-days N]`: a code (shown once) another organization uses with `vm create --from`; `snapshot-shares` lists the codes given and `snapshot-unshare <snapshot> <share-id>` revokes one.
|
|
11
30
|
- `koigrid apps github-repos`: the repositories your connected GitHub App installations can deploy, latest push first (or the link to connect GitHub).
|
|
12
31
|
- `koigrid apps deploy --repo <github-url> --github-installation <id>`: links the app to the GitHub App before the first deploy, so a private repo clones without a token and every push redeploys.
|
|
13
32
|
- `koigrid dns list`, `koigrid logs list` and `koigrid wordpress list`: `list` now works as an alias of `ls` in every command that lists, as it already did in the rest.
|
package/dist/commands/db.js
CHANGED
|
@@ -305,7 +305,19 @@ export async function db(a) {
|
|
|
305
305
|
const name = a.positionals[1];
|
|
306
306
|
if (!name) {
|
|
307
307
|
const r = await api(`/databases/${encodeURIComponent(id)}/extensions`);
|
|
308
|
-
|
|
308
|
+
if (json)
|
|
309
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
310
|
+
console.log('allowed: ' + (r.allowed || []).join(', '));
|
|
311
|
+
const inst = r.installed;
|
|
312
|
+
if (!inst)
|
|
313
|
+
return;
|
|
314
|
+
if (!inst.measured)
|
|
315
|
+
return console.log(`installed: not measured (${inst.reason})`);
|
|
316
|
+
if (inst.preloadLibraries?.length)
|
|
317
|
+
console.log('preloaded: ' + inst.preloadLibraries.join(', '));
|
|
318
|
+
for (const d of inst.databases || [])
|
|
319
|
+
console.log(`installed in ${d.name}: ` + d.extensions.map((e) => `${e.name} ${e.version}`).join(', '));
|
|
320
|
+
return;
|
|
309
321
|
}
|
|
310
322
|
// `--schema` (paridad con la API): instala la extensión en ese schema. Es el camino de los ex-Supabase —
|
|
311
323
|
// sus dumps declaran tipos como `extensions.vector`, así que sin esto el restore falla con "type
|
|
@@ -67,6 +67,15 @@ export async function registry(a) {
|
|
|
67
67
|
// ayuda: imprime el comando docker login (el push/pull es por docker, no por este CLI)
|
|
68
68
|
return console.log('docker login registry.koigrid.com -u token -p <koi-token-with-registry:read/write>\n# luego: docker tag <img> registry.koigrid.com/<name>:<tag> && docker push registry.koigrid.com/<name>:<tag>');
|
|
69
69
|
}
|
|
70
|
+
if (sub === 'signing-key') {
|
|
71
|
+
// La clave pública con la que koigrid firma las imágenes que construye (cosign). Pública: no pide token.
|
|
72
|
+
const r = await api('/registry/signing-key');
|
|
73
|
+
if (json)
|
|
74
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
75
|
+
console.log(r.pem.trim());
|
|
76
|
+
console.error(r.verify);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
70
79
|
if (sub === 'policy') {
|
|
71
80
|
// Retención por repositorio (como una lifecycle policy de ECR): `policy <name>` la enseña, `policy <name> 20`
|
|
72
81
|
// la fija y `policy <name> plan` vuelve a la del plan. Lo que sirve un despliegue vivo se conserva siempre.
|
|
@@ -52,14 +52,25 @@ export async function sandboxes(a) {
|
|
|
52
52
|
}
|
|
53
53
|
const USO_VM = `usage: koigrid sandboxes vm <action> …
|
|
54
54
|
ls list VMs
|
|
55
|
+
run [--dir LOCAL] [--size S] [--from SNAPSHOT] [--keep] -- <command…>
|
|
56
|
+
one go: create a VM, upload the folder to /root/work, run the command there
|
|
57
|
+
(live output, exits with its code), print the cost, delete the VM (--keep: don't)
|
|
55
58
|
create <name> [--size small|medium|large|xlarge] [--auto-pause MIN] [--label k=v] [--ssh-key FILE.pub]
|
|
59
|
+
create <name> --from <snapshot> born from a named snapshot (template) or a share code (koisnap_…): its disk and memory, its size
|
|
56
60
|
[--env KEY=VALUE]… [--repo owner/repo]… [--environment FILE.json] [--safe-for-third-parties]
|
|
57
61
|
env <vm> its environment: variable names, files, repositories, last apply (never values)
|
|
58
62
|
env set <vm> [--env KEY=VALUE]… [--repo owner/repo]… [--environment FILE.json] [--safe-for-third-parties]
|
|
59
63
|
replace it (values may use \${{ shared.KEY }}, \${{ db.<name>.DATABASE_URL }}…)
|
|
60
64
|
token <vm> [--expires SECONDS] [--read-only] an API token that only works on this VM, to hand to someone else
|
|
61
65
|
usage <vm> [--days N] what it has used: seconds running, GB·h and cost, per day (≤90 days)
|
|
66
|
+
history <vm> [--limit N] [--before ISO] commands run in it (direct and background), newest first, 90 days
|
|
67
|
+
ps <vm> processes running now, highest CPU first
|
|
62
68
|
limits fair-use ceilings of your VMs and how much of each is used
|
|
69
|
+
ports ls <vm> ports exposed over HTTPS (public ones show their URL)
|
|
70
|
+
ports expose <vm> <port> [--public] expose a port; private by default (reach it with a signed URL)
|
|
71
|
+
ports public|private <vm> <port> make it public or private · ports rm <vm> <port>: stop exposing it
|
|
72
|
+
ports url <vm> <port> [--expires S] a signed URL for that port (default 1 h, max 7 days), shown once
|
|
73
|
+
ports urls <vm> <port> its signed URLs · ports revoke <vm> <port> <url-id>: revoke one
|
|
63
74
|
ssh <vm> [-- command] SSH into the VM (wakes it if paused); needs your key on it (ssh-key set)
|
|
64
75
|
ssh-key set <vm> [--key FILE.pub]… replace the keys allowed in (default ~/.ssh/id_ed25519.pub) · ssh-key ls <vm>
|
|
65
76
|
ssh-config <vm> [--write] the ~/.ssh/config block for ssh, VS Code and Cursor (--write adds it, and the VM host key)
|
|
@@ -73,7 +84,13 @@ const USO_VM = `usage: koigrid sandboxes vm <action> …
|
|
|
73
84
|
commands stop <vm> <cmd> SIGTERM to its process group, SIGKILL after 5 s
|
|
74
85
|
pause|resume|stop|start <vm>
|
|
75
86
|
fork <vm> --name <new>
|
|
76
|
-
snapshot <vm> --name <label> · snapshots <vm>
|
|
87
|
+
snapshot <vm> --name <label> · snapshots <vm> (a named snapshot outlives its VM)
|
|
88
|
+
snapshots named snapshots of the project, also of deleted VMs
|
|
89
|
+
snapshot-rm <snapshot> delete a named snapshot (id or name; cannot be undone)
|
|
90
|
+
snapshot-ls <snapshot> [path] a directory of the snapshot disk, without booting it (default /root)
|
|
91
|
+
snapshot-cat <snapshot> <path> a file of the snapshot disk, without booting it (up to 700 KB)
|
|
92
|
+
snapshot-share <snapshot> [--expires-days N] a code another organization uses as --from (shown once)
|
|
93
|
+
snapshot-shares <snapshot> codes given (prefix, uses, expiry) · snapshot-unshare <snapshot> <share-id>
|
|
77
94
|
update <vm> [--auto-pause MIN] [--size …] [--label k=v]
|
|
78
95
|
rm <vm>
|
|
79
96
|
files ls <vm> [path] [--depth N] · files find <vm> <path> --name '*.ts'
|
|
@@ -158,8 +175,12 @@ async function vm(a, json) {
|
|
|
158
175
|
const l = r.vms || [];
|
|
159
176
|
return output(l, json, { rows: l.map(filaVm), columns: ['name', 'size', 'status', 'ssh', 'autoPause', 'id'] });
|
|
160
177
|
}
|
|
178
|
+
if (accion === 'run')
|
|
179
|
+
return correrDePuntaAPunta(a, json);
|
|
161
180
|
if (accion === 'create') {
|
|
162
181
|
const body = { name: necesita() };
|
|
182
|
+
if (a.flags.from)
|
|
183
|
+
body.fromSnapshot = String(a.flags.from);
|
|
163
184
|
if (a.flags.size)
|
|
164
185
|
body.size = String(a.flags.size);
|
|
165
186
|
if (a.flags['auto-pause'] !== undefined)
|
|
@@ -186,6 +207,24 @@ async function vm(a, json) {
|
|
|
186
207
|
return console.log(JSON.stringify(r, null, 2));
|
|
187
208
|
return muestraEntorno(r.environment || {});
|
|
188
209
|
}
|
|
210
|
+
if (accion === 'history') {
|
|
211
|
+
const q = new URLSearchParams();
|
|
212
|
+
if (a.flags.limit !== undefined)
|
|
213
|
+
q.set('limit', String(Number(a.flags.limit)));
|
|
214
|
+
if (a.flags.before)
|
|
215
|
+
q.set('before', String(a.flags.before));
|
|
216
|
+
const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/history${q.size ? `?${q}` : ''}`);
|
|
217
|
+
const l = r.entries || [];
|
|
218
|
+
output(l, json, { rows: l.map((x) => ({ started: x.startedAt, kind: x.kind, status: x.status, exit: x.exitCode ?? '', ms: x.durationMs ?? '', command: String(x.command).slice(0, 80) })), columns: ['started', 'kind', 'status', 'exit', 'ms', 'command'] });
|
|
219
|
+
if (!json && r.nextBefore)
|
|
220
|
+
console.log(`more: --before ${r.nextBefore}`);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (accion === 'ps') {
|
|
224
|
+
const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/processes`);
|
|
225
|
+
const l = r.processes || [];
|
|
226
|
+
return output(l, json, { rows: l.map((x) => ({ pid: x.pid, user: x.user, cpu: x.cpuPct, rssMb: Math.round(x.rssKb / 1024), secs: x.elapsedSec, command: String(x.command).slice(0, 80) })), columns: ['pid', 'user', 'cpu', 'rssMb', 'secs', 'command'] });
|
|
227
|
+
}
|
|
189
228
|
if (accion === 'usage') {
|
|
190
229
|
const dias = a.flags.days ? `?days=${Number(a.flags.days)}` : '';
|
|
191
230
|
const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/usage${dias}`);
|
|
@@ -218,6 +257,55 @@ async function vm(a, json) {
|
|
|
218
257
|
console.error(`only valid on ${r.base}/… until ${r.token.expiresAt} · revoke: koigrid tokens revoke ${r.token.id}`);
|
|
219
258
|
return;
|
|
220
259
|
}
|
|
260
|
+
// ── Puertos por https (hueco 11, ficha 1cabcf55): privados por defecto, URL firmada o pública ──
|
|
261
|
+
if (accion === 'ports') {
|
|
262
|
+
const sub = objetivo;
|
|
263
|
+
const vmNombre = a.positionals[2];
|
|
264
|
+
const puerto = a.positionals[3];
|
|
265
|
+
if (!vmNombre || !['ls', 'expose', 'public', 'private', 'rm', 'url', 'urls', 'revoke'].includes(String(sub)))
|
|
266
|
+
throw new Error(USO_VM);
|
|
267
|
+
if (sub !== 'ls' && !puerto)
|
|
268
|
+
throw new Error(USO_VM);
|
|
269
|
+
let r;
|
|
270
|
+
if (sub === 'ls')
|
|
271
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports`);
|
|
272
|
+
else if (sub === 'expose')
|
|
273
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports`, { method: 'POST', body: { port: Number(puerto), public: !!a.flags.public } });
|
|
274
|
+
else if (sub === 'public' || sub === 'private')
|
|
275
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports/${encodeURIComponent(String(puerto))}`, { method: 'PATCH', body: { public: sub === 'public' } });
|
|
276
|
+
else if (sub === 'rm')
|
|
277
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports/${encodeURIComponent(String(puerto))}`, { method: 'DELETE' });
|
|
278
|
+
else if (sub === 'url')
|
|
279
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports/${encodeURIComponent(String(puerto))}/urls`, { method: 'POST', body: a.flags.expires ? { expiresInSeconds: Number(a.flags.expires) } : {} });
|
|
280
|
+
else if (sub === 'urls')
|
|
281
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports/${encodeURIComponent(String(puerto))}/urls`);
|
|
282
|
+
else {
|
|
283
|
+
const urlId = a.positionals[4];
|
|
284
|
+
if (!urlId)
|
|
285
|
+
throw new Error(USO_VM);
|
|
286
|
+
r = await api(`/sandboxes/vms/${encodeURIComponent(vmNombre)}/ports/${encodeURIComponent(String(puerto))}/urls/${encodeURIComponent(urlId)}`, { method: 'DELETE' });
|
|
287
|
+
}
|
|
288
|
+
if (json)
|
|
289
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
290
|
+
if (sub === 'ls') {
|
|
291
|
+
if (!r.ports.length)
|
|
292
|
+
return console.log(`no ports exposed (at most ${r.max}): koigrid sandboxes vm ports expose ${vmNombre} <port>`);
|
|
293
|
+
for (const p of r.ports)
|
|
294
|
+
console.log(`${p.port}\t${p.public ? 'public ' : 'private'}\t${p.url ?? '(signed URL: koigrid sandboxes vm ports url ' + vmNombre + ' ' + p.port + ')'}`);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (sub === 'url') {
|
|
298
|
+
console.log(r.url);
|
|
299
|
+
console.error(`only for port ${puerto}, until ${r.expiresAt} · revoke: koigrid sandboxes vm ports revoke ${vmNombre} ${puerto} ${r.id}`);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (sub === 'urls') {
|
|
303
|
+
for (const u of r.urls)
|
|
304
|
+
console.log(`${u.id}\t${u.tokenPrefix}…\t${u.active ? 'active' : u.revokedAt ? 'revoked' : 'expired'}\t${u.expiresAt}`);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
return console.log(JSON.stringify(r));
|
|
308
|
+
}
|
|
221
309
|
// ── SSH (ficha daa6b24a): por la puerta de koigrid, cifrado de punta a punta con la VM ──
|
|
222
310
|
if (accion === 'ssh-key') {
|
|
223
311
|
const sub = objetivo;
|
|
@@ -324,6 +412,60 @@ async function vm(a, json) {
|
|
|
324
412
|
return console.log(JSON.stringify(r, null, 2));
|
|
325
413
|
return console.log(green(`✓ snapshot ${r.snapshot?.name} (${r.snapshot?.id})`));
|
|
326
414
|
}
|
|
415
|
+
if (accion === 'snapshots' && !objetivo) {
|
|
416
|
+
const r = await api('/sandboxes/snapshots');
|
|
417
|
+
const l = r.snapshots || [];
|
|
418
|
+
return output(l, json, { rows: l.map((x) => ({ name: x.name, size: x.size, bytes: x.sizeBytes ?? '', vm: `${x.vm?.name}${x.vm?.deleted ? ' (deleted)' : ''}`, created: x.createdAt, id: String(x.id) })), columns: ['name', 'size', 'bytes', 'vm', 'created', 'id'] });
|
|
419
|
+
}
|
|
420
|
+
if (accion === 'snapshot-ls') {
|
|
421
|
+
const ruta = a.positionals[2] ? `?path=${encodeURIComponent(String(a.positionals[2]))}` : '';
|
|
422
|
+
const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/files${ruta}`);
|
|
423
|
+
const l = r.entries || [];
|
|
424
|
+
return output(l, json, { rows: l.map((x) => ({ type: x.type, size: x.size, mode: x.mode, path: x.path })), columns: ['type', 'size', 'mode', 'path'] });
|
|
425
|
+
}
|
|
426
|
+
if (accion === 'snapshot-cat') {
|
|
427
|
+
const ruta = a.positionals[2];
|
|
428
|
+
if (!ruta)
|
|
429
|
+
throw new Error(USO_VM);
|
|
430
|
+
const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/files/content?path=${encodeURIComponent(String(ruta))}`);
|
|
431
|
+
if (json)
|
|
432
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
433
|
+
process.stdout.write(Buffer.from(r.contentBase64 || '', 'base64'));
|
|
434
|
+
if (r.truncated)
|
|
435
|
+
console.error(`\n(truncated: the file has ${r.size} bytes, shown ${r.maxBytes})`);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (accion === 'snapshot-share') {
|
|
439
|
+
const body = {};
|
|
440
|
+
if (a.flags['expires-days'] !== undefined)
|
|
441
|
+
body.expiresInDays = Number(a.flags['expires-days']);
|
|
442
|
+
const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares`, { method: 'POST', body });
|
|
443
|
+
if (json)
|
|
444
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
445
|
+
console.log(green(`✓ share code (shown only now): ${r.code}`));
|
|
446
|
+
console.log(` use it with: koigrid sandboxes vm create <name> --from ${r.code}`);
|
|
447
|
+
return console.error(` ${r.warning}`);
|
|
448
|
+
}
|
|
449
|
+
if (accion === 'snapshot-shares') {
|
|
450
|
+
const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares`);
|
|
451
|
+
const l = r.shares || [];
|
|
452
|
+
return output(l, json, { rows: l.map((x) => ({ code: `${x.codePrefix}…`, uses: x.uses, expires: x.expiresAt ?? 'never', revoked: x.revokedAt ?? '', created: x.createdAt, id: String(x.id) })), columns: ['code', 'uses', 'expires', 'revoked', 'created', 'id'] });
|
|
453
|
+
}
|
|
454
|
+
if (accion === 'snapshot-unshare') {
|
|
455
|
+
const share = a.positionals[2];
|
|
456
|
+
if (!share)
|
|
457
|
+
throw new Error(USO_VM);
|
|
458
|
+
const r = await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}/shares/${encodeURIComponent(String(share))}`, { method: 'DELETE' });
|
|
459
|
+
if (json)
|
|
460
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
461
|
+
return console.log(green(`✓ share ${share} revoked`));
|
|
462
|
+
}
|
|
463
|
+
if (accion === 'snapshot-rm') {
|
|
464
|
+
await api(`/sandboxes/snapshots/${encodeURIComponent(necesita())}`, { method: 'DELETE' });
|
|
465
|
+
if (json)
|
|
466
|
+
return console.log(JSON.stringify({ deleted: true }));
|
|
467
|
+
return console.log(green(`✓ snapshot ${objetivo} deleted`));
|
|
468
|
+
}
|
|
327
469
|
if (accion === 'snapshots') {
|
|
328
470
|
const r = await api(`/sandboxes/vms/${encodeURIComponent(necesita())}/snapshots`);
|
|
329
471
|
const l = r.snapshots || [];
|
|
@@ -425,6 +567,58 @@ async function seguirOrden(vmId, ruta, cuerpo, json, cmd) {
|
|
|
425
567
|
cuerpo = undefined;
|
|
426
568
|
}
|
|
427
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* `vm run` (hueco 15, como `boat run`): crear → subir la carpeta → ejecutar en directo → coste → borrar. La VM se borra
|
|
572
|
+
* SIEMPRE al acabar (también si la orden falla o se corta con Ctrl-C), salvo --keep; si no se pudo borrar, se dice cómo.
|
|
573
|
+
*/
|
|
574
|
+
async function correrDePuntaAPunta(a, json) {
|
|
575
|
+
const args = a.passthrough ?? [];
|
|
576
|
+
if (!args.length)
|
|
577
|
+
throw new Error(USO_VM);
|
|
578
|
+
const { DIR_DE_RUN, nombreDeRun, ordenDeShell } = await import('../vm-run');
|
|
579
|
+
const body = { name: a.flags.name ? String(a.flags.name) : nombreDeRun(new Date(), Math.random().toString(36).slice(2)) };
|
|
580
|
+
if (a.flags.from)
|
|
581
|
+
body.fromSnapshot = String(a.flags.from);
|
|
582
|
+
if (a.flags.size)
|
|
583
|
+
body.size = String(a.flags.size);
|
|
584
|
+
const creada = (await api('/sandboxes/vms', { method: 'POST', body })).vm;
|
|
585
|
+
if (!creada || creada.status !== 'running')
|
|
586
|
+
throw new Error(`the VM did not start: ${creada?.statusReason ?? creada?.status ?? 'no answer'}`);
|
|
587
|
+
const id = String(creada.id);
|
|
588
|
+
const borrar = async () => {
|
|
589
|
+
if (a.flags.keep)
|
|
590
|
+
return console.error(`kept: koigrid sandboxes vm rm ${creada.name}`);
|
|
591
|
+
try {
|
|
592
|
+
await api(`/sandboxes/vms/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
593
|
+
if (!json)
|
|
594
|
+
console.error(`✓ VM ${creada.name} deleted`);
|
|
595
|
+
}
|
|
596
|
+
catch (e) {
|
|
597
|
+
console.error(`could not delete the VM (${e.message}); delete it with: koigrid sandboxes vm rm ${creada.name}`);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const alCortar = () => { void borrar().finally(() => process.exit(130)); };
|
|
601
|
+
process.once('SIGINT', alCortar);
|
|
602
|
+
try {
|
|
603
|
+
if (!json)
|
|
604
|
+
console.error(`✓ VM ${creada.name} (${creada.size}) running`);
|
|
605
|
+
if (a.flags.dir) {
|
|
606
|
+
const { execFileSync } = await import('node:child_process');
|
|
607
|
+
const tgz = execFileSync('tar', ['-czf', '-', '--exclude=node_modules', '--exclude=.git', '-C', String(a.flags.dir), '.'], { maxBuffer: 6 * 1024 ** 3 });
|
|
608
|
+
const r = await subirGrande(id, tgz, DIR_DE_RUN, true);
|
|
609
|
+
if (!json)
|
|
610
|
+
console.error(`✓ ${a.flags.dir} → ${DIR_DE_RUN} (${r.uploadedBytes} bytes packed)`);
|
|
611
|
+
}
|
|
612
|
+
await seguirOrden(id, `/sandboxes/vms/${encodeURIComponent(id)}/exec`, { command: ordenDeShell(args), cwd: a.flags.dir ? DIR_DE_RUN : '/root', stream: true }, json);
|
|
613
|
+
const u = (await api(`/sandboxes/vms/${encodeURIComponent(id)}/usage?days=1`)).usage;
|
|
614
|
+
if (u && !json)
|
|
615
|
+
console.error(`cost: $${u.total?.costUsd ?? 0} (${Math.round(u.total?.seconds ?? 0)} s at $${u.pricePerHourUsd}/h)${u.billed ? '' : ' — measured, not charged'}`);
|
|
616
|
+
}
|
|
617
|
+
finally {
|
|
618
|
+
process.off('SIGINT', alCortar);
|
|
619
|
+
await borrar();
|
|
620
|
+
}
|
|
621
|
+
}
|
|
428
622
|
// koigrid sandboxes vm files — ficheros de una VM (ficha VM-FICHEROS, lib/api/vm-ficheros.ts).
|
|
429
623
|
async function ficheros(a, json) {
|
|
430
624
|
const sub = a.positionals[1] || 'ls';
|
package/dist/manifest.js
CHANGED
|
@@ -50,7 +50,7 @@ export const CLI_COMMANDS = [
|
|
|
50
50
|
{ name: 'analytics', product: 'analytics', summary: 'Privacy-first web analytics (no cookies)', subs: ['sites', 'create', 'stats', 'rm'], endpoints: ['analytics/sites', 'analytics/sites/[id]', 'analytics/sites/[id]/stats'] },
|
|
51
51
|
{ name: 'errors', aliases: ['error'], product: 'errors', summary: 'Error tracking (capture exceptions, group by fingerprint)', subs: ['ls', 'token', 'resolve', 'reopen', 'rm'], endpoints: ['errors', 'errors/groups/[id]'] },
|
|
52
52
|
{ name: 'speed', aliases: ['vitals'], product: 'speed-insights', summary: 'Speed Insights (Core Web Vitals: LCP/CLS/FCP/TTFB)', subs: ['ls'], endpoints: ['speed-insights', 'speed-insights/[id]'] },
|
|
53
|
-
{ name: 'sandboxes', aliases: ['sandbox', 'sb'], product: 'sandboxes', summary: 'Ephemeral runs (image+command once) and persistent agent VMs (sandboxes vm …: pause with memory, fork, exec, ssh, environment, VM-scoped tokens)', subs: ['run', 'ls', 'get', 'vm'], endpoints: ['sandboxes', 'sandboxes/[id]', 'sandboxes/vms', 'sandboxes/vms/[id]', 'sandboxes/vms/[id]/exec', 'sandboxes/vms/[id]/pause', 'sandboxes/vms/[id]/resume', 'sandboxes/vms/[id]/stop', 'sandboxes/vms/[id]/start', 'sandboxes/vms/[id]/fork', 'sandboxes/vms/[id]/ssh-keys', 'sandboxes/vms/[id]/environment', 'sandboxes/vms/[id]/tokens', 'sandboxes/vms/[id]/usage', 'sandboxes/vms/limits', 'sandboxes/vms/[id]/snapshots', 'sandboxes/vms/[id]/commands', 'sandboxes/vms/[id]/commands/[cmd]', 'sandboxes/vms/[id]/commands/[cmd]/stream', 'sandboxes/vms/[id]/files', 'sandboxes/vms/[id]/files/content', 'sandboxes/vms/[id]/files/move', 'sandboxes/vms/[id]/files/mkdir', 'sandboxes/vms/[id]/files/chmod', 'sandboxes/vms/[id]/files/replace', 'sandboxes/vms/[id]/files/upload-url', 'sandboxes/vms/[id]/files/upload-complete', 'sandboxes/vms/[id]/files/download-url'] },
|
|
53
|
+
{ name: 'sandboxes', aliases: ['sandbox', 'sb'], product: 'sandboxes', summary: 'Ephemeral runs (image+command once) and persistent agent VMs (sandboxes vm …: pause with memory, fork, exec, ssh, environment, VM-scoped tokens)', subs: ['run', 'ls', 'get', 'vm'], endpoints: ['sandboxes', 'sandboxes/[id]', 'sandboxes/vms', 'sandboxes/vms/[id]', 'sandboxes/vms/[id]/exec', 'sandboxes/vms/[id]/pause', 'sandboxes/vms/[id]/resume', 'sandboxes/vms/[id]/stop', 'sandboxes/vms/[id]/start', 'sandboxes/vms/[id]/fork', 'sandboxes/vms/[id]/ssh-keys', 'sandboxes/vms/[id]/environment', 'sandboxes/vms/[id]/tokens', 'sandboxes/vms/[id]/ports', 'sandboxes/vms/[id]/ports/[port]', 'sandboxes/vms/[id]/ports/[port]/urls', 'sandboxes/vms/[id]/ports/[port]/urls/[urlId]', 'sandboxes/vms/[id]/usage', 'sandboxes/vms/[id]/history', 'sandboxes/vms/[id]/processes', 'sandboxes/vms/limits', 'sandboxes/vms/[id]/snapshots', 'sandboxes/snapshots', 'sandboxes/snapshots/[id]', 'sandboxes/snapshots/[id]/files', 'sandboxes/snapshots/[id]/shares', 'sandboxes/snapshots/[id]/shares/[shareId]', 'sandboxes/snapshots/[id]/files/content', 'sandboxes/vms/[id]/commands', 'sandboxes/vms/[id]/commands/[cmd]', 'sandboxes/vms/[id]/commands/[cmd]/stream', 'sandboxes/vms/[id]/files', 'sandboxes/vms/[id]/files/content', 'sandboxes/vms/[id]/files/move', 'sandboxes/vms/[id]/files/mkdir', 'sandboxes/vms/[id]/files/chmod', 'sandboxes/vms/[id]/files/replace', 'sandboxes/vms/[id]/files/upload-url', 'sandboxes/vms/[id]/files/upload-complete', 'sandboxes/vms/[id]/files/download-url'] },
|
|
54
54
|
{ name: 'images', aliases: ['image', 'img'], product: 'images', summary: 'Image optimization (resize/re-encode on the fly, allowlisted)', subs: ['config', 'allow', 'usage'], endpoints: ['images/config', 'images/usage'] },
|
|
55
55
|
{ name: 'waf', aliases: ['firewall'], product: 'firewall', summary: 'Firewall/WAF — allow/block rules (IP/country/path…) + evaluate', subs: ['rules', 'add', 'rm', 'evaluate'], endpoints: ['waf/rules', 'waf/rules/[id]', 'waf/evaluate'] },
|
|
56
56
|
{ name: 'webhooks', aliases: ['webhook', 'hooks'], product: 'webhooks', summary: 'Outbound webhooks — platform events → your URL, signed + retried', subs: ['ls', 'create', 'enable', 'disable', 'deliveries', 'rm'], endpoints: ['webhooks', 'webhooks/[id]', 'webhooks/[id]/deliveries'] },
|
|
@@ -62,7 +62,7 @@ export const CLI_COMMANDS = [
|
|
|
62
62
|
{ name: 'dns', product: 'dns', summary: 'DNS Management (BYO) — connect your zone + CRUD records', subs: ['zones', 'connect', 'disconnect', 'records', 'add', 'update', 'del'], endpoints: ['dns/zones', 'dns/zones/[id]', 'dns/zones/[id]/records', 'dns/zones/[id]/records/[recordId]'] },
|
|
63
63
|
{ name: 'queues', aliases: ['queue', 'sqs'], product: 'queues', summary: 'Queues — durable message queue (SQS-like): send/receive/ack + visibility timeout + dead-letter', subs: ['ls', 'create', 'show', 'update', 'send', 'receive', 'ack', 'rm'], endpoints: ['queues', 'queues/[id]', 'queues/[id]/messages', 'queues/[id]/receive', 'queues/[id]/ack'] },
|
|
64
64
|
{ name: 'workflows', aliases: ['workflow', 'wf'], product: 'workflows', summary: 'Workflows — durable execution (Step-Functions-like): ordered steps + journal + durable sleep + retries', subs: ['ls', 'create', 'rm', 'update', 'start', 'runs', 'run', 'next', 'complete', 'fail', 'sleep'], endpoints: ['workflows', 'workflows/[id]', 'workflows/[id]/runs', 'workflows/[id]/runs/[runId]', 'workflows/[id]/runs/[runId]/next', 'workflows/[id]/runs/[runId]/complete', 'workflows/[id]/runs/[runId]/fail', 'workflows/[id]/runs/[runId]/sleep'] },
|
|
65
|
-
{ name: 'registry', aliases: ['ecr', 'cr'], product: 'container-registry', summary: 'Container Registry (OCI, ECR-like) — docker push/pull; list repos + tags (digest/size/pushed); CVE scan (Trivy)', subs: ['repos', 'tags', 'rm-tag', 'gc', 'login', 'scan', 'policy'], endpoints: ['registry/repositories', 'registry/repositories/[name]/tags', 'registry/repositories/[name]/policy', 'registry/repositories/[name]/tags/[tag]', 'registry/gc'] },
|
|
65
|
+
{ name: 'registry', aliases: ['ecr', 'cr'], product: 'container-registry', summary: 'Container Registry (OCI, ECR-like) — docker push/pull; list repos + tags (digest/size/pushed); CVE scan (Trivy)', subs: ['repos', 'tags', 'rm-tag', 'gc', 'login', 'scan', 'policy', 'signing-key'], endpoints: ['registry/signing-key', 'registry/repositories', 'registry/repositories/[name]/tags', 'registry/repositories/[name]/policy', 'registry/repositories/[name]/tags/[tag]', 'registry/gc'] },
|
|
66
66
|
{ name: 'audit', aliases: ['audit-log', 'cloudtrail'], product: 'audit', summary: 'Audit Log — who did what (security/config changes), with IP + CSV export (owner/admin only)', subs: ['ls', 'export'], endpoints: ['audit', 'audit/export'] },
|
|
67
67
|
{ name: 'up', aliases: ['apply', 'cutover'], summary: 'Cutover manifest — bring up a WHOLE stack (apps+db+redis, wired by ${{...}}) from koigrid.yaml in one command', subs: [], endpoints: ['manifest'] },
|
|
68
68
|
{ name: 'plan', summary: 'Dry-run a cutover manifest (koigrid.yaml): what would be created/updated, without mutating', subs: [], endpoints: ['manifest/plan'] },
|
package/dist/vm-run.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// cli/src/vm-run.ts — lo puro de `koigrid sandboxes vm run` (hueco 15 de docs/design/VMS.md §6-bis, ficha 3153e09c):
|
|
2
|
+
// una orden de punta a punta en una VM de usar y tirar, como `boat run`. Aquí sólo lo que se prueba sin red.
|
|
3
|
+
/** Une los argumentos tras `--` en UNA orden de shell, citando cada uno (POSIX): `ls "a b"` llega como dos argumentos. */
|
|
4
|
+
export function ordenDeShell(args) {
|
|
5
|
+
return args.map((a) => (/^[A-Za-z0-9_./:=@%+,-]+$/.test(a) ? a : `'${a.replace(/'/g, `'\\''`)}'`)).join(' ');
|
|
6
|
+
}
|
|
7
|
+
/** Nombre de la VM de usar y tirar: reconocible en la lista y sin chocar con otra del mismo minuto. */
|
|
8
|
+
export function nombreDeRun(ahora, azar) {
|
|
9
|
+
const t = ahora.toISOString().slice(0, 19).replace(/[-:]/g, '').replace('T', '-');
|
|
10
|
+
return `run-${t}-${azar.toLowerCase().replace(/[^a-z0-9]/g, '').slice(0, 4)}`;
|
|
11
|
+
}
|
|
12
|
+
/** Donde se deja la carpeta subida y desde donde corre la orden. */
|
|
13
|
+
export const DIR_DE_RUN = '/root/work';
|