diff --git a/.github/workflows/hermes-01x-image-verify.yaml b/.github/workflows/hermes-01x-image-verify.yaml new file mode 100644 index 00000000000..bea2406fab2 --- /dev/null +++ b/.github/workflows/hermes-01x-image-verify.yaml @@ -0,0 +1,134 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Build the Hermes image for OpenShell 0.1.x from agents/hermes-01x on native +# amd64 and arm64 runners without publishing it (derekhsu/NemoClaw#98). +# hermes-01x-image.yaml builds and publishes the same Dockerfiles. +# +# The job has a read-only token, no registry login, and no secrets, so it +# cannot push an image. The base image is exported to an OCI layout, checked, +# and passed to the final build as a named build context. This is the same +# method as the Hermes PR build in managed-images.yaml. + +name: Images / Hermes OpenShell 0.1.x Verify + +on: + pull_request: + branches: + - feat/image-only-cli + paths: + - agents/hermes-01x/** + - "!agents/hermes-01x/Dockerfile.tools" + - src/lib/sandbox-base-image/** + - scripts/security/** + - scripts/checks/resolve-hermes-pr-source-base.sh + - scripts/check-production-build-args.sh + - scripts/check-image-layer-count.sh + - .github/workflows/hermes-01x-image-verify.yaml + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: hermes-01x-image-verify-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Verify ${{ matrix.arch }} + if: github.repository == 'derekhsu/NemoClaw' + runs-on: ${{ matrix.runner }} + timeout-minutes: 120 + strategy: + fail-fast: false + matrix: + include: + - arch: amd64 + runner: ubuntu-24.04 + - arch: arm64 + runner: ubuntu-24.04-arm + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # The two OCI layouts and the BuildKit cache need more space than the + # runner has free by default. + - name: Free runner disk + run: | + set -euo pipefail + df -h / + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL /usr/local/share/boost + docker system prune -af >/dev/null + df -h / + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 + + - name: Guard production build args + run: | + set -euo pipefail + scripts/check-production-build-args.sh -f agents/hermes-01x/Dockerfile.base + scripts/check-production-build-args.sh -f agents/hermes-01x/Dockerfile --build-arg "BASE_IMAGE=nemoclaw-hermes-pr-base" + + - name: Build base image without publishing + id: base_build + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 + with: + context: . + file: agents/hermes-01x/Dockerfile.base + platforms: linux/${{ matrix.arch }} + outputs: type=oci,dest=${{ runner.temp }}/hermes-01x-base,tar=false + push: false + provenance: false + sbom: false + cache-from: type=gha,scope=hermes-01x-verify-base-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=hermes-01x-verify-base-${{ matrix.arch }} + + # Writes ref=nemoclaw-hermes-pr-base and the oci-layout build context. + - name: Resolve base image + id: base + env: + DIGEST: ${{ steps.base_build.outputs.digest }} + PLATFORM: linux/${{ matrix.arch }} + run: bash scripts/checks/resolve-hermes-pr-source-base.sh "$RUNNER_TEMP/hermes-01x-base" "$DIGEST" "$PLATFORM" + + # BASE_IMAGE replaces the Dockerfile's default, a published base image. + - name: Build final image without publishing + id: final_build + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 + with: + context: . + file: agents/hermes-01x/Dockerfile + platforms: linux/${{ matrix.arch }} + build-contexts: ${{ steps.base.outputs.context }} + build-args: | + BASE_IMAGE=${{ steps.base.outputs.ref }} + outputs: type=oci,dest=${{ runner.temp }}/hermes-01x-final,tar=false + push: false + provenance: false + sbom: false + cache-from: type=gha,scope=hermes-01x-verify-final-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=hermes-01x-verify-final-${{ matrix.arch }} + + # Same limit as scripts/check-image-layer-count.sh, which reads a + # registry; Docker's overlay2 storage driver refuses more than 125 (#70). + - name: Check final image layer count + env: + DIGEST: ${{ steps.final_build.outputs.digest }} + ARCH: ${{ matrix.arch }} + run: | + set -euo pipefail + layout="$RUNNER_TEMP/hermes-01x-final" + limit="$(sed -n 's/^MAX_LAYERS=//p' scripts/check-image-layer-count.sh)" + [[ "$limit" =~ ^[0-9]+$ ]] || { echo "ERROR: cannot read MAX_LAYERS" >&2; exit 1; } + [[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "ERROR: invalid final image digest: $DIGEST" >&2; exit 1; } + listed="$(jq -er '.manifests | if length == 1 then .[0].digest else error("not one manifest") end' "$layout/index.json")" + [[ "$listed" == "$DIGEST" ]] || { echo "ERROR: final image layout does not hold $DIGEST" >&2; exit 1; } + count="$(jq -er '.layers | length' "$layout/blobs/sha256/${DIGEST#sha256:}")" + echo "linux/${ARCH}: $count layers (limit $limit)" + if [ "$count" -gt "$limit" ]; then + echo "ERROR: final image has $count layers; the limit is $limit (Docker refuses more than 125)" >&2 + exit 1 + fi diff --git a/agents/hermes-01x/README.md b/agents/hermes-01x/README.md index e9eb5cb73dc..ffc7268d722 100644 --- a/agents/hermes-01x/README.md +++ b/agents/hermes-01x/README.md @@ -22,6 +22,15 @@ model. image has more than 115 layers. Docker's overlay2 storage driver refuses an image with more than 125 layers; Podman has no such limit (#70). To add a build step, extend an existing `RUN` instruction. +- Build without publishing: `.github/workflows/hermes-01x-image-verify.yaml` + (#98) builds `Dockerfile.base` and `Dockerfile` on amd64 and arm64 for pull + requests to `feat/image-only-cli` that change this directory (except + `Dockerfile.tools`), the security package inventory, or the scripts the + workflow runs, and on manual runs. It exports the base image to an OCI + layout and passes it to the final build as a build context, so the final + build does not pull the base image from a registry. It has a read-only token, no registry login, and no + secrets, so it cannot push an image. It applies the same 115-layer limit to + the final image. - Tools image (#74): `Dockerfile.tools` adds the document, PDF/OCR, media, browser, and workspace tools of the OpenClaw tools image to a published image pinned by `BASE_IMAGE`. It is verified by diff --git a/test/helpers/vitest-watch-triggers.ts b/test/helpers/vitest-watch-triggers.ts index 5b561028e26..c7d8b759a38 100644 --- a/test/helpers/vitest-watch-triggers.ts +++ b/test/helpers/vitest-watch-triggers.ts @@ -149,6 +149,10 @@ export const vitestWatchTriggerPatterns: VitestWatchTriggerPattern[] = [ pattern: /(?:^|\/)\.github\/workflows\/code-scanning\.yaml$/, testsToRun: runTests("test/code-scanning-workflow.test.ts"), }, + { + pattern: /(?:^|\/)\.github\/workflows\/hermes-01x-image-verify\.yaml$/, + testsToRun: runTests("test/hermes-01x-image-verify-workflow.test.ts"), + }, { pattern: /(?:^|\/)\.github\/workflows\/pr-merge-conflict-fixer\.yaml$/, testsToRun: runTests("test/pr-merge-conflict-fixer-workflow-boundary.test.ts"), diff --git a/test/hermes-01x-image-verify-workflow.test.ts b/test/hermes-01x-image-verify-workflow.test.ts new file mode 100644 index 00000000000..7ba21e142dd --- /dev/null +++ b/test/hermes-01x-image-verify-workflow.test.ts @@ -0,0 +1,247 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +// The Hermes OpenShell 0.1.x verify workflow builds agents/hermes-01x without +// publishing it (#98). hermes-01x-image.yaml publishes the same Dockerfiles. + +import { spawnSync } from "node:child_process"; +import crypto from "node:crypto"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import YAML from "yaml"; + +type Step = { + env?: Record; + id?: string; + name?: string; + run?: string; + uses?: string; + with?: Record; +}; + +type Job = { + if?: string; + permissions?: unknown; + "runs-on"?: string; + steps?: Step[]; + strategy?: { "fail-fast"?: boolean; matrix?: { include?: Record[] } }; +}; + +type Workflow = { + jobs?: Record; + on?: Record; + permissions?: unknown; +}; + +const repoRoot = path.resolve(import.meta.dirname, ".."); +const workflowPath = path.join(repoRoot, ".github", "workflows", "hermes-01x-image-verify.yaml"); +const workflow = YAML.parse(fs.readFileSync(workflowPath, "utf8")) as Workflow; +const verify = workflow.jobs?.verify ?? {}; +const steps = verify.steps ?? []; + +function step(name: string): Step { + const found = steps.find((candidate) => candidate.name === name); + if (!found) throw new Error(`hermes-01x-image-verify.yaml is missing '${name}'`); + return found; +} + +const guard = step("Guard production build args"); +const baseBuild = step("Build base image without publishing"); +const resolveBase = step("Resolve base image"); +const finalBuild = step("Build final image without publishing"); +const layerCount = step("Check final image layer count"); + +describe("Hermes OpenShell 0.1.x verify workflow (#98)", () => { + it("runs on Hermes OpenShell 0.1.x pull requests and on demand, but not for Dockerfile.tools", () => { + expect(Object.keys(workflow.on ?? {})).toEqual(["pull_request", "workflow_dispatch"]); + expect(workflow.on?.pull_request?.branches).toEqual(["feat/image-only-cli"]); + expect(workflow.on?.pull_request?.paths).toEqual([ + "agents/hermes-01x/**", + "!agents/hermes-01x/Dockerfile.tools", + "src/lib/sandbox-base-image/**", + "scripts/security/**", + "scripts/checks/resolve-hermes-pr-source-base.sh", + "scripts/check-production-build-args.sh", + "scripts/check-image-layer-count.sh", + ".github/workflows/hermes-01x-image-verify.yaml", + ]); + expect(verify.if).toBe("github.repository == 'derekhsu/NemoClaw'"); + }); + + it("cannot publish: read-only token, no registry login, no secrets, no push", () => { + const text = JSON.stringify(workflow); + expect(workflow.permissions).toEqual({ contents: "read" }); + expect(verify.permissions).toBeUndefined(); + expect(text).not.toContain("docker/login-action"); + expect(text).not.toContain("secrets."); + expect(text).not.toMatch(/push=true|push-by-digest/u); + expect(text).not.toMatch(/ghcr\.io|nvidia|docker\.io/iu); + for (const build of [baseBuild, finalBuild]) { + expect(build.with?.push).toBe(false); + expect(build.with?.provenance).toBe(false); + expect(build.with?.sbom).toBe(false); + expect(String(build.with?.outputs)).toMatch(/^type=oci,dest=\$\{\{ runner\.temp \}\}\//u); + } + }); + + it("builds the base and the final image on native amd64 and arm64 runners", () => { + expect(verify["runs-on"]).toBe("${{ matrix.runner }}"); + expect(verify.strategy?.["fail-fast"]).toBe(false); + expect(verify.strategy?.matrix?.include).toEqual([ + { arch: "amd64", runner: "ubuntu-24.04" }, + { arch: "arm64", runner: "ubuntu-24.04-arm" }, + ]); + expect(baseBuild.with?.file).toBe("agents/hermes-01x/Dockerfile.base"); + expect(finalBuild.with?.file).toBe("agents/hermes-01x/Dockerfile"); + for (const build of [baseBuild, finalBuild]) { + expect(build.with?.platforms).toBe("linux/${{ matrix.arch }}"); + } + }); + + it("feeds the checked base layout to the final build instead of a registry image", () => { + expect(steps.indexOf(guard)).toBeLessThan(steps.indexOf(baseBuild)); + expect(steps.indexOf(baseBuild)).toBeLessThan(steps.indexOf(resolveBase)); + expect(steps.indexOf(resolveBase)).toBeLessThan(steps.indexOf(finalBuild)); + expect(steps.indexOf(finalBuild)).toBeLessThan(steps.indexOf(layerCount)); + + expect(baseBuild.id).toBe("base_build"); + expect(resolveBase.id).toBe("base"); + expect(resolveBase.env).toEqual({ + DIGEST: "${{ steps.base_build.outputs.digest }}", + PLATFORM: "linux/${{ matrix.arch }}", + }); + expect(resolveBase.run).toContain( + 'bash scripts/checks/resolve-hermes-pr-source-base.sh "$RUNNER_TEMP/hermes-01x-base" "$DIGEST" "$PLATFORM"', + ); + expect(String(baseBuild.with?.outputs)).toContain("/hermes-01x-base,"); + expect(finalBuild.with?.["build-contexts"]).toBe("${{ steps.base.outputs.context }}"); + expect(String(finalBuild.with?.["build-args"]).trim()).toBe( + "BASE_IMAGE=${{ steps.base.outputs.ref }}", + ); + + expect(guard.run).toContain( + "scripts/check-production-build-args.sh -f agents/hermes-01x/Dockerfile.base", + ); + }); + + it("guards the same base reference that the resolver gives the final build", () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-01x-base-layout-")); + try { + const sha = (data: string) => crypto.createHash("sha256").update(data).digest("hex"); + const blobs = path.join(tmp, "hermes-01x-base", "blobs", "sha256"); + fs.mkdirSync(blobs, { recursive: true }); + const config = JSON.stringify({ os: "linux", architecture: "arm64" }); + fs.writeFileSync(path.join(blobs, sha(config)), config); + const manifest = JSON.stringify({ config: { digest: `sha256:${sha(config)}` }, layers: [] }); + fs.writeFileSync(path.join(blobs, sha(manifest)), manifest); + fs.writeFileSync( + path.join(tmp, "hermes-01x-base", "index.json"), + JSON.stringify({ + manifests: [ + { + mediaType: "application/vnd.oci.image.manifest.v1+json", + digest: `sha256:${sha(manifest)}`, + }, + ], + }), + ); + const output = path.join(tmp, "github-output"); + const resolved = spawnSync("bash", ["-c", resolveBase.run ?? ""], { + cwd: repoRoot, + encoding: "utf8", + env: { + ...process.env, + RUNNER_TEMP: tmp, + DIGEST: `sha256:${sha(manifest)}`, + PLATFORM: "linux/arm64", + GITHUB_OUTPUT: output, + }, + }); + expect(resolved.status, resolved.stderr).toBe(0); + const ref = fs.readFileSync(output, "utf8").match(/^ref=(.+)$/mu)?.[1]; + expect(guard.run).toContain( + `scripts/check-production-build-args.sh -f agents/hermes-01x/Dockerfile --build-arg "BASE_IMAGE=${ref}"`, + ); + expect(fs.readFileSync(output, "utf8")).toContain( + `context=${ref}=oci-layout://${tmp}/hermes-01x-base@sha256:${sha(manifest)}`, + ); + } finally { + fs.rmSync(tmp, { recursive: true, force: true }); + } + }); + + it("caches only in its own GitHub Actions cache scopes", () => { + for (const [build, name] of [ + [baseBuild, "base"], + [finalBuild, "final"], + ] as const) { + expect(build.with?.["cache-from"]).toBe( + `type=gha,scope=hermes-01x-verify-${name}-\${{ matrix.arch }}`, + ); + expect(build.with?.["cache-to"]).toBe( + `type=gha,mode=max,scope=hermes-01x-verify-${name}-\${{ matrix.arch }}`, + ); + } + }); + + it("pins every action to a full commit SHA", () => { + const uses = steps.map((candidate) => candidate.uses).filter(Boolean); + expect(uses.length).toBeGreaterThan(0); + for (const action of uses) expect(action).toMatch(/^[^@]+@[0-9a-f]{40}$/u); + }); + + describe("layer count check", () => { + const digest = (seed: string) => + `sha256:${Buffer.from(seed).toString("hex").padEnd(64, "0").slice(0, 64)}`; + let tmp: string; + + beforeEach(() => { + tmp = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-01x-layers-")); + }); + afterEach(() => fs.rmSync(tmp, { recursive: true, force: true })); + + function layout(layers: number, listed = digest("final")): string { + const root = path.join(tmp, "hermes-01x-final"); + fs.mkdirSync(path.join(root, "blobs", "sha256"), { recursive: true }); + fs.writeFileSync( + path.join(root, "index.json"), + JSON.stringify({ manifests: [{ digest: listed }] }), + ); + fs.writeFileSync( + path.join(root, "blobs", "sha256", digest("final").slice(7)), + JSON.stringify({ layers: Array.from({ length: layers }, () => ({})) }), + ); + return digest("final"); + } + + function run(imageDigest: string) { + return spawnSync("bash", ["-c", layerCount.run ?? ""], { + cwd: repoRoot, + encoding: "utf8", + env: { ...process.env, RUNNER_TEMP: tmp, DIGEST: imageDigest, ARCH: "amd64" }, + }); + } + + it("accepts a final image at the shared layer limit", () => { + const result = run(layout(115)); + expect(result.status, result.stderr).toBe(0); + expect(result.stdout).toContain("linux/amd64: 115 layers (limit 115)"); + }); + + it("rejects a final image above the shared layer limit", () => { + const result = run(layout(116)); + expect(result.status).not.toBe(0); + expect(result.stderr).toContain("final image has 116 layers; the limit is 115"); + }); + + it("rejects a layout that does not hold the built digest", () => { + layout(10, digest("other")); + const result = run(digest("final")); + expect(result.status).not.toBe(0); + expect(result.stderr).toContain("final image layout does not hold"); + }); + }); +});