Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/base-image-resolver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# shellcheck shell=bash

# Shared mechanics for the sandbox base-image resolver actions. Agent-specific
# candidate construction and validation intentionally remain in each action.

resolver_glibc_version() {
docker run --rm --entrypoint /usr/bin/ldd "$1" --version 2>/dev/null \
| sed -nE 's/.*GLIBC ([0-9]+\.[0-9]+).*/\1/p; s/.* ([0-9]+\.[0-9]+)$/\1/p' \
| head -n 1
}

resolver_glibc_ok() {
local have="$1" minimum="$2"
[[ -n "$have" ]] \
&& [[ "$(printf '%s\n%s\n' "$minimum" "$have" | sort -V | head -n 1)" == "$minimum" ]]
}

resolver_pull() {
docker pull "$1" >/dev/null 2>&1
}

resolver_repo_digest() {
local ref="$1" repository="$2"
docker image inspect "$ref" --format '{{range .RepoDigests}}{{println .}}{{end}}' \
| grep -F -m 1 "${repository}@sha256:"
}

resolver_try_candidates() {
local callback="$1" ref
shift
for ref in "$@"; do
if "$callback" "$ref"; then
return 0
fi
done
return 1
}

resolver_build_local() {
local dockerfile="$1" tag="$2"
docker build -f "$dockerfile" -t "$tag" .
}

resolver_write_env() {
local name="$1" value="$2"
[[ "$name" =~ ^[A-Z_][A-Z0-9_]*$ ]] || {
echo "::error::Invalid GitHub environment variable name: ${name}" >&2
return 1
}
[[ "$value" != *$'\n'* && -n "$value" ]] || {
echo "::error::Invalid empty or multiline image reference" >&2
return 1
}
printf '%s=%s\n' "$name" "$value" >>"$GITHUB_ENV"
}
43 changes: 17 additions & 26 deletions .github/actions/resolve-hermes-base-image/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ runs:

image="ghcr.io/nvidia/nemoclaw/hermes-sandbox-base"
min_glibc="2.39"

glibc_version() {
docker run --rm --entrypoint /usr/bin/ldd "$1" --version 2>/dev/null \
| sed -nE 's/.*GLIBC ([0-9]+\.[0-9]+).*/\1/p; s/.* ([0-9]+\.[0-9]+)$/\1/p' \
| head -n 1
}

glibc_ok() {
local have="$1"
[[ -n "$have" ]] && [[ "$(printf '%s\n%s\n' "$min_glibc" "$have" | sort -V | head -n 1)" == "$min_glibc" ]]
}
source "${GITHUB_ACTION_PATH}/../base-image-resolver.sh"

# Build-time package/import guard only. Authenticated HTTPS execution is
# validated by test/e2e/live/mcp-bridge.test.ts against a
Expand All @@ -51,16 +41,16 @@ runs:

try_image() {
local ref="$1" version digest_ref
if ! docker pull "$ref" >/dev/null 2>&1; then
if ! resolver_pull "$ref"; then
return 1
fi
digest_ref="$(docker image inspect "$ref" --format '{{range .RepoDigests}}{{println .}}{{end}}' | grep -F -m 1 "${image}@sha256:" || true)"
digest_ref="$(resolver_repo_digest "$ref" "$image" || true)"
if [[ -z "$digest_ref" ]]; then
echo "::warning::Hermes sandbox base image ${ref} did not expose an immutable GHCR repo digest (may be a fresh tag); building locally"
return 1
fi
version="$(glibc_version "$digest_ref" || true)"
if ! glibc_ok "$version"; then
version="$(resolver_glibc_version "$digest_ref" || true)"
if ! resolver_glibc_ok "$version" "$min_glibc"; then
echo "::warning::Hermes sandbox base image ${ref} has glibc ${version:-unknown}; need >= ${min_glibc}"
return 1
fi
Expand All @@ -72,14 +62,17 @@ runs:
echo "::warning::Hermes sandbox base image ${ref} lacks the packaged MCP Streamable HTTP client imports"
return 1
fi
echo "HERMES_BASE_IMAGE=${digest_ref}" >> "$GITHUB_ENV"
resolver_write_env HERMES_BASE_IMAGE "$digest_ref" || return 1
return 0
}

# The final Hermes Dockerfile is the trust anchor for remote base
# images. Prefer its immutable digest so a newly published, mutable
# source-SHA tag cannot outrank the reviewed pin during E2E.
mapfile -t tracked_refs < <(
tracked_refs=()
while IFS= read -r ref; do
tracked_refs+=("$ref")
done < <(
sed -nE \
's|^ARG BASE_IMAGE=(ghcr\.io/nvidia/nemoclaw/hermes-sandbox-base@sha256:[0-9a-f]{64})$|\1|p' \
agents/hermes/Dockerfile
Expand All @@ -96,16 +89,14 @@ runs:
fi
candidates+=("${image}:latest")

for ref in "${candidates[@]}"; do
if try_image "$ref"; then
exit 0
fi
done
if resolver_try_candidates try_image "${candidates[@]}"; then
exit 0
fi

echo "::warning::No compatible GHCR Hermes sandbox base image found, building locally"
docker build -f agents/hermes/Dockerfile.base -t nemoclaw-hermes-base-local .
version="$(glibc_version nemoclaw-hermes-base-local || true)"
if ! glibc_ok "$version"; then
resolver_build_local agents/hermes/Dockerfile.base nemoclaw-hermes-base-local
version="$(resolver_glibc_version nemoclaw-hermes-base-local || true)"
if ! resolver_glibc_ok "$version" "$min_glibc"; then
echo "::error::Local Hermes sandbox base image has glibc ${version:-unknown}; need >= ${min_glibc}"
exit 1
fi
Expand All @@ -117,4 +108,4 @@ runs:
echo "::error::Local Hermes sandbox base image lacks the packaged MCP Streamable HTTP client imports"
exit 1
fi
echo "HERMES_BASE_IMAGE=nemoclaw-hermes-base-local" >> "$GITHUB_ENV"
resolver_write_env HERMES_BASE_IMAGE nemoclaw-hermes-base-local
36 changes: 12 additions & 24 deletions .github/actions/resolve-sandbox-base-image/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ runs:
image="ghcr.io/nvidia/nemoclaw/sandbox-base"
min_glibc="2.39"
base_inputs=(Dockerfile.base nemoclaw-blueprint/blueprint.yaml)
source "${GITHUB_ACTION_PATH}/../base-image-resolver.sh"

normalize_version_tag() {
local raw="${1:-}" version
Expand All @@ -26,28 +27,17 @@ runs:
printf 'v%s\n' "$version"
}

glibc_version() {
docker run --rm --entrypoint /usr/bin/ldd "$1" --version 2>/dev/null \
| sed -nE 's/.*GLIBC ([0-9]+\.[0-9]+).*/\1/p; s/.* ([0-9]+\.[0-9]+)$/\1/p' \
| head -n 1
}

glibc_ok() {
local have="$1"
[[ -n "$have" ]] && [[ "$(printf '%s\n%s\n' "$min_glibc" "$have" | sort -V | head -n 1)" == "$min_glibc" ]]
}

try_image() {
local ref="$1" version
if ! docker pull "$ref" >/dev/null 2>&1; then
if ! resolver_pull "$ref"; then
return 1
fi
version="$(glibc_version "$ref" || true)"
if ! glibc_ok "$version"; then
version="$(resolver_glibc_version "$ref" || true)"
if ! resolver_glibc_ok "$version" "$min_glibc"; then
echo "::warning::Sandbox base image ${ref} has glibc ${version:-unknown}; need >= ${min_glibc}"
return 1
fi
echo "BASE_IMAGE=${ref}" >> "$GITHUB_ENV"
resolver_write_env BASE_IMAGE "$ref" || return 1
return 0
}

Expand All @@ -69,13 +59,13 @@ runs:
use_local_base() {
local version
echo "::notice::Sandbox base image inputs changed in this checkout; building Dockerfile.base locally"
docker build -f Dockerfile.base -t nemoclaw-sandbox-base-local .
version="$(glibc_version nemoclaw-sandbox-base-local || true)"
if ! glibc_ok "$version"; then
resolver_build_local Dockerfile.base nemoclaw-sandbox-base-local
version="$(resolver_glibc_version nemoclaw-sandbox-base-local || true)"
if ! resolver_glibc_ok "$version" "$min_glibc"; then
echo "::error::Local sandbox base image has glibc ${version:-unknown}; need >= ${min_glibc}"
exit 1
fi
echo "BASE_IMAGE=nemoclaw-sandbox-base-local" >> "$GITHUB_ENV"
resolver_write_env BASE_IMAGE nemoclaw-sandbox-base-local
}

candidates=()
Expand All @@ -93,11 +83,9 @@ runs:
candidates+=("${image}:${GITHUB_SHA:0:8}" "${image}:${GITHUB_SHA:0:7}")
fi

for ref in "${candidates[@]}"; do
if try_image "$ref"; then
exit 0
fi
done
if resolver_try_candidates try_image "${candidates[@]}"; then
exit 0
fi

if base_inputs_changed; then
use_local_base
Expand Down
166 changes: 166 additions & 0 deletions test/base-image-resolver-helper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";

import { afterEach, describe, expect, it } from "vitest";

import { type CompositeAction, readYaml } from "./helpers/e2e-workflow-contract";
import { execTimeout } from "./helpers/timeouts";

const repoRoot = path.resolve(import.meta.dirname, "..");
const helper = path.join(repoRoot, ".github/actions/base-image-resolver.sh");
const sandboxAction = readYaml<CompositeAction>(
".github/actions/resolve-sandbox-base-image/action.yaml",
);
const tempDirs: string[] = [];

function run(script: string, env: NodeJS.ProcessEnv = {}) {
return spawnSync("bash", ["--noprofile", "--norc", "-c", `source "$HELPER"\n${script}`], {
encoding: "utf8",
env: { ...process.env, HELPER: helper, ...env },
});
}

function fakeDocker(body: string) {
const dir = mkdtempSync(path.join(tmpdir(), "nemoclaw-base-resolver-"));
tempDirs.push(dir);
const executable = path.join(dir, "docker");
writeFileSync(executable, `#!/usr/bin/env bash\nset -eu\n${body}\n`, { mode: 0o755 });
return dir;
}

afterEach(() => {
for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});

describe("base image resolver helper (#6957)", () => {
it("executes the sandbox action and exports a compatible candidate", () => {
const bin = fakeDocker(`
if [[ "$1" == pull ]]; then exit 0; fi
if [[ "$1" == run ]]; then echo "ldd (Ubuntu GLIBC 2.39-0ubuntu8) 2.39"; exit 0; fi
exit 1`);
const githubEnv = path.join(bin, "github.env");
writeFileSync(githubEnv, "");
const resolver = sandboxAction.runs.steps.find(
(step) => step.name === "Resolve sandbox base image",
)?.run;

const result = spawnSync("bash", ["--noprofile", "--norc", "-c", resolver ?? ""], {
cwd: repoRoot,
encoding: "utf8",
timeout: execTimeout(),
env: {
...process.env,
GITHUB_ACTION_PATH: path.join(repoRoot, ".github/actions/resolve-sandbox-base-image"),
GITHUB_ENV: githubEnv,
GITHUB_SHA: "1".repeat(40),
PATH: `${bin}:${process.env.PATH}`,
},
});

expect(result.status, result.stderr).toBe(0);
expect(readFileSync(githubEnv, "utf8")).toBe(
"BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:11111111\n",
);
});

it("pulls a remote image and accepts a compatible glibc version", () => {
const bin = fakeDocker(`
if [[ "$1" == pull ]]; then exit 0; fi
if [[ "$1" == run ]]; then echo "ldd (Ubuntu GLIBC 2.39-0ubuntu8) 2.39"; exit 0; fi
exit 1`);

const result = run(
'resolver_pull example:test && version="$(resolver_glibc_version example:test)" && resolver_glibc_ok "$version" 2.39 && printf "%s" "$version"',
{ PATH: `${bin}:${process.env.PATH}` },
);

expect(result.status).toBe(0);
expect(result.stdout).toBe("2.39");
});

it("rejects an incompatible or missing glibc version", () => {
expect(run('resolver_glibc_ok "2.38" 2.39').status).not.toBe(0);
expect(run('resolver_glibc_ok "" 2.39').status).not.toBe(0);
});

it("returns only the requested repository digest", () => {
const bin = fakeDocker(`
cat <<'EOF'
other.example/base@sha256:aaaaaaaa
ghcr.io/nvidia/nemoclaw/hermes-sandbox-base@sha256:bbbbbbbb
EOF`);
const env = { PATH: `${bin}:${process.env.PATH}` };

const found = run(
"resolver_repo_digest mutable:tag ghcr.io/nvidia/nemoclaw/hermes-sandbox-base",
env,
);
const missing = run("resolver_repo_digest mutable:tag ghcr.io/nvidia/nemoclaw/missing", env);

expect(found.status).toBe(0);
expect(found.stdout.trim()).toBe("ghcr.io/nvidia/nemoclaw/hermes-sandbox-base@sha256:bbbbbbbb");
expect(missing.status).not.toBe(0);
});

it("iterates candidates through an agent-owned validator and reports exhaustion", () => {
const selected = run(`
validate() { [[ "$1" == compatible ]] && printf '%s' "$1"; }
resolver_try_candidates validate rejected compatible later`);
const exhausted = run(`
reject() { return 1; }
resolver_try_candidates reject first second`);

expect(selected.status).toBe(0);
expect(selected.stdout).toBe("compatible");
expect(exhausted.status).not.toBe(0);
});

it("builds a local fallback with the exact Dockerfile and tag", () => {
const bin = fakeDocker('printf "%s\\0" "$@" >> "$DOCKER_LOG"');
const log = path.join(bin, "docker.log");

const result = run("resolver_build_local agents/hermes/Dockerfile.base local:test", {
DOCKER_LOG: log,
PATH: `${bin}:${process.env.PATH}`,
});

expect(result.status).toBe(0);
expect(readFileSync(log, "utf8").split("\0")).toEqual([
"build",
"-f",
"agents/hermes/Dockerfile.base",
"-t",
"local:test",
".",
"",
]);
});

it("writes one validated GitHub environment assignment", () => {
const dir = mkdtempSync(path.join(tmpdir(), "nemoclaw-base-env-"));
tempDirs.push(dir);
const githubEnv = path.join(dir, "github.env");

const valid = run("resolver_write_env BASE_IMAGE ghcr.io/nvidia/nemoclaw/sandbox-base:latest", {
GITHUB_ENV: githubEnv,
});
const invalidName = run('resolver_write_env "BAD-NAME" image', { GITHUB_ENV: githubEnv });
const emptyValue = run('resolver_write_env BASE_IMAGE ""', { GITHUB_ENV: githubEnv });
const multilineValue = run("resolver_write_env BASE_IMAGE $'first\\nsecond'", {
GITHUB_ENV: githubEnv,
});

expect(valid.status).toBe(0);
expect(invalidName.status).not.toBe(0);
expect(emptyValue.status).not.toBe(0);
expect(multilineValue.status).not.toBe(0);
expect(readFileSync(githubEnv, "utf8")).toBe(
"BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest\n",
);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
});
Loading
Loading