@foldrun/core 20.1.0 → 20.3.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/src/runtime.d.ts +7 -0
- package/dist/src/runtime.js +9 -2
- package/dist/src/secrets.d.ts +9 -0
- package/dist/src/secrets.js +20 -1
- package/package.json +1 -1
- package/src/runtime.ts +10 -2
- package/src/secrets.ts +23 -1
package/dist/src/runtime.d.ts
CHANGED
|
@@ -39,6 +39,13 @@ export declare function parseRuntime(raw: unknown): RuntimeSpec | null;
|
|
|
39
39
|
* say so, loudly, at build time — better than one of them silently winning.
|
|
40
40
|
*/
|
|
41
41
|
export declare function mergeRuntimes(...specs: (RuntimeSpec | null | undefined)[]): RuntimeSpec | null;
|
|
42
|
+
/**
|
|
43
|
+
* The file a platform drops in a cache entry it unpacked from its object store
|
|
44
|
+
* (foldrun-platform runtime-archives.ts), naming the archive it came from. A
|
|
45
|
+
* rebuild removes it with the rest of the entry, so "ready, and no marker" is
|
|
46
|
+
* an entry built here, which is the one worth keeping for the next sandbox.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RUNTIME_FROM_STORE = ".from-store";
|
|
42
49
|
export declare function fingerprint(spec: RuntimeSpec): string;
|
|
43
50
|
/**
|
|
44
51
|
* A tenant name that is safe as one path segment. Tenants come from account
|
package/dist/src/runtime.js
CHANGED
|
@@ -123,6 +123,13 @@ export function mergeRuntimes(...specs) {
|
|
|
123
123
|
merged.ignored = ignored;
|
|
124
124
|
return merged;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The file a platform drops in a cache entry it unpacked from its object store
|
|
128
|
+
* (foldrun-platform runtime-archives.ts), naming the archive it came from. A
|
|
129
|
+
* rebuild removes it with the rest of the entry, so "ready, and no marker" is
|
|
130
|
+
* an entry built here, which is the one worth keeping for the next sandbox.
|
|
131
|
+
*/
|
|
132
|
+
export const RUNTIME_FROM_STORE = ".from-store";
|
|
126
133
|
export function fingerprint(spec) {
|
|
127
134
|
const canonical = JSON.stringify({
|
|
128
135
|
python: spec.python ?? null,
|
|
@@ -1142,7 +1149,7 @@ FOLDRUN_SNAPSHOT_JS
|
|
|
1142
1149
|
$AS sh -c '${PRUNE_SH}' sh "$S" "${cacheDir}" 2>/dev/null
|
|
1143
1150
|
fi
|
|
1144
1151
|
fi
|
|
1145
|
-
printf '{"ok": %s, "exit": %s, "seconds": %s, "mode": "%s", "stale": %s, "packages": "%s", "refused": "%s", "unsaved": "%s"}\n' "$([ $RC -eq 0 ] && echo true || echo false)" "$RC" "$(( $(date +%s) - T0 ))" "$MODE" "$STALE" "$SYS" "$WHY" "$UNSAVED" > ${logDir}/system-install.json
|
|
1152
|
+
printf '{"ok": %s, "exit": %s, "seconds": %s, "mode": "%s", "stale": %s, "packages": "%s", "refused": "%s", "unsaved": "%s", "key": "%s"}\n' "$([ $RC -eq 0 ] && echo true || echo false)" "$RC" "$(( $(date +%s) - T0 ))" "$MODE" "$STALE" "$SYS" "$WHY" "$UNSAVED" "$KEY" > ${logDir}/system-install.json
|
|
1146
1153
|
[ -n "$W" ] && rm -rf "$W"
|
|
1147
1154
|
rm -rf /var/lib/apt/lists/* 2>/dev/null || true
|
|
1148
1155
|
fi`;
|
|
@@ -1287,7 +1294,7 @@ function prepareLanguageRuntime(tenant, spec) {
|
|
|
1287
1294
|
if (stale || !fs.existsSync(path.join(shared, ".ready"))) {
|
|
1288
1295
|
// A clean slate: whatever a stale or half-finished build left behind is
|
|
1289
1296
|
// exactly what must not be built on top of.
|
|
1290
|
-
for (const leftover of [".ready", "venv", "node_modules", "package.json", "package-lock.json"]) {
|
|
1297
|
+
for (const leftover of [".ready", RUNTIME_FROM_STORE, "venv", "node_modules", "package.json", "package-lock.json"]) {
|
|
1291
1298
|
fs.rmSync(path.join(shared, leftover), { recursive: true, force: true });
|
|
1292
1299
|
}
|
|
1293
1300
|
}
|
package/dist/src/secrets.d.ts
CHANGED
|
@@ -57,9 +57,18 @@ export interface VaultStore {
|
|
|
57
57
|
mutate(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile;
|
|
58
58
|
/** The workspaces of this account whose scope is in the store. */
|
|
59
59
|
workspaces(tenant: string): string[];
|
|
60
|
+
/** The scope's FILE was just written while the store is not serving it
|
|
61
|
+
* (switched off): whatever the store still holds for it is stale and must
|
|
62
|
+
* go, so switching back on starts from the file. */
|
|
63
|
+
forget?(tenant: string, workspace?: string): void;
|
|
60
64
|
}
|
|
61
65
|
/** Register (or, with null, remove) the platform's vault store. None: files. */
|
|
62
66
|
export declare function setVaultStore(store: VaultStore | null): void;
|
|
67
|
+
/** Where a scope's vault file is (a platform store imports from it and keeps
|
|
68
|
+
* it current while files remain the fallback). */
|
|
69
|
+
export declare function vaultFilePath(tenant: string, workspace?: string): string;
|
|
70
|
+
/** A vault file's records as they are stored; {} when there is none. */
|
|
71
|
+
export declare function readVaultFile(file: string): SecretsFile;
|
|
63
72
|
/**
|
|
64
73
|
* An exclusive lock on `file` for a read-change-write, across processes and
|
|
65
74
|
* pods: `<file>.lock` opened O_EXCL (NFS 4.1 and EFS honour it), taken over
|
package/dist/src/secrets.js
CHANGED
|
@@ -208,7 +208,26 @@ function read(tenant, workspace) {
|
|
|
208
208
|
/** Change one vault scope safely, wherever it lives (see mutateVaultFile). */
|
|
209
209
|
function mutateVault(tenant, workspace, change) {
|
|
210
210
|
const store = inStore(tenant, workspace);
|
|
211
|
-
|
|
211
|
+
if (store)
|
|
212
|
+
return store.mutate(tenant, workspace, change);
|
|
213
|
+
let wrote = false;
|
|
214
|
+
const after = mutateVaultFile(secretsFile(tenant, workspace), (all) => {
|
|
215
|
+
const next = change(all);
|
|
216
|
+
wrote = next !== null;
|
|
217
|
+
return next;
|
|
218
|
+
});
|
|
219
|
+
if (wrote)
|
|
220
|
+
vaultStore?.forget?.(tenant, workspace);
|
|
221
|
+
return after;
|
|
222
|
+
}
|
|
223
|
+
/** Where a scope's vault file is (a platform store imports from it and keeps
|
|
224
|
+
* it current while files remain the fallback). */
|
|
225
|
+
export function vaultFilePath(tenant, workspace) {
|
|
226
|
+
return secretsFile(tenant, workspace);
|
|
227
|
+
}
|
|
228
|
+
/** A vault file's records as they are stored; {} when there is none. */
|
|
229
|
+
export function readVaultFile(file) {
|
|
230
|
+
return readFile(file);
|
|
212
231
|
}
|
|
213
232
|
// ------------------------------------------------------------ safe writes
|
|
214
233
|
//
|
package/package.json
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -141,6 +141,14 @@ export function mergeRuntimes(...specs: (RuntimeSpec | null | undefined)[]): Run
|
|
|
141
141
|
return merged;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* The file a platform drops in a cache entry it unpacked from its object store
|
|
146
|
+
* (foldrun-platform runtime-archives.ts), naming the archive it came from. A
|
|
147
|
+
* rebuild removes it with the rest of the entry, so "ready, and no marker" is
|
|
148
|
+
* an entry built here, which is the one worth keeping for the next sandbox.
|
|
149
|
+
*/
|
|
150
|
+
export const RUNTIME_FROM_STORE = ".from-store";
|
|
151
|
+
|
|
144
152
|
export function fingerprint(spec: RuntimeSpec): string {
|
|
145
153
|
const canonical = JSON.stringify({
|
|
146
154
|
python: spec.python ?? null,
|
|
@@ -1190,7 +1198,7 @@ FOLDRUN_SNAPSHOT_JS
|
|
|
1190
1198
|
$AS sh -c '${PRUNE_SH}' sh "$S" "${cacheDir}" 2>/dev/null
|
|
1191
1199
|
fi
|
|
1192
1200
|
fi
|
|
1193
|
-
printf '{"ok": %s, "exit": %s, "seconds": %s, "mode": "%s", "stale": %s, "packages": "%s", "refused": "%s", "unsaved": "%s"}\n' "$([ $RC -eq 0 ] && echo true || echo false)" "$RC" "$(( $(date +%s) - T0 ))" "$MODE" "$STALE" "$SYS" "$WHY" "$UNSAVED" > ${logDir}/system-install.json
|
|
1201
|
+
printf '{"ok": %s, "exit": %s, "seconds": %s, "mode": "%s", "stale": %s, "packages": "%s", "refused": "%s", "unsaved": "%s", "key": "%s"}\n' "$([ $RC -eq 0 ] && echo true || echo false)" "$RC" "$(( $(date +%s) - T0 ))" "$MODE" "$STALE" "$SYS" "$WHY" "$UNSAVED" "$KEY" > ${logDir}/system-install.json
|
|
1194
1202
|
[ -n "$W" ] && rm -rf "$W"
|
|
1195
1203
|
rm -rf /var/lib/apt/lists/* 2>/dev/null || true
|
|
1196
1204
|
fi`;
|
|
@@ -1338,7 +1346,7 @@ function prepareLanguageRuntime(tenant: string, spec: RuntimeSpec): PreparedRunt
|
|
|
1338
1346
|
if (stale || !fs.existsSync(path.join(shared, ".ready"))) {
|
|
1339
1347
|
// A clean slate: whatever a stale or half-finished build left behind is
|
|
1340
1348
|
// exactly what must not be built on top of.
|
|
1341
|
-
for (const leftover of [".ready", "venv", "node_modules", "package.json", "package-lock.json"]) {
|
|
1349
|
+
for (const leftover of [".ready", RUNTIME_FROM_STORE, "venv", "node_modules", "package.json", "package-lock.json"]) {
|
|
1342
1350
|
fs.rmSync(path.join(shared, leftover), { recursive: true, force: true });
|
|
1343
1351
|
}
|
|
1344
1352
|
}
|
package/src/secrets.ts
CHANGED
|
@@ -272,6 +272,10 @@ export interface VaultStore {
|
|
|
272
272
|
mutate(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile;
|
|
273
273
|
/** The workspaces of this account whose scope is in the store. */
|
|
274
274
|
workspaces(tenant: string): string[];
|
|
275
|
+
/** The scope's FILE was just written while the store is not serving it
|
|
276
|
+
* (switched off): whatever the store still holds for it is stale and must
|
|
277
|
+
* go, so switching back on starts from the file. */
|
|
278
|
+
forget?(tenant: string, workspace?: string): void;
|
|
275
279
|
}
|
|
276
280
|
|
|
277
281
|
let vaultStore: VaultStore | null = null;
|
|
@@ -289,7 +293,25 @@ function read(tenant: string, workspace?: string): SecretsFile {
|
|
|
289
293
|
/** Change one vault scope safely, wherever it lives (see mutateVaultFile). */
|
|
290
294
|
function mutateVault(tenant: string, workspace: string | undefined, change: (all: SecretsFile) => SecretsFile | null): SecretsFile {
|
|
291
295
|
const store = inStore(tenant, workspace);
|
|
292
|
-
|
|
296
|
+
if (store) return store.mutate(tenant, workspace, change);
|
|
297
|
+
let wrote = false;
|
|
298
|
+
const after = mutateVaultFile(secretsFile(tenant, workspace), (all) => {
|
|
299
|
+
const next = change(all);
|
|
300
|
+
wrote = next !== null;
|
|
301
|
+
return next;
|
|
302
|
+
});
|
|
303
|
+
if (wrote) vaultStore?.forget?.(tenant, workspace);
|
|
304
|
+
return after;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Where a scope's vault file is (a platform store imports from it and keeps
|
|
308
|
+
* it current while files remain the fallback). */
|
|
309
|
+
export function vaultFilePath(tenant: string, workspace?: string): string {
|
|
310
|
+
return secretsFile(tenant, workspace);
|
|
311
|
+
}
|
|
312
|
+
/** A vault file's records as they are stored; {} when there is none. */
|
|
313
|
+
export function readVaultFile(file: string): SecretsFile {
|
|
314
|
+
return readFile(file);
|
|
293
315
|
}
|
|
294
316
|
|
|
295
317
|
// ------------------------------------------------------------ safe writes
|