Skip to content

Commit 24878fc

Browse files
committed
Merge branch 'main' into fix/gateway-lifecycle-recovery
2 parents 43cf8eb + b42f291 commit 24878fc

17 files changed

Lines changed: 942 additions & 100 deletions

‎.github/workflows/base-image.yaml‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Build and push the sandbox base image to GHCR.
5+
#
6+
# Triggers:
7+
# - Push to main when Dockerfile.base changes (new apt pkgs, openclaw bump, etc.)
8+
# - Manual dispatch for ad-hoc rebuilds
9+
#
10+
# The base image contains the expensive, rarely-changing layers (apt, gosu,
11+
# user setup, openclaw CLI). The production Dockerfile layers PR-specific
12+
# code on top via: FROM ghcr.io/nvidia/nemoclaw/sandbox-base:<tag>
13+
14+
name: base-image
15+
16+
on:
17+
push:
18+
branches: [main]
19+
paths:
20+
- "Dockerfile.base"
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
concurrency:
28+
group: base-image
29+
cancel-in-progress: true
30+
31+
env:
32+
REGISTRY: ghcr.io
33+
IMAGE_NAME: nvidia/nemoclaw/sandbox-base
34+
35+
jobs:
36+
build-and-push:
37+
if: github.repository == 'NVIDIA/NemoClaw'
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 15
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v6
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Log in to GHCR
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract metadata
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
59+
tags: |
60+
type=raw,value=latest
61+
type=sha,prefix=,format=short
62+
63+
- name: Build and push
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
file: Dockerfile.base
68+
push: true
69+
tags: ${{ steps.meta.outputs.tags }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
cache-from: type=gha
72+
cache-to: type=gha,mode=max

‎.github/workflows/docker-pin-check.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ jobs:
2525
uses: actions/checkout@v6
2626

2727
- name: Check Dockerfile base-image pin
28-
run: bash scripts/update-docker-pin.sh --check
28+
run: |
29+
bash scripts/update-docker-pin.sh --check
30+
DOCKERFILE=Dockerfile.base bash scripts/update-docker-pin.sh --check

‎.github/workflows/pr.yaml‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,18 @@ jobs:
8282
- name: Checkout
8383
uses: actions/checkout@v6
8484

85+
- name: Pull base image from GHCR (fall back to local build)
86+
run: |
87+
if docker pull ghcr.io/nvidia/nemoclaw/sandbox-base:latest 2>/dev/null; then
88+
echo "BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest" >> "$GITHUB_ENV"
89+
else
90+
echo "::warning::GHCR base image not available, building locally"
91+
docker build -f Dockerfile.base -t nemoclaw-sandbox-base-local .
92+
echo "BASE_IMAGE=nemoclaw-sandbox-base-local" >> "$GITHUB_ENV"
93+
fi
94+
8595
- name: Build production image
86-
run: docker build -t nemoclaw-production .
96+
run: docker build --build-arg BASE_IMAGE=${{ env.BASE_IMAGE }} -t nemoclaw-production .
8797

8898
- name: Build sandbox test image (fixtures layered on production)
8999
run: docker build -f test/Dockerfile.sandbox --build-arg BASE_IMAGE=nemoclaw-production -t nemoclaw-sandbox-test .
@@ -114,8 +124,18 @@ jobs:
114124
- name: Checkout
115125
uses: actions/checkout@v6
116126

127+
- name: Pull base image from GHCR (fall back to local build)
128+
run: |
129+
if docker pull ghcr.io/nvidia/nemoclaw/sandbox-base:latest 2>/dev/null; then
130+
echo "BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest" >> "$GITHUB_ENV"
131+
else
132+
echo "::warning::GHCR base image not available, building locally"
133+
docker build -f Dockerfile.base -t nemoclaw-sandbox-base-local .
134+
echo "BASE_IMAGE=nemoclaw-sandbox-base-local" >> "$GITHUB_ENV"
135+
fi
136+
117137
- name: Build production image on arm64
118-
run: docker build -t nemoclaw-production-arm64 .
138+
run: docker build --build-arg BASE_IMAGE=${{ env.BASE_IMAGE }} -t nemoclaw-production-arm64 .
119139

120140
- name: Build sandbox test image on arm64
121141
run: docker build -f test/Dockerfile.sandbox --build-arg BASE_IMAGE=nemoclaw-production-arm64 -t nemoclaw-sandbox-test-arm64 .

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Thumbs.db
1515

1616
# Project-specific
1717
draft_newsletter_*
18+
research/
1819
specs/
1920
vdr-notes/
2021

‎Dockerfile‎

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# NemoClaw sandbox image — OpenClaw + NemoClaw plugin inside OpenShell
2+
#
3+
# Layers PR-specific code (plugin, blueprint, config, startup script) on top
4+
# of the pre-built base image from GHCR. The base image contains all the
5+
# expensive, rarely-changing layers (apt, gosu, users, openclaw CLI).
6+
#
7+
# For local builds without GHCR access, build the base first:
8+
# docker build -f Dockerfile.base -t ghcr.io/nvidia/nemoclaw/sandbox-base:latest .
9+
10+
# Global ARG — must be declared before the first FROM to be visible
11+
# to all FROM directives. Can be overridden via --build-arg.
12+
ARG BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest
213

314
# Stage 1: Build TypeScript plugin from source
415
FROM node:22-slim@sha256:4f77a690f2f8946ab16fe1e791a3ac0667ae1c3575c3e4d0d4589e9ed5bfaf3d AS builder
@@ -7,86 +18,18 @@ COPY nemoclaw/src/ /opt/nemoclaw/src/
718
WORKDIR /opt/nemoclaw
819
RUN npm install && npm run build
920

10-
# Stage 2: Runtime image
11-
FROM node:22-slim@sha256:4f77a690f2f8946ab16fe1e791a3ac0667ae1c3575c3e4d0d4589e9ed5bfaf3d
12-
13-
ENV DEBIAN_FRONTEND=noninteractive
14-
15-
RUN apt-get update && apt-get install -y --no-install-recommends \
16-
python3=3.11.2-1+b1 \
17-
python3-pip=23.0.1+dfsg-1 \
18-
python3-venv=3.11.2-1+b1 \
19-
curl=7.88.1-10+deb12u14 \
20-
git=1:2.39.5-0+deb12u3 \
21-
ca-certificates=20230311+deb12u1 \
22-
iproute2=6.1.0-3 \
23-
iptables=1.8.9-2 \
24-
&& rm -rf /var/lib/apt/lists/*
25-
26-
# gosu for privilege separation (gateway vs sandbox user).
27-
# Install from GitHub release with checksum verification instead of
28-
# Debian bookworm's ancient 1.14 (2020). Pinned to 1.19 (2025-09).
29-
# hadolint ignore=DL4006
30-
RUN arch="$(dpkg --print-architecture)" \
31-
&& case "$arch" in \
32-
amd64) gosu_asset="gosu-amd64"; gosu_sha256="52c8749d0142edd234e9d6bd5237dff2d81e71f43537e2f4f66f75dd4b243dd0" ;; \
33-
arm64) gosu_asset="gosu-arm64"; gosu_sha256="3a8ef022d82c0bc4a98bcb144e77da714c25fcfa64dccc57f6aba7ae47ff1a44" ;; \
34-
*) echo "Unsupported architecture for gosu: $arch" >&2; exit 1 ;; \
35-
esac \
36-
&& curl -fsSL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.19/${gosu_asset}" \
37-
&& echo "${gosu_sha256} /usr/local/bin/gosu" | sha256sum -c - \
38-
&& chmod +x /usr/local/bin/gosu \
39-
&& gosu --version
40-
41-
# Create sandbox user (matches OpenShell convention) and gateway user.
42-
# The gateway runs as 'gateway' so the 'sandbox' user (agent) cannot
43-
# kill it or restart it with a tampered HOME/config.
44-
RUN groupadd -r gateway && useradd -r -g gateway -d /sandbox -s /usr/sbin/nologin gateway \
45-
&& groupadd -r sandbox && useradd -r -g sandbox -d /sandbox -s /bin/bash sandbox \
46-
&& mkdir -p /sandbox/.nemoclaw \
47-
&& chown -R sandbox:sandbox /sandbox
48-
49-
# Split .openclaw into immutable config dir + writable state dir.
50-
# The policy makes /sandbox/.openclaw read-only via Landlock, so the agent
51-
# cannot modify openclaw.json, auth tokens, or CORS settings. Writable
52-
# state (agents, plugins, etc.) lives in .openclaw-data, reached via symlinks.
53-
# Ref: https://github.com/NVIDIA/NemoClaw/issues/514
54-
RUN mkdir -p /sandbox/.openclaw-data/agents/main/agent \
55-
/sandbox/.openclaw-data/extensions \
56-
/sandbox/.openclaw-data/workspace \
57-
/sandbox/.openclaw-data/skills \
58-
/sandbox/.openclaw-data/hooks \
59-
/sandbox/.openclaw-data/identity \
60-
/sandbox/.openclaw-data/devices \
61-
/sandbox/.openclaw-data/canvas \
62-
/sandbox/.openclaw-data/cron \
63-
&& mkdir -p /sandbox/.openclaw \
64-
&& ln -s /sandbox/.openclaw-data/agents /sandbox/.openclaw/agents \
65-
&& ln -s /sandbox/.openclaw-data/extensions /sandbox/.openclaw/extensions \
66-
&& ln -s /sandbox/.openclaw-data/workspace /sandbox/.openclaw/workspace \
67-
&& ln -s /sandbox/.openclaw-data/skills /sandbox/.openclaw/skills \
68-
&& ln -s /sandbox/.openclaw-data/hooks /sandbox/.openclaw/hooks \
69-
&& ln -s /sandbox/.openclaw-data/identity /sandbox/.openclaw/identity \
70-
&& ln -s /sandbox/.openclaw-data/devices /sandbox/.openclaw/devices \
71-
&& ln -s /sandbox/.openclaw-data/canvas /sandbox/.openclaw/canvas \
72-
&& ln -s /sandbox/.openclaw-data/cron /sandbox/.openclaw/cron \
73-
&& touch /sandbox/.openclaw-data/update-check.json \
74-
&& ln -s /sandbox/.openclaw-data/update-check.json /sandbox/.openclaw/update-check.json \
75-
&& chown -R sandbox:sandbox /sandbox/.openclaw /sandbox/.openclaw-data
76-
77-
# Install OpenClaw CLI + PyYAML for inline Python scripts in e2e tests
78-
RUN npm install -g [email protected] \
79-
&& pip3 install --no-cache-dir --break-system-packages "pyyaml==6.0.3"
21+
# Stage 2: Runtime image — pull cached base from GHCR
22+
FROM ${BASE_IMAGE}
8023

8124
# Copy built plugin and blueprint into the sandbox
8225
COPY --from=builder /opt/nemoclaw/dist/ /opt/nemoclaw/dist/
8326
COPY nemoclaw/openclaw.plugin.json /opt/nemoclaw/
84-
COPY nemoclaw/package.json /opt/nemoclaw/
27+
COPY nemoclaw/package.json nemoclaw/package-lock.json /opt/nemoclaw/
8528
COPY nemoclaw-blueprint/ /opt/nemoclaw-blueprint/
8629

8730
# Install runtime dependencies only (no devDependencies, no build step)
8831
WORKDIR /opt/nemoclaw
89-
RUN npm install --omit=dev
32+
RUN npm ci --omit=dev
9033

9134
# Set up blueprint for local resolution
9235
RUN mkdir -p /sandbox/.nemoclaw/blueprints/0.1.0 \

‎Dockerfile.base‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# NemoClaw sandbox base image — expensive, rarely-changing layers.
2+
#
3+
# Contains: node:22-slim, apt packages, gosu, user/group setup,
4+
# .openclaw directory structure, OpenClaw CLI, and PyYAML.
5+
#
6+
# Built on main merges and pushed to GHCR. The production Dockerfile
7+
# layers PR-specific code (plugin, blueprint, config) on top.
8+
#
9+
# ── Why these layers are safe to cache ──────────────────────────────────
10+
#
11+
# Everything in this file is either pinned to an exact version or is
12+
# structural (users, directories, symlinks) that doesn't depend on
13+
# NemoClaw application code. Specifically:
14+
#
15+
# node:22-slim — pinned by sha256 digest, checked weekly by
16+
# docker-pin-check.yaml
17+
# apt packages — pinned to exact Debian bookworm versions
18+
# gosu 1.19 — pinned release + per-arch sha256 checksum
19+
# gateway/sandbox — OS users and groups; names and UIDs are a
20+
# users stable contract with OpenShell
21+
# .openclaw dirs — directory structure + symlinks are dictated by
22+
# + symlinks the OpenClaw CLI layout; new dirs are additive
23+
# (add them here and rebuild)
24+
# openclaw CLI — pinned to exact npm version (e.g., 2026.3.11)
25+
# pyyaml — pinned to exact pip version (6.0.3)
26+
#
27+
# Nothing here references NemoClaw plugin source, blueprint files,
28+
# startup scripts, or build-time config (model, provider, auth token).
29+
# Those all live in the production Dockerfile's thin top layers.
30+
#
31+
# ── When to rebuild ─────────────────────────────────────────────────────
32+
#
33+
# The base-image.yaml workflow rebuilds automatically on main merges that
34+
# touch this file. You need to edit this file (triggering a rebuild) when:
35+
#
36+
# 1. OpenClaw CLI version bump — change the openclaw@version below
37+
# 2. New apt package needed — add it to the apt-get install list
38+
# 3. gosu upgrade — update URL, checksum, and version
39+
# 4. node:22-slim digest rotated — update-docker-pin.sh updates both
40+
# Dockerfile and Dockerfile.base
41+
# 5. New .openclaw subdirectory — add mkdir + symlink below
42+
# 6. PyYAML or other pip dep bump — change the version below
43+
#
44+
# For ad-hoc rebuilds (e.g., security patch), use workflow_dispatch on
45+
# the base-image workflow.
46+
#
47+
# Expected rebuild frequency: every few weeks to months, driven mostly
48+
# by OpenClaw CLI version bumps or the weekly docker-pin-check.
49+
# ────────────────────────────────────────────────────────────────────────
50+
51+
FROM node:22-slim@sha256:4f77a690f2f8946ab16fe1e791a3ac0667ae1c3575c3e4d0d4589e9ed5bfaf3d
52+
53+
ENV DEBIAN_FRONTEND=noninteractive
54+
55+
RUN apt-get update && apt-get install -y --no-install-recommends \
56+
python3=3.11.2-1+b1 \
57+
python3-pip=23.0.1+dfsg-1 \
58+
python3-venv=3.11.2-1+b1 \
59+
curl=7.88.1-10+deb12u14 \
60+
git=1:2.39.5-0+deb12u3 \
61+
ca-certificates=20230311+deb12u1 \
62+
iproute2=6.1.0-3 \
63+
iptables=1.8.9-2 \
64+
libcap2-bin=1:2.66-4+deb12u2+b2 \
65+
&& rm -rf /var/lib/apt/lists/*
66+
67+
# gosu for privilege separation (gateway vs sandbox user).
68+
# Install from GitHub release with checksum verification instead of
69+
# Debian bookworm's ancient 1.14 (2020). Pinned to 1.19 (2025-09).
70+
# hadolint ignore=DL4006
71+
RUN arch="$(dpkg --print-architecture)" \
72+
&& case "$arch" in \
73+
amd64) gosu_asset="gosu-amd64"; gosu_sha256="52c8749d0142edd234e9d6bd5237dff2d81e71f43537e2f4f66f75dd4b243dd0" ;; \
74+
arm64) gosu_asset="gosu-arm64"; gosu_sha256="3a8ef022d82c0bc4a98bcb144e77da714c25fcfa64dccc57f6aba7ae47ff1a44" ;; \
75+
*) echo "Unsupported architecture for gosu: $arch" >&2; exit 1 ;; \
76+
esac \
77+
&& curl -fsSL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.19/${gosu_asset}" \
78+
&& echo "${gosu_sha256} /usr/local/bin/gosu" | sha256sum -c - \
79+
&& chmod +x /usr/local/bin/gosu \
80+
&& gosu --version
81+
82+
# Create sandbox user (matches OpenShell convention) and gateway user.
83+
# The gateway runs as 'gateway' so the 'sandbox' user (agent) cannot
84+
# kill it or restart it with a tampered HOME/config.
85+
RUN groupadd -r gateway && useradd -r -g gateway -d /sandbox -s /usr/sbin/nologin gateway \
86+
&& groupadd -r sandbox && useradd -r -g sandbox -d /sandbox -s /bin/bash sandbox \
87+
&& mkdir -p /sandbox/.nemoclaw \
88+
&& chown -R sandbox:sandbox /sandbox
89+
90+
# Split .openclaw into immutable config dir + writable state dir.
91+
# The policy makes /sandbox/.openclaw read-only via Landlock, so the agent
92+
# cannot modify openclaw.json, auth tokens, or CORS settings. Writable
93+
# state (agents, plugins, etc.) lives in .openclaw-data, reached via symlinks.
94+
# Ref: https://github.com/NVIDIA/NemoClaw/issues/514
95+
RUN mkdir -p /sandbox/.openclaw-data/agents/main/agent \
96+
/sandbox/.openclaw-data/extensions \
97+
/sandbox/.openclaw-data/workspace \
98+
/sandbox/.openclaw-data/skills \
99+
/sandbox/.openclaw-data/hooks \
100+
/sandbox/.openclaw-data/identity \
101+
/sandbox/.openclaw-data/devices \
102+
/sandbox/.openclaw-data/canvas \
103+
/sandbox/.openclaw-data/cron \
104+
&& mkdir -p /sandbox/.openclaw \
105+
&& ln -s /sandbox/.openclaw-data/agents /sandbox/.openclaw/agents \
106+
&& ln -s /sandbox/.openclaw-data/extensions /sandbox/.openclaw/extensions \
107+
&& ln -s /sandbox/.openclaw-data/workspace /sandbox/.openclaw/workspace \
108+
&& ln -s /sandbox/.openclaw-data/skills /sandbox/.openclaw/skills \
109+
&& ln -s /sandbox/.openclaw-data/hooks /sandbox/.openclaw/hooks \
110+
&& ln -s /sandbox/.openclaw-data/identity /sandbox/.openclaw/identity \
111+
&& ln -s /sandbox/.openclaw-data/devices /sandbox/.openclaw/devices \
112+
&& ln -s /sandbox/.openclaw-data/canvas /sandbox/.openclaw/canvas \
113+
&& ln -s /sandbox/.openclaw-data/cron /sandbox/.openclaw/cron \
114+
&& touch /sandbox/.openclaw-data/update-check.json \
115+
&& ln -s /sandbox/.openclaw-data/update-check.json /sandbox/.openclaw/update-check.json \
116+
&& chown -R sandbox:sandbox /sandbox/.openclaw /sandbox/.openclaw-data
117+
118+
# Install OpenClaw CLI + PyYAML for inline Python scripts in e2e tests.
119+
# When bumping the openclaw version, rebuild this base image.
120+
RUN npm install -g [email protected] \
121+
&& pip3 install --no-cache-dir --break-system-packages "pyyaml==6.0.3"

‎bin/lib/inference-config.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ function getOpenClawPrimaryModel(provider, model) {
118118
return resolvedModel ? `${MANAGED_PROVIDER_ID}/${resolvedModel}` : null;
119119
}
120120

121+
function parseGatewayInference(output) {
122+
if (!output || /Not configured/i.test(output)) return null;
123+
const provider = output.match(/Provider:\s*(.+)/);
124+
const model = output.match(/Model:\s*(.+)/);
125+
if (!provider && !model) return null;
126+
return {
127+
provider: provider ? provider[1].trim() : null,
128+
model: model ? model[1].trim() : null,
129+
};
130+
}
131+
121132
module.exports = {
122133
CLOUD_MODEL_OPTIONS,
123134
DEFAULT_CLOUD_MODEL,
@@ -128,4 +139,5 @@ module.exports = {
128139
MANAGED_PROVIDER_ID,
129140
getOpenClawPrimaryModel,
130141
getProviderSelectionConfig,
142+
parseGatewayInference,
131143
};

0 commit comments

Comments
 (0)