Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,16 @@ RUN if [ "$NEMOCLAW_DARWIN_VM_COMPAT" = "1" ]; then \
chmod a+rw /sandbox/.nemoclaw/config.json; \
fi

# Health check: poll the gateway's /health endpoint so Docker (and Compose)
# can detect and restart unhealthy containers in standalone deployments.
# Ref: https://github.com/NVIDIA/NemoClaw/issues/1430
HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3 \
CMD port="${NEMOCLAW_DASHBOARD_PORT:-${OPENCLAW_GATEWAY_PORT:-}}"; \
if [ -z "$port" ]; then \
port="$(python3 -c 'import os; from urllib.parse import urlparse; raw = os.environ.get("CHAT_UI_URL") or "http://127.0.0.1:18789"; raw = raw if "://" in raw else "http://" + raw; u = urlparse(raw); print(u.port or 18789)' 2>/dev/null || printf '18789')"; \
fi; \
curl -sf "http://127.0.0.1:${port}/health"

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
# Entrypoint runs as root to start the gateway as the gateway user,
# then drops to sandbox for agent commands. See nemoclaw-start.sh.
ENTRYPOINT ["/usr/local/bin/nemoclaw-start"]
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,11 @@ RUN openclaw plugins install '@tencent-weixin/openclaw-weixin@2.4.2' --pin \
# hadolint ignore=DL3002
USER root
WORKDIR /

# Baseline health check. The base image runs no service, so this only
# verifies the Node.js runtime is functional. Child images that expose
# a service (e.g. the production Dockerfile's gateway) MUST override
# this with a service-specific probe; otherwise an unresponsive service
# will still report healthy.
HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3 \
CMD node -e "process.exit(0)"
5 changes: 5 additions & 0 deletions test/Dockerfile.sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ RUN mkdir -p /sandbox/openclaw-state/extensions /sandbox/openclaw-state/skills /
&& printf '%s\n' '---' 'name: override-hook' 'description: Override hook fixture' '---' > /sandbox/openclaw-state/hooks/demo-hook/HOOK.md \
&& printf '%s\n' 'export default async function overrideHook() {}' > /sandbox/openclaw-state/hooks/demo-hook/handler.js

# Test image: no long-running service, so just verify the runtime works.
# Overrides any inherited HEALTHCHECK to avoid false-positive probes.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD node -e "process.exit(0)"

ENTRYPOINT ["/bin/bash"]
28 changes: 28 additions & 0 deletions test/sandbox-provisioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ function runLoggedDockerShell(command: string, tmp: string, functionDefs: string
return { result, calls };
}

describe("sandbox provisioning: image health checks (#1430)", () => {
it("production image probes the configured gateway port", () => {
const dockerfile = fs.readFileSync(DOCKERFILE, "utf-8");
const start = dockerfile.indexOf("# Health check: poll the gateway's /health endpoint");
const end = dockerfile.indexOf("# Entrypoint runs as root", start);
expect(start).toBeGreaterThanOrEqual(0);
expect(end).toBeGreaterThan(start);

const healthcheck = dockerfile.slice(start, end);
expect(healthcheck).toContain("HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3");
expect(healthcheck).toContain("NEMOCLAW_DASHBOARD_PORT");
expect(healthcheck).toContain("OPENCLAW_GATEWAY_PORT");
expect(healthcheck).toContain("CHAT_UI_URL");
expect(healthcheck).toContain("127.0.0.1:${port}/health");
expect(healthcheck).not.toContain("127.0.0.1:18789/health");
});

it("base and test images keep non-service health checks runtime-only", () => {
const base = fs.readFileSync(DOCKERFILE_BASE, "utf-8");
const sandbox = fs.readFileSync(DOCKERFILE_SANDBOX, "utf-8");

expect(base).toContain("HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3");
expect(base).toContain('CMD node -e "process.exit(0)"');
expect(sandbox).toContain("HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3");
expect(sandbox).toContain('CMD node -e "process.exit(0)"');
});
});

describe("sandbox provisioning: unified .openclaw layout (#2227)", () => {
it("provisions unified mutable .openclaw layout and trusted rc shims", () => {
const dockerfile = fs.readFileSync(DOCKERFILE_BASE, "utf-8");
Expand Down
Loading