forgedock 1.70.0 → 1.71.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/bin/pool/agent.mjs +7 -7
- package/bin/pool/docker.mjs +4 -0
- package/bin/pool/lane-image.mjs +84 -0
- package/bin/pool/version.mjs +1 -1
- package/package.json +1 -1
- package/pool/image/Dockerfile +6 -3
package/bin/pool/agent.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { basename, dirname, join } from "node:path";
|
|
|
11
11
|
import { cpus, hostname } from "node:os";
|
|
12
12
|
import { bearerOk, call, readJson, route, sameSecret, send } from "./http.mjs";
|
|
13
13
|
import { repoRoot, versionOf, laneImageTag, laneBuildArgs } from "./version.mjs";
|
|
14
|
+
import { provideLaneImage } from "./lane-image.mjs";
|
|
14
15
|
import { jsonStore } from "./store.mjs";
|
|
15
16
|
import { makeWarm } from "./warm.mjs";
|
|
16
17
|
import { resolveLaneImage, laneImageNow, laneToolsTag, isLaneToolsTagOf } from "./lane-tools.mjs";
|
|
@@ -1060,10 +1061,10 @@ export function createAgent(cfg, { docker, now = () => Date.now(), log = console
|
|
|
1060
1061
|
if (want.image !== running.image || want.version !== running.version) {
|
|
1061
1062
|
const nextImage = cfg.image && cfg.image !== "computeshare-lane:1" ? cfg.image : laneImageTag(want.version);
|
|
1062
1063
|
log.info?.(`rebuilding ${nextImage} (${running.version}/${running.image} -> ${want.version}/${want.image})`);
|
|
1063
|
-
//
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1064
|
+
// #6166: present (pre-seeded) -> pull the published image -> local build only as the fallback
|
|
1065
|
+
const how = await provideLaneImage({ docker, image: nextImage, version: want.version, recipe: want.image, publishable: nextImage === laneImageTag(want.version), log,
|
|
1066
|
+
build: () => buildWithRetry(() => docker.build(join(next, "pool", "image"), nextImage, laneBuildArgs(want.version, want.image)), { log }) }); // #5919
|
|
1067
|
+
log.info?.(`${nextImage}: ${how}`);
|
|
1067
1068
|
}
|
|
1068
1069
|
await pruneLaneImages([laneImageTag(want.version)]);
|
|
1069
1070
|
await prepullImages();
|
|
@@ -1232,9 +1233,8 @@ export function createAgent(cfg, { docker, now = () => Date.now(), log = console
|
|
|
1232
1233
|
|
|
1233
1234
|
/** Build the lane image for the running ForgeDock version when this host does not have it yet. */
|
|
1234
1235
|
async function ensureImage() {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
await docker.build(join(cfg.code_root ?? repoRoot, "pool", "image"), image, laneBuildArgs(running.version));
|
|
1236
|
+
await provideLaneImage({ docker, image, version: running.version, recipe: running.image, publishable: image === laneImageTag(running.version), log,
|
|
1237
|
+
build: () => docker.build(join(cfg.code_root ?? repoRoot, "pool", "image"), image, laneBuildArgs(running.version, running.image)) });
|
|
1238
1238
|
await pruneLaneImages();
|
|
1239
1239
|
}
|
|
1240
1240
|
|
package/bin/pool/docker.mjs
CHANGED
|
@@ -81,6 +81,10 @@ export const dockerCli = {
|
|
|
81
81
|
return out ? out.split("\n").filter(Boolean) : [];
|
|
82
82
|
},
|
|
83
83
|
async pull(image) { return docker(["pull", "-q", image], { timeoutMs: 30 * 60000 }); },
|
|
84
|
+
/** #6166: retags a local image (the pulled ghcr.io image becomes forgedock-lane:<version>). */
|
|
85
|
+
async tag(src, dst) { return docker(["tag", src, dst], { timeoutMs: 30000 }); },
|
|
86
|
+
/** #6166: one label of a local image ("" when unset or the image is missing). */
|
|
87
|
+
async imageLabel(ref, label) { try { return await docker(["image", "inspect", "--format", `{{index .Config.Labels "${label}"}}`, ref], { timeoutMs: 20000 }); } catch { return ""; } },
|
|
84
88
|
async load(file) { return docker(["load", "-q", "-i", file], { timeoutMs: 30 * 60000 }); },
|
|
85
89
|
async hasImage(ref) { try { await docker(["image", "inspect", ref], { timeoutMs: 20000 }); return true; } catch { return false; } },
|
|
86
90
|
/** {name: {cpu (cores), mem_gb}} for running containers with the label. */
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #6166: a pool host gets the lane image by PULLING the one publish.yml built (ghcr.io), and builds locally only when the pull fails.
|
|
4
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { resolve4 } from "node:dns/promises";
|
|
6
|
+
|
|
7
|
+
export const LANE_REGISTRY_IMAGE = "ghcr.io/rapiercraftstudios/forgedock-lane";
|
|
8
|
+
/** Label the Dockerfile stamps with the recipe hash (versionOf().image); checked after a pull. */
|
|
9
|
+
export const RECIPE_LABEL = "forgedock.recipe";
|
|
10
|
+
/** Hosts dockerd contacts for a pull from ghcr.io and for a build FROM docker.io (the IPv4 pins cover exactly these). */
|
|
11
|
+
export const REGISTRY_HOSTS = ["ghcr.io", "pkg-containers.githubusercontent.com", "registry-1.docker.io", "auth.docker.io", "production.cloudflare.docker.com"];
|
|
12
|
+
/** dockerd/BuildKit dial the AAAA record and do not fall back to A (WSL mirrored networking has no IPv6 route). */
|
|
13
|
+
export const IPV6_DIAL_RE = /cannot assign requested address|network is unreachable|dial tcp \[[0-9a-f:]+\]/i;
|
|
14
|
+
const PIN_MARK = "# forgedock-ipv4-pin";
|
|
15
|
+
|
|
16
|
+
const errText = (e) => String(e?.stderr || e?.stdout || e?.message || e || "");
|
|
17
|
+
|
|
18
|
+
/** Remote ref of the lane image for a ForgeDock version. */
|
|
19
|
+
export const remoteLaneImage = (version) => `${LANE_REGISTRY_IMAGE}:${version}`;
|
|
20
|
+
/** Tag carrying the image recipe hash, pushed beside the version tag (identifies the recipe independent of a version bump). */
|
|
21
|
+
export const remoteRecipeImage = (recipe) => `${LANE_REGISTRY_IMAGE}:r-${recipe}`;
|
|
22
|
+
|
|
23
|
+
let pinDepth = 0; // concurrent pins share one /etc/hosts edit; the last one out removes it
|
|
24
|
+
/**
|
|
25
|
+
* Run `fn` with temporary /etc/hosts IPv4 pins for the registry hosts (lines tagged `# forgedock-ipv4-pin`), removed afterwards,
|
|
26
|
+
* also stale ones left by a crashed agent. Needs write access to the hosts file (the agent runs as root); throws when it has none.
|
|
27
|
+
*/
|
|
28
|
+
export async function withIpv4Pins(fn, { hosts = REGISTRY_HOSTS, file = "/etc/hosts", resolve = resolve4, log = null } = {}) {
|
|
29
|
+
const strip = (t) => t.split("\n").filter((l) => !l.includes(PIN_MARK)).join("\n");
|
|
30
|
+
if (pinDepth === 0) {
|
|
31
|
+
const lines = [];
|
|
32
|
+
for (const h of hosts) { try { const [ip] = await resolve(h); if (ip) lines.push(`${ip} ${h} ${PIN_MARK}`); } catch { /* no A record: leave that host alone */ } }
|
|
33
|
+
if (!lines.length) throw new Error("ipv4 pins: no A records resolved");
|
|
34
|
+
const cur = readFileSync(file, "utf8");
|
|
35
|
+
writeFileSync(file, `${strip(cur).replace(/\n*$/, "\n")}${lines.join("\n")}\n`);
|
|
36
|
+
log?.info?.(`pinned IPv4 for ${lines.length} registry hosts in ${file}`);
|
|
37
|
+
}
|
|
38
|
+
pinDepth++;
|
|
39
|
+
try { return await fn(); } finally {
|
|
40
|
+
if (--pinDepth === 0) { try { writeFileSync(file, strip(readFileSync(file, "utf8")).replace(/\n*$/, "\n")); } catch (e) { log?.warn?.(`could not remove IPv4 pins from ${file}: ${errText(e)}`); } }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Run `op`; on an IPv6 dial error retry it once under temporary IPv4 pins. A host that cannot pin reports the original error. */
|
|
45
|
+
export async function withIpv4Fallback(op, pinOpts = {}) {
|
|
46
|
+
try { return await op(); } catch (e) {
|
|
47
|
+
if (!IPV6_DIAL_RE.test(errText(e))) throw e;
|
|
48
|
+
pinOpts.log?.warn?.(`IPv6 dial error; retrying with IPv4 pins: ${errText(e).slice(-300)}`);
|
|
49
|
+
try { return await withIpv4Pins(op, pinOpts); } catch (e2) { if (e2 === e || IPV6_DIAL_RE.test(errText(e2))) throw e2; throw e; }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pull the published lane image, retag it as `image` and verify its recipe label equals `recipe`. Resolves true on success;
|
|
55
|
+
* a mismatched image is removed again (it must never serve lanes) and rejects.
|
|
56
|
+
*/
|
|
57
|
+
export async function pullLaneImage({ docker, image, version, recipe, log = null, pinOpts = {} }) {
|
|
58
|
+
const remote = remoteLaneImage(version);
|
|
59
|
+
await withIpv4Fallback(() => docker.pull(remote), { ...pinOpts, log });
|
|
60
|
+
const got = await docker.imageLabel(remote, RECIPE_LABEL);
|
|
61
|
+
if (got !== recipe) {
|
|
62
|
+
try { await docker.removeImage?.(remote); } catch { /* best effort */ }
|
|
63
|
+
throw new Error(`pulled ${remote} has recipe ${got || "(none)"}, want ${recipe}`);
|
|
64
|
+
}
|
|
65
|
+
await docker.tag(remote, image);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Make `image` exist locally: already present, else pulled (only the default `forgedock-lane:<version>` tag has a published
|
|
71
|
+
* counterpart), else built by `build()`. Resolves "present" | "pulled" | "built". `build` is wrapped in the IPv4 fallback too.
|
|
72
|
+
*/
|
|
73
|
+
export async function provideLaneImage({ docker, image, version, recipe, publishable = true, build, log = null, pinOpts = {} }) {
|
|
74
|
+
if (await docker.hasImage?.(image)) return "present";
|
|
75
|
+
if (publishable && recipe && docker.pull && docker.tag && docker.imageLabel) {
|
|
76
|
+
try {
|
|
77
|
+
await pullLaneImage({ docker, image, version, recipe, log, pinOpts });
|
|
78
|
+
log?.info?.(`${image} pulled from ${remoteLaneImage(version)}; no build`);
|
|
79
|
+
return "pulled";
|
|
80
|
+
} catch (e) { log?.warn?.(`pull of ${remoteLaneImage(version)} failed, building locally: ${errText(e).slice(-300)}`); }
|
|
81
|
+
}
|
|
82
|
+
await withIpv4Fallback(build, { ...pinOpts, log });
|
|
83
|
+
return "built";
|
|
84
|
+
}
|
package/bin/pool/version.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export function versionOf(root = repoRoot) {
|
|
|
25
25
|
|
|
26
26
|
/** The lane image is tagged and built from the ForgeDock package version (no separate pin). */
|
|
27
27
|
export const laneImageTag = (version) => `forgedock-lane:${version}`;
|
|
28
|
-
export const laneBuildArgs = (version) => ({ FORGEDOCK_VERSION: version });
|
|
28
|
+
export const laneBuildArgs = (version, recipe) => ({ FORGEDOCK_VERSION: version, ...(recipe ? { FORGEDOCK_RECIPE: recipe } : {}) });
|
|
29
29
|
|
|
30
30
|
/** Numeric dotted-version compare (1.10 > 1.9): negative, 0 or positive; null when either side is not a version. */
|
|
31
31
|
export function cmpVersion(a, b) {
|
package/package.json
CHANGED
package/pool/image/Dockerfile
CHANGED
|
@@ -16,7 +16,9 @@ ARG POETRY_VERSION=2.4.3
|
|
|
16
16
|
ARG YQ_VERSION=4.44.3
|
|
17
17
|
ARG PLAYWRIGHT_VERSION=1.49.1
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# Image recipe hash (versionOf().image); pool agents check it after pulling the published image (#6166).
|
|
20
|
+
ARG FORGEDOCK_RECIPE=
|
|
21
|
+
LABEL org.opencontainers.image.version=$FORGEDOCK_VERSION forgedock.recipe=$FORGEDOCK_RECIPE
|
|
20
22
|
RUN test -n "$FORGEDOCK_VERSION" || { echo "FORGEDOCK_VERSION build arg is required" >&2; exit 1; }
|
|
21
23
|
|
|
22
24
|
ENV IS_SANDBOX=1 DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 PLAYWRIGHT_BROWSERS_PATH=/opt/playwright UV_PYTHON_INSTALL_DIR=/opt/uv-python PATH=/opt/cs/bin:/opt/node/bin:/root/.local/bin:$PATH
|
|
@@ -34,8 +36,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
34
36
|
|
|
35
37
|
RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" | tar -xJ -C /opt \
|
|
36
38
|
&& mv "/opt/node-v${NODE_VERSION}-linux-x64" /opt/node \
|
|
37
|
-
&& npm install -g "corepack@${COREPACK_VERSION}" "forgedock@${FORGEDOCK_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" \
|
|
38
|
-
&& npm cache clean --force
|
|
39
|
+
&& NODE_OPTIONS=--dns-result-order=ipv4first npm install -g --include=optional "corepack@${COREPACK_VERSION}" "forgedock@${FORGEDOCK_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" \
|
|
40
|
+
&& npm cache clean --force \
|
|
41
|
+
&& claude --version && forgedock --version # smoke: a missing native binary (failed optional download) fails the build, never a lane
|
|
39
42
|
|
|
40
43
|
RUN curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" | env UV_INSTALL_DIR=/usr/local/bin sh \
|
|
41
44
|
&& uv tool install "poetry==${POETRY_VERSION}" \
|