@foldrun/core 15.1.0 → 17.0.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/a2a-publish.d.ts +7 -0
- package/dist/src/a2a-publish.js +15 -1
- package/dist/src/a2a-reach.d.ts +156 -0
- package/dist/src/a2a-reach.js +446 -0
- package/dist/src/browse-egress.d.ts +1 -1
- package/dist/src/browse-egress.js +7 -6
- package/dist/src/egress.d.ts +9 -0
- package/dist/src/env-names.d.ts +12 -0
- package/dist/src/env-names.js +49 -0
- package/dist/src/failure.d.ts +92 -0
- package/dist/src/failure.js +294 -0
- package/dist/src/frontmatter-fields.js +1 -1
- package/dist/src/install-helper.js +10 -5
- package/dist/src/network.js +1 -1
- package/dist/src/ops-log.js +4 -0
- package/dist/src/otel.d.ts +16 -1
- package/dist/src/otel.js +121 -5
- package/dist/src/platform.d.ts +8 -0
- package/dist/src/run-container.d.ts +88 -4
- package/dist/src/run-container.js +215 -26
- package/dist/src/run-event.d.ts +179 -0
- package/dist/src/run-event.js +473 -0
- package/dist/src/runner.js +35 -1
- package/dist/src/runtime.d.ts +116 -16
- package/dist/src/runtime.js +531 -44
- package/dist/src/scan.js +80 -18
- package/dist/src/search-egress.d.ts +58 -0
- package/dist/src/search-egress.js +88 -0
- package/dist/src/starter.js +4 -1
- package/dist/src/store.d.ts +34 -3
- package/dist/src/store.js +46 -10
- package/package.json +2 -1
- package/src/a2a-publish.ts +19 -1
- package/src/a2a-reach.ts +503 -0
- package/src/browse-egress.ts +8 -7
- package/src/egress.ts +7 -0
- package/src/env-names.ts +53 -0
- package/src/failure.ts +368 -0
- package/src/frontmatter-fields.ts +1 -1
- package/src/install-helper.ts +10 -5
- package/src/network.ts +1 -1
- package/src/ops-log.ts +4 -0
- package/src/otel.ts +122 -7
- package/src/platform.ts +8 -0
- package/src/run-container.ts +228 -29
- package/src/run-event.ts +563 -0
- package/src/runner.ts +32 -1
- package/src/runtime.ts +546 -45
- package/src/scan.ts +91 -20
- package/src/search-egress.ts +116 -0
- package/src/starter.ts +4 -1
- package/src/store.ts +75 -12
package/src/run-container.ts
CHANGED
|
@@ -33,8 +33,8 @@ import { divertedSummary, isDivertedPath, overlayTestWrites } from "./test-mode.
|
|
|
33
33
|
import { refusedBack, refusedLine, keptLine, type RefusedPath } from "./copy-back.ts";
|
|
34
34
|
import type { CallIo, EventExtra, ExecUsage } from "./step-exec.ts";
|
|
35
35
|
import type { TokenPrice } from "./catalog.ts";
|
|
36
|
-
import { isFileValue, fileContent } from "./secrets.ts";
|
|
37
|
-
import { safeTenantSegment, systemInstallSh, SYSTEM_FROM_INPUT_SH, INSTALL_SOCKET, type RuntimeSpec } from "./runtime.ts";
|
|
36
|
+
import { isFileValue, fileContent, installKeyMaterial } from "./secrets.ts";
|
|
37
|
+
import { safeTenantSegment, systemInstallSh, SYSTEM_FROM_INPUT_SH, INSTALL_SOCKET, ROOT_ENV_RESET_SH, ROOT_SHELL_GUARD_SH, ROOT_ENV_FILE, STEP_ENV_FILE, stepEnvShell, rootEnvShell, SNAPSHOT_KEY_FILE, type RuntimeSpec } from "./runtime.ts";
|
|
38
38
|
import { egressCaSh, type NetworkLevel } from "./network.ts";
|
|
39
39
|
import { anyMemoryMi, quantityMi, type ResourceOverride } from "./resources.ts";
|
|
40
40
|
import type { ScriptSpec } from "./script-tools.ts";
|
|
@@ -152,6 +152,10 @@ export interface StepTiming {
|
|
|
152
152
|
* from an executor that marks none, and from a resumed driver (the
|
|
153
153
|
* first driver's phases are on the record already). */
|
|
154
154
|
phases?: StartupPhases;
|
|
155
|
+
/** When the phases count from: the epoch ms the executor began the step
|
|
156
|
+
* (FOL-122) — what places them on the clock (StepRecord.startupAt). Set
|
|
157
|
+
* beside `phases` only. */
|
|
158
|
+
origin?: number;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
/** The start-up phases and what each marks — startup.ts, where every
|
|
@@ -609,10 +613,88 @@ export const RUNTIME_CACHE = "/home/agent/.foldrun/runner/.runtimes";
|
|
|
609
613
|
/** Starts the install helper as root, in the background, before the drop to
|
|
610
614
|
* the agent user: the root half of the `install` tool (install-helper.ts).
|
|
611
615
|
* The agent reaches it only through the socket; it installs only validated
|
|
612
|
-
* Debian package names, and dies with the container.
|
|
616
|
+
* Debian package names, and dies with the container.
|
|
617
|
+
* @deprecated the start-ups use rootStartSh, which starts the helper in a
|
|
618
|
+
* clean environment with the snapshot key's path (FOL-129). */
|
|
613
619
|
export const INSTALL_HELPER_SH = `FOLDRUN_INSTALL_SOCKET=${INSTALL_SOCKET}; export FOLDRUN_INSTALL_SOCKET
|
|
614
620
|
node /opt/runner/node_modules/@foldrun/core/dist/src/install-helper.js "$FOLDRUN_INSTALL_SOCKET" ${RUNTIME_CACHE} >/dev/null 2>&1 &`;
|
|
615
621
|
|
|
622
|
+
/**
|
|
623
|
+
* The account's key for sealing its `runtime: system:` snapshots (FOL-129):
|
|
624
|
+
* derived from the install key, so it needs no store and no rotation of its
|
|
625
|
+
* own, and per account, so one account's key seals nothing for another. The
|
|
626
|
+
* worker stages it as the step's SNAPSHOT_KEY_FILE; null (no tenant, or a
|
|
627
|
+
* process without the install key) means the step gets no snapshots.
|
|
628
|
+
*/
|
|
629
|
+
export function aptSnapshotKey(tenant: string | undefined | null): string | null {
|
|
630
|
+
if (!tenant) return null;
|
|
631
|
+
try {
|
|
632
|
+
return crypto.createHmac("sha256", installKeyMaterial()).update(`foldrun apt snapshot v1\0${tenant}`).digest("hex");
|
|
633
|
+
} catch {
|
|
634
|
+
return null;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Root's part of a run container's start-up, before the chown and the drop
|
|
640
|
+
* to the agent user (k8s SHIM, docker ENTRY): the snapshot key moved where
|
|
641
|
+
* only root can read it, then — in a subshell whose environment is the root
|
|
642
|
+
* shell's own plus the proxy's variables (ROOT_ENV_FILE), reset to those
|
|
643
|
+
* alone (ROOT_ENV_RESET_SH) — the declared system packages and the install
|
|
644
|
+
* helper. The key never enters an environment: root's commands and the
|
|
645
|
+
* helper get only its path, and the copy in the job folder (which is chowned
|
|
646
|
+
* to the agent next) is gone before the subshell ends, or the start-up stops.
|
|
647
|
+
*
|
|
648
|
+
* The step's own environment (STEP_ENV_FILE) is never read here (FOL-130):
|
|
649
|
+
* its names are the account's to choose, and an LD_PRELOAD or PATH there
|
|
650
|
+
* pointing into the agent-writable cache would run the agent's code as root.
|
|
651
|
+
* ROOT_ENV_FILE is the worker's cut of it to ROOT_ENV_NAMES, sourced before
|
|
652
|
+
* the reset so even a name that should not be there is unset again; the
|
|
653
|
+
* socket and the locale are set after it, so nothing read can move them.
|
|
654
|
+
*/
|
|
655
|
+
export function rootStartSh(cacheDir: string = RUNTIME_CACHE): string {
|
|
656
|
+
return `FOLDRUN_INSTALL_SOCKET=${INSTALL_SOCKET}; export FOLDRUN_INSTALL_SOCKET
|
|
657
|
+
(
|
|
658
|
+
if [ -f ${ROOT_ENV_FILE} ] && [ ! -L ${ROOT_ENV_FILE} ]; then . ${ROOT_ENV_FILE}; fi
|
|
659
|
+
${ROOT_ENV_RESET_SH}
|
|
660
|
+
FOLDRUN_INSTALL_SOCKET=${INSTALL_SOCKET} LANG=C.UTF-8 LC_ALL=C.UTF-8; export FOLDRUN_INSTALL_SOCKET LANG LC_ALL
|
|
661
|
+
unset FOLDRUN_SNAP_KEY_FILE; FOLDRUN_SNAP_KEY_FILE=""
|
|
662
|
+
if [ -e ${SNAPSHOT_KEY_FILE} ] || [ -L ${SNAPSHOT_KEY_FILE} ]; then
|
|
663
|
+
_fk=$(mktemp -d /tmp/.foldrun-key.XXXXXX 2>/dev/null) && [ ! -L ${SNAPSHOT_KEY_FILE} ] && cat ${SNAPSHOT_KEY_FILE} > "$_fk/key" 2>/dev/null && FOLDRUN_SNAP_KEY_FILE=$_fk/key
|
|
664
|
+
rm -f ${SNAPSHOT_KEY_FILE}
|
|
665
|
+
fi
|
|
666
|
+
${SYSTEM_FROM_INPUT_SH}
|
|
667
|
+
${systemInstallSh(cacheDir)}
|
|
668
|
+
FOLDRUN_SNAP_KEY_FILE="$FOLDRUN_SNAP_KEY_FILE" node /opt/runner/node_modules/@foldrun/core/dist/src/install-helper.js "$FOLDRUN_INSTALL_SOCKET" ${cacheDir} >/dev/null 2>&1 &
|
|
669
|
+
)
|
|
670
|
+
if [ -e ${SNAPSHOT_KEY_FILE} ] || [ -L ${SNAPSHOT_KEY_FILE} ]; then echo "the snapshot key could not be removed from the job folder — not starting the step" >&2; exit 1; fi`;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* The drop to the agent user, and the only place the step's environment is
|
|
675
|
+
* read (FOL-130): runuser starts with the root shell's own environment — the
|
|
676
|
+
* image's and the pod spec's, which ROOT_SHELL_GUARD_SH has already cleaned —
|
|
677
|
+
* and the agent's shell then sources STEP_ENV_FILE, sets up the egress
|
|
678
|
+
* proxy's CA (which root never needs: apt goes through the proxy unopened),
|
|
679
|
+
* and execs `command`, so its exit status is the step's.
|
|
680
|
+
*
|
|
681
|
+
* What the agent ends with is what it had when root sourced the file before
|
|
682
|
+
* the drop: the step's names over the root shell's, the CA's variables over
|
|
683
|
+
* those, runuser's HOME/USER/LOGNAME over all (kept in positional
|
|
684
|
+
* parameters, which no sourced name can reach), and the install socket at
|
|
685
|
+
* its fixed path. No `set -e`: an egress CA that cannot be written leaves
|
|
686
|
+
* the step without it, as before, rather than stopping it.
|
|
687
|
+
*/
|
|
688
|
+
export function agentStartSh(command = "node /opt/runner/driver.mjs"): string {
|
|
689
|
+
const inner = `set -- "$HOME" "$USER" "$LOGNAME"
|
|
690
|
+
set -a; if [ -f ${STEP_ENV_FILE} ]; then . ${STEP_ENV_FILE}; fi; set +a
|
|
691
|
+
HOME=$1 USER=$2 LOGNAME=$3; export HOME USER LOGNAME; shift 3
|
|
692
|
+
FOLDRUN_INSTALL_SOCKET=${INSTALL_SOCKET}; export FOLDRUN_INSTALL_SOCKET
|
|
693
|
+
${egressCaSh("/opt/runner/job")}
|
|
694
|
+
exec ${command}`;
|
|
695
|
+
return `runuser -u agent -- /bin/sh -c '${inner.replaceAll("'", `'\\''`)}'`;
|
|
696
|
+
}
|
|
697
|
+
|
|
616
698
|
/**
|
|
617
699
|
* Where the platform's shared runtime layer is mounted, read-only, in a run
|
|
618
700
|
* pod — and read-write, one entry at a time, in the pod that builds an entry
|
|
@@ -1035,7 +1117,7 @@ export const RETRY_SH = `retry() { what=$1; shift; n=1; until "$@"; do if [ "$n"
|
|
|
1035
1117
|
* RCE, TLS hostname bypasses); the pin before carried 22.23.3. */
|
|
1036
1118
|
export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173bffab391592812e85136452f781741c7242ddf";
|
|
1037
1119
|
|
|
1038
|
-
// Two images from one file, as build targets.
|
|
1120
|
+
// Two images from one file, as build targets, in two parts.
|
|
1039
1121
|
//
|
|
1040
1122
|
// full (the default, the last stage) — everything, browsers included. The
|
|
1041
1123
|
// per-account browser pod runs it, and so does any step that may
|
|
@@ -1048,10 +1130,44 @@ export const NODE_BASE = "node:22-trixie-slim@sha256:8eb619e402eaede1748a3c8173b
|
|
|
1048
1130
|
// (run-k8s.ts picks), and its declared packages arrive at run time
|
|
1049
1131
|
// through the runtime cache — uv is in the base for exactly that.
|
|
1050
1132
|
//
|
|
1133
|
+
// The parts (FOL-50, 5 Nov 2026):
|
|
1134
|
+
//
|
|
1135
|
+
// the OS RUNNER_OS_DOCKERFILE: Debian, every apt package, uv, the
|
|
1136
|
+
// Playwright client and, for full, the browsers (Google's Chrome
|
|
1137
|
+
// included). Targets `slim-os` and `browsers`. Everything that
|
|
1138
|
+
// writes /var/lib/dpkg/status is here and nowhere else.
|
|
1139
|
+
// the app core and the driver on top (CORE_STAGE, CORE_INSTALL): files
|
|
1140
|
+
// only, no apt.
|
|
1141
|
+
//
|
|
1142
|
+
// Built together (runnerDockerfile() — a laptop, a self-hoster, images.yml)
|
|
1143
|
+
// it is one image as before. The hosted platform builds the OS part on its
|
|
1144
|
+
// own as the runner BASE image, pins it by digest (foldrun-infra
|
|
1145
|
+
// images/runner-base.env, refreshed weekly and at once for a fixable critical
|
|
1146
|
+
// vulnerability) and builds the app part FROM it (FOLDRUN_RUNNER_BASE_SLIM /
|
|
1147
|
+
// _FULL). A release that changes only foldrun's code then keeps the base's
|
|
1148
|
+
// bytes, so the dpkg status a `runtime: system:` snapshot was built on is
|
|
1149
|
+
// still there after the deploy (runtime.ts systemInstallSh) — rebuilding the
|
|
1150
|
+
// OS on every core change moved Chrome, the apt index and every package's
|
|
1151
|
+
// status line, and each release cost each package set a full apt install.
|
|
1152
|
+
//
|
|
1051
1153
|
// The browsers sit BELOW the core install in `full`, as they always have,
|
|
1052
1154
|
// so a core change rebuilds one thin layer and not 1.4 GB of Chromium.
|
|
1053
|
-
|
|
1155
|
+
|
|
1156
|
+
/** Stands for the OS definition's id inside its own text: the id is the
|
|
1157
|
+
* sha256 of the text with this in place, then substituted in. */
|
|
1158
|
+
const OS_ID_SLOT = "@@FOLDRUN_RUNNER_OS@@";
|
|
1159
|
+
/** The end of each OS target: which definition built it, as a label and as
|
|
1160
|
+
* a file the app part checks (OS_GUARD). Not under /var/lib/dpkg. */
|
|
1161
|
+
const OS_MARK = `LABEL io.foldrun.runner-os=${OS_ID_SLOT}
|
|
1162
|
+
RUN echo ${OS_ID_SLOT} > /etc/foldrun-runner-os`;
|
|
1163
|
+
|
|
1164
|
+
const OS_TEMPLATE = `FROM ${NODE_BASE} AS base
|
|
1165
|
+
# upgrade: node's image lags Debian security (the platform images learnt it
|
|
1166
|
+
# on 6 Oct 2026, perl-base), and the hosted runner's base is rebuilt weekly
|
|
1167
|
+
# precisely so those fixes arrive; without it a refresh changed nothing the
|
|
1168
|
+
# node image already carried.
|
|
1054
1169
|
RUN apt-get update \\
|
|
1170
|
+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y --no-install-recommends \\
|
|
1055
1171
|
&& apt-get install -y --no-install-recommends python3 python3-venv ca-certificates bash util-linux tar openssh-client sshpass git curl \\
|
|
1056
1172
|
&& rm -rf /var/lib/apt/lists/* \\
|
|
1057
1173
|
&& useradd -m -u 10001 agent
|
|
@@ -1060,8 +1176,7 @@ RUN apt-get update \\
|
|
|
1060
1176
|
COPY --from=ghcr.io/astral-sh/uv:${UV_VERSION} /uv /uvx /usr/local/bin/
|
|
1061
1177
|
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/browser NODE_PATH=/usr/local/lib/node_modules
|
|
1062
1178
|
|
|
1063
|
-
|
|
1064
|
-
FROM base AS slim
|
|
1179
|
+
FROM base AS slim-os
|
|
1065
1180
|
# Fonts, because a step that draws text without a browser still needs them:
|
|
1066
1181
|
# the full image gets 51 from Playwright's --with-deps, slim had none, so from
|
|
1067
1182
|
# 2026-09-29 (when non-browsing steps moved to slim) every resvg/sharp diagram
|
|
@@ -1087,7 +1202,8 @@ RUN apt-get update \\
|
|
|
1087
1202
|
# npm's download cache is dropped in the same layer: it was 190 MB of every
|
|
1088
1203
|
# image, read by nothing after the build.
|
|
1089
1204
|
RUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null && npm cache clean --force >/dev/null 2>&1
|
|
1090
|
-
${
|
|
1205
|
+
${OS_MARK}
|
|
1206
|
+
|
|
1091
1207
|
FROM base AS browsers
|
|
1092
1208
|
# Real browsers, because directories and portals increasingly render with
|
|
1093
1209
|
# JavaScript and a plain fetch sees only the empty shell. Chromium is the one the
|
|
@@ -1212,26 +1328,91 @@ RUN node -e ' \\
|
|
|
1212
1328
|
if (missing.length) console.error("runner image: built without " + missing.join(", ") + " on " + arch); \\
|
|
1213
1329
|
' \\
|
|
1214
1330
|
&& chmod a+r /opt/browser/engines.json
|
|
1331
|
+
${OS_MARK}
|
|
1332
|
+
`;
|
|
1333
|
+
|
|
1334
|
+
/** Which definition of the OS part this core holds: 16 hex of the sha256 of
|
|
1335
|
+
* its text. A base image carries it (label io.foldrun.runner-os and
|
|
1336
|
+
* /etc/foldrun-runner-os); a base from another definition is refused. */
|
|
1337
|
+
export const RUNNER_OS_ID = crypto.createHash("sha256").update(OS_TEMPLATE).digest("hex").slice(0, 16);
|
|
1338
|
+
|
|
1339
|
+
/** The runner's OS part on its own — what the base image is built from
|
|
1340
|
+
* (targets RUNNER_OS_TARGETS). No build context: it copies nothing local. */
|
|
1341
|
+
export const RUNNER_OS_DOCKERFILE = OS_TEMPLATE.split(OS_ID_SLOT).join(RUNNER_OS_ID);
|
|
1342
|
+
|
|
1343
|
+
/** The OS part's build target for each runner variant. */
|
|
1344
|
+
export const RUNNER_OS_TARGETS = { slim: "slim-os", full: "browsers" } as const;
|
|
1345
|
+
|
|
1346
|
+
/** The app part's first word in both variants: the OS under it is the one
|
|
1347
|
+
* this core's text describes. A base built from an older definition (a
|
|
1348
|
+
* Playwright bump, a new apt package) would otherwise ship a runner whose
|
|
1349
|
+
* browsers or packages are not the ones its core expects. */
|
|
1350
|
+
const OS_GUARD = `RUN test "$(cat /etc/foldrun-runner-os 2>/dev/null)" = "${RUNNER_OS_ID}" \\
|
|
1351
|
+
|| { echo "runner image: its base was built from another definition (wants ${RUNNER_OS_ID}, has $(cat /etc/foldrun-runner-os 2>/dev/null || echo none)) - build the base again: bash foldrun-infra/dev/ci/runner-base.sh refresh" >&2; exit 1; }`;
|
|
1352
|
+
|
|
1353
|
+
/** The base images a runner is built FROM, by digest, one per variant. */
|
|
1354
|
+
export type RunnerBase = { slim: string; full: string };
|
|
1355
|
+
|
|
1356
|
+
const BASE_REF = /^[a-z0-9][a-z0-9._/:-]*@sha256:[0-9a-f]{64}$/;
|
|
1215
1357
|
|
|
1358
|
+
/**
|
|
1359
|
+
* The runner base from FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL:
|
|
1360
|
+
* both or neither (empty counts as unset, as FOLDRUN_RUNNER_IMAGE does), each
|
|
1361
|
+
* an image by digest — a tag would let the same runner tag hold another
|
|
1362
|
+
* base's bytes. Anything else throws: a half-set base is a broken deploy,
|
|
1363
|
+
* not a reason to quietly build the OS again.
|
|
1364
|
+
*/
|
|
1365
|
+
export function runnerBase(env: NodeJS.ProcessEnv = process.env): RunnerBase | null {
|
|
1366
|
+
const slim = env.FOLDRUN_RUNNER_BASE_SLIM ?? "";
|
|
1367
|
+
const full = env.FOLDRUN_RUNNER_BASE_FULL ?? "";
|
|
1368
|
+
if (!slim && !full) return null;
|
|
1369
|
+
if (!slim || !full) {
|
|
1370
|
+
throw new Error("FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL go together: set both (the base's two images, by digest) or neither");
|
|
1371
|
+
}
|
|
1372
|
+
for (const [k, v] of [["FOLDRUN_RUNNER_BASE_SLIM", slim], ["FOLDRUN_RUNNER_BASE_FULL", full]] as const) {
|
|
1373
|
+
if (!BASE_REF.test(v)) throw new Error(`${k} must name an image by digest (name@sha256:<64 hex>), not ${JSON.stringify(v.slice(0, 120))}`);
|
|
1374
|
+
}
|
|
1375
|
+
return { slim, full };
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* The runner's Dockerfile: with no base, the OS part and the app part in one
|
|
1380
|
+
* file (a self-contained build); with one, the app part FROM the base's two
|
|
1381
|
+
* images. The app part's text is the same either way.
|
|
1382
|
+
*/
|
|
1383
|
+
export function runnerDockerfile(base: RunnerBase | null = null): string {
|
|
1384
|
+
const os = base
|
|
1385
|
+
? `FROM ${base.slim} AS slim-os\nFROM ${base.full} AS browsers\nFROM slim-os AS base\n`
|
|
1386
|
+
: RUNNER_OS_DOCKERFILE;
|
|
1387
|
+
return `${os}
|
|
1388
|
+
${CORE_STAGE}
|
|
1389
|
+
FROM slim-os AS slim
|
|
1390
|
+
${OS_GUARD}
|
|
1391
|
+
${CORE_INSTALL}
|
|
1216
1392
|
FROM browsers AS full
|
|
1393
|
+
${OS_GUARD}
|
|
1217
1394
|
${CORE_INSTALL}`;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/** The self-contained runner Dockerfile (no base): runnerDockerfile(). */
|
|
1398
|
+
export const DOCKERFILE = runnerDockerfile();
|
|
1218
1399
|
|
|
1219
1400
|
// runtime: system: — apt as root, before the drop (runtime.ts systemInstallSh).
|
|
1220
1401
|
// set -e is off around it: a failed install is reported by the driver, which
|
|
1221
1402
|
// reads the status file and fails the step with apt's own words.
|
|
1222
|
-
|
|
1403
|
+
/** The docker run container's entrypoint (entry.sh), exported for its tests. */
|
|
1404
|
+
export const ENTRY = `#!/bin/sh
|
|
1223
1405
|
set +e
|
|
1224
|
-
${
|
|
1225
|
-
${SYSTEM_FROM_INPUT_SH}
|
|
1226
|
-
${systemInstallSh(RUNTIME_CACHE)}
|
|
1227
|
-
${INSTALL_HELPER_SH}
|
|
1228
|
-
set -e
|
|
1229
|
-
chown -R agent:agent /workspace /library /opt/runner/job
|
|
1406
|
+
${ROOT_SHELL_GUARD_SH}
|
|
1230
1407
|
# The runtime cache, when one is mounted. NOT recursive: a warm cache is tens
|
|
1231
1408
|
# of thousands of files and its contents are already agent-owned from the step
|
|
1232
|
-
# that built them — only the mount point itself arrives owned by root.
|
|
1409
|
+
# that built them — only the mount point itself arrives owned by root. Before
|
|
1410
|
+
# the system install: root works in the cache as the agent user (FOL-129).
|
|
1233
1411
|
chown agent:agent ${RUNTIME_CACHE} 2>/dev/null || true
|
|
1234
|
-
|
|
1412
|
+
${rootStartSh(RUNTIME_CACHE)}
|
|
1413
|
+
set -e
|
|
1414
|
+
chown -R agent:agent /workspace /library /opt/runner/job
|
|
1415
|
+
exec ${agentStartSh()}
|
|
1235
1416
|
`;
|
|
1236
1417
|
|
|
1237
1418
|
function corePackageDir(): string {
|
|
@@ -1260,7 +1441,9 @@ export function runnerImageTag(variant: RunnerVariant = "full"): string {
|
|
|
1260
1441
|
// The fingerprint hashes the *built code*, not the version — a version
|
|
1261
1442
|
// string that nobody bumped would pin every future run to the runner
|
|
1262
1443
|
// image of whatever core happened to build first.
|
|
1263
|
-
|
|
1444
|
+
// The Dockerfile as it will be built — with the base's digests in it when
|
|
1445
|
+
// one is set, so a new base is a new tag.
|
|
1446
|
+
const hash = crypto.createHash("sha256").update(DRIVER + "\n" + runnerDockerfile(runnerBase()) + "\n" + ENTRY);
|
|
1264
1447
|
const dist = path.join(corePackageDir(), "dist");
|
|
1265
1448
|
if (fs.existsSync(dist)) {
|
|
1266
1449
|
for (const entry of fs.readdirSync(dist, { recursive: true }).sort()) {
|
|
@@ -1309,6 +1492,12 @@ export function ensureRunnerImage(
|
|
|
1309
1492
|
const { tag, explicit } = runnerImageRef(opts);
|
|
1310
1493
|
const log: string[] = [];
|
|
1311
1494
|
if (explicit) return { tag, log };
|
|
1495
|
+
const base = runnerBase();
|
|
1496
|
+
// A base is one platform's images (the hosted base is linux/amd64): a
|
|
1497
|
+
// cross-build on it would pull the wrong arch or none.
|
|
1498
|
+
if (base && opts.platform) {
|
|
1499
|
+
throw new Error(`a runner base names one platform's images: unset FOLDRUN_RUNNER_BASE_SLIM and FOLDRUN_RUNNER_BASE_FULL to build for ${opts.platform}`);
|
|
1500
|
+
}
|
|
1312
1501
|
|
|
1313
1502
|
const have = spawnSync(cli(), ["image", "inspect", tag], { stdio: "ignore" });
|
|
1314
1503
|
if (have.status === 0) return { tag, log };
|
|
@@ -1323,8 +1512,9 @@ export function ensureRunnerImage(
|
|
|
1323
1512
|
fs.renameSync(path.join(build, tarball), path.join(build, "foldrun-core.tgz"));
|
|
1324
1513
|
fs.writeFileSync(path.join(build, "driver.mjs"), DRIVER);
|
|
1325
1514
|
fs.writeFileSync(path.join(build, "entry.sh"), ENTRY);
|
|
1326
|
-
|
|
1327
|
-
|
|
1515
|
+
// The same text the tag hashed (runnerImageTag), base and all.
|
|
1516
|
+
fs.writeFileSync(path.join(build, "Dockerfile"), runnerDockerfile(base));
|
|
1517
|
+
log.push(`building runner image ${tag} (first run only)${base ? ` on base ${base.full.split("@")[1].slice(7, 19)}` : ""}`);
|
|
1328
1518
|
const args = [
|
|
1329
1519
|
"build",
|
|
1330
1520
|
...(opts.platform ? ["--platform", opts.platform] : []),
|
|
@@ -1659,8 +1849,10 @@ export interface WriteDivert {
|
|
|
1659
1849
|
/**
|
|
1660
1850
|
* What crosses into the container as its environment, and how.
|
|
1661
1851
|
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
1852
|
+
* It crosses as a file the agent's shell sources after the drop (env.sh,
|
|
1853
|
+
* FOL-130); until then it was a docker --env-file, one `KEY=value` per
|
|
1854
|
+
* line, which cannot carry a newline — and what a step sees stays the shape
|
|
1855
|
+
* that file set. @file secrets are multi-line by nature (a PEM key, a cert), so
|
|
1664
1856
|
* they are staged as files NOW, into the copied-in workspace, and the env
|
|
1665
1857
|
* carries the container path — the one place a path is stable across the
|
|
1666
1858
|
* boundary. A plain secret whose value happens to hold a newline gets the
|
|
@@ -1868,15 +2060,19 @@ export async function runStepInContainer(args: RunInContainerArgs): Promise<Cont
|
|
|
1868
2060
|
const jobIn = path.join(staging, "job");
|
|
1869
2061
|
fs.mkdirSync(jobIn);
|
|
1870
2062
|
fs.writeFileSync(path.join(jobIn, "input.json"), JSON.stringify(args.input, null, 2));
|
|
2063
|
+
// The account's snapshot key, for root's start-up alone (rootStartSh
|
|
2064
|
+
// moves it out of the agent's reach before the drop) — FOL-129.
|
|
2065
|
+
const snapKey = aptSnapshotKey(args.tenant);
|
|
2066
|
+
if (snapKey) fs.writeFileSync(path.join(jobIn, "snapshot.key"), snapKey, { mode: 0o600 });
|
|
1871
2067
|
|
|
1872
2068
|
const containerEnv = stageContainerEnv(args.env, wsIn, args.input.agentRel, args.emit);
|
|
1873
2069
|
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
);
|
|
2070
|
+
// Files in the job folder, not the container's environment (FOL-130): a
|
|
2071
|
+
// docker --env-file is PID 1's environment, so a secret named LD_PRELOAD
|
|
2072
|
+
// reached the root shell before its first line. The agent's shell sources
|
|
2073
|
+
// env.sh after the drop; root's start-up reads only the proxy's lines.
|
|
2074
|
+
fs.writeFileSync(path.join(jobIn, "env.sh"), stepEnvShell(containerEnv), { mode: 0o600 });
|
|
2075
|
+
fs.writeFileSync(path.join(jobIn, "root-env.sh"), rootEnvShell(containerEnv), { mode: 0o600 });
|
|
1880
2076
|
|
|
1881
2077
|
const lim = args.limits ?? resolveResources(args.size);
|
|
1882
2078
|
const cpus = dockerCpus(lim.cpus);
|
|
@@ -1894,7 +2090,6 @@ export async function runStepInContainer(args: RunInContainerArgs): Promise<Cont
|
|
|
1894
2090
|
// the whole machine from the steps beside it.
|
|
1895
2091
|
"--memory", dockerMemory(lim.memory),
|
|
1896
2092
|
...(cpus ? ["--cpus", cpus] : []),
|
|
1897
|
-
"--env-file", envFile,
|
|
1898
2093
|
];
|
|
1899
2094
|
// gVisor (or kata) where the host has it: one env var, because the flag
|
|
1900
2095
|
// is the same docker invocation everywhere else.
|
|
@@ -1947,6 +2142,9 @@ export async function runStepInContainer(args: RunInContainerArgs): Promise<Cont
|
|
|
1947
2142
|
cp(`${wsIn}/.`, `${containerId}:/workspace`);
|
|
1948
2143
|
cp(`${libIn}/.`, `${containerId}:/library`);
|
|
1949
2144
|
cp(`${jobIn}/input.json`, `${containerId}:/opt/runner/job/input.json`);
|
|
2145
|
+
cp(`${jobIn}/env.sh`, `${containerId}:${STEP_ENV_FILE}`);
|
|
2146
|
+
cp(`${jobIn}/root-env.sh`, `${containerId}:${ROOT_ENV_FILE}`);
|
|
2147
|
+
if (snapKey) cp(`${jobIn}/snapshot.key`, `${containerId}:${SNAPSHOT_KEY_FILE}`);
|
|
1950
2148
|
phases.files = Date.now() - t0;
|
|
1951
2149
|
|
|
1952
2150
|
// Start attached and read the driver's JSONL. The step timeout gets a
|
|
@@ -2032,6 +2230,7 @@ export async function runStepInContainer(args: RunInContainerArgs): Promise<Cont
|
|
|
2032
2230
|
firstOutputMs: firstOutputAt === null ? null : firstOutputAt - t0 - sandboxMs,
|
|
2033
2231
|
totalMs: Date.now() - t0,
|
|
2034
2232
|
phases,
|
|
2233
|
+
origin: t0,
|
|
2035
2234
|
};
|
|
2036
2235
|
args.emit("info", timingLine(timing));
|
|
2037
2236
|
return { ...outcome, timing, applied, ...(refused.length ? { refused } : {}) };
|