Skip to content

Commit 15b23cf

Browse files
authored
fix(docker): use authenticated gateway health command (#118996)
* fix(docker): use authenticated gateway health command * test(docker): prove documented compose health command
1 parent a78f2c4 commit 15b23cf

5 files changed

Lines changed: 62 additions & 5 deletions

File tree

‎docs/install/docker.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ The image's built-in `HEALTHCHECK` pings `/healthz`; repeated failures mark the
287287
Authenticated deep health snapshot:
288288

289289
```bash
290-
docker compose exec openclaw-gateway node dist/index.js health --token "$OPENCLAW_GATEWAY_TOKEN"
290+
docker compose exec openclaw-gateway sh -lc 'node dist/index.js gateway health --token "$OPENCLAW_GATEWAY_TOKEN"'
291291
```
292292

293293
### LAN vs loopback

‎scripts/docker/setup.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,4 @@ echo "Token: stored in Docker environment/config (not printed)."
985985
echo ""
986986
echo "Commands:"
987987
echo " ${COMPOSE_HINT} logs -f openclaw-gateway"
988-
echo " ${COMPOSE_HINT} exec openclaw-gateway sh -lc 'node dist/index.js health --token \"\$OPENCLAW_GATEWAY_TOKEN\"'"
988+
echo " ${COMPOSE_HINT} exec openclaw-gateway sh -lc 'node dist/index.js gateway health --token \"\$OPENCLAW_GATEWAY_TOKEN\"'"

‎scripts/e2e/compose-setup.sh‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,35 @@ cleanup() {
1717
docker_e2e_docker_cmd rm -f "$CLI_NAME" >/dev/null 2>&1 || true
1818
"${COMPOSE[@]}" down --remove-orphans --volumes >/dev/null 2>&1 || true
1919
docker_e2e_cleanup_package_tgz "$PACKAGE_TGZ"
20+
docker_e2e_docker_cmd run --rm --user 0:0 \
21+
-v "$PROJECT_DIR:/target" \
22+
"$IMAGE_NAME" \
23+
sh -c 'rm -rf /target/* /target/.[!.]* /target/..?*' >/dev/null 2>&1 || true
2024
rm -rf "$PROJECT_DIR"
2125
}
2226
trap cleanup EXIT
2327

28+
assert_gateway_health_json() {
29+
local label="$1"
30+
local health_path="$2"
31+
node - "$label" "$health_path" <<'NODE'
32+
const fs = require("node:fs");
33+
const label = process.argv[2];
34+
const healthPath = process.argv[3];
35+
const health = JSON.parse(fs.readFileSync(healthPath, "utf8"));
36+
if (
37+
health?.ok !== true ||
38+
!Number.isFinite(health.ts) ||
39+
!Number.isFinite(health.durationMs) ||
40+
!health.channels ||
41+
typeof health.channels !== "object" ||
42+
Array.isArray(health.channels)
43+
) {
44+
throw new Error(`${label} gateway health JSON is incomplete`);
45+
}
46+
NODE
47+
}
48+
2449
mkdir -p "$PROJECT_DIR/config/workspace" "$PROJECT_DIR/auth-profile"
2550
chmod -R 0777 "$PROJECT_DIR/config" "$PROJECT_DIR/auth-profile"
2651
cat >"$PROJECT_DIR/config/openclaw.json" <<EOF
@@ -71,8 +96,11 @@ if [ "$(docker inspect --format '{{.State.Health.Status}}' "$GATEWAY_ID")" != "h
7196
exit 1
7297
fi
7398

74-
"${COMPOSE[@]}" exec -T openclaw-gateway node dist/index.js health --token "$TOKEN"
75-
"${COMPOSE[@]}" run -T --no-deps --name "$CLI_NAME" openclaw-cli health --token "$TOKEN"
99+
"${COMPOSE[@]}" exec -T openclaw-gateway sh -lc 'node dist/index.js gateway health --token "$OPENCLAW_GATEWAY_TOKEN"'
100+
"${COMPOSE[@]}" exec -T openclaw-gateway node dist/index.js gateway health --token "$TOKEN" --json >"$PROJECT_DIR/gateway-health.json"
101+
assert_gateway_health_json "gateway service" "$PROJECT_DIR/gateway-health.json"
102+
"${COMPOSE[@]}" run -T --no-deps --name "$CLI_NAME" openclaw-cli gateway health --token "$TOKEN" --json >"$PROJECT_DIR/cli-health.json"
103+
assert_gateway_health_json "CLI sidecar" "$PROJECT_DIR/cli-health.json"
76104
GATEWAY_VERSION="$("${COMPOSE[@]}" exec -T openclaw-gateway node -p "require('./package.json').version")"
77105

78106
node --import tsx "$ROOT_DIR/scripts/e2e/lib/docker-artifact-proof/write-identities.ts" \
@@ -84,6 +112,8 @@ node --import tsx "$ROOT_DIR/scripts/e2e/lib/docker-artifact-proof/write-identit
84112
--container "cli=$CLI_NAME" \
85113
--detail "gateway:openclawVersion=$GATEWAY_VERSION" \
86114
--detail "gateway:health=healthy" \
87-
--detail "cli:healthCommand=passed"
115+
--detail "gateway:documentedHealthCommand=passed" \
116+
--detail "gateway:healthJsonEnvelope=passed" \
117+
--detail "cli:healthJsonEnvelope=passed"
88118

89119
echo "Docker Compose setup proof passed."

‎src/docker-setup.e2e.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ describe("scripts/docker/setup.sh", () => {
155155
expect(result.stdout).toContain("Access from tailnet devices via the host's tailnet IP.");
156156
expect(result.stdout).toContain("Commands:");
157157
expect(result.stdout).toContain("logs -f openclaw-gateway");
158+
expect(result.stdout).toContain(
159+
`exec openclaw-gateway sh -lc 'node dist/index.js gateway health --token "$OPENCLAW_GATEWAY_TOKEN"'`,
160+
);
161+
expect(result.stdout).not.toContain("node dist/index.js health --token");
158162
expect(result.stdout).not.toContain("test-token");
159163
expect(result.stdout).not.toContain("#token=");
160164
expect(log).toContain(

‎src/dockerfile.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const repoRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
1010
const dockerfilePath = join(repoRoot, "Dockerfile");
1111
const dockerComposePath = join(repoRoot, "docker-compose.yml");
1212
const dockerInstallDocsPath = join(repoRoot, "docs/install/docker.md");
13+
const composeSetupScriptPath = join(repoRoot, "scripts/e2e/compose-setup.sh");
1314
const dockerReleaseWorkflowPath = join(repoRoot, ".github/workflows/docker-release.yml");
1415
const fullReleaseValidationWorkflowPath = join(
1516
repoRoot,
@@ -46,6 +47,28 @@ describe("Dockerfile", () => {
4647
expect(compose).not.toContain("127.0.0.1:18789/healthz");
4748
});
4849

50+
it("executes the documented Compose health command and validates JSON envelopes", async () => {
51+
const docs = await readFile(dockerInstallDocsPath, "utf8");
52+
const composeSetup = await readFile(composeSetupScriptPath, "utf8");
53+
const gatewayHealthCommand =
54+
'node dist/index.js gateway health --token "$OPENCLAW_GATEWAY_TOKEN"';
55+
56+
expect(docs).toContain(`docker compose exec openclaw-gateway sh -lc '${gatewayHealthCommand}'`);
57+
expect(docs).not.toContain('node dist/index.js health --token "$OPENCLAW_GATEWAY_TOKEN"');
58+
expect(composeSetup).toContain(
59+
`"\${COMPOSE[@]}" exec -T openclaw-gateway sh -lc '${gatewayHealthCommand}'`,
60+
);
61+
expect(composeSetup.match(/gateway health --token "\$TOKEN" --json/g)).toHaveLength(2);
62+
expect(composeSetup).toContain('assert_gateway_health_json "gateway service"');
63+
expect(composeSetup).toContain('assert_gateway_health_json "CLI sidecar"');
64+
expect(composeSetup).toContain('--detail "gateway:documentedHealthCommand=passed"');
65+
expect(composeSetup).toContain('--detail "gateway:healthJsonEnvelope=passed"');
66+
expect(composeSetup).toContain('--detail "cli:healthJsonEnvelope=passed"');
67+
expect(composeSetup).not.toContain('dist/index.js health --token "$TOKEN"');
68+
expect(composeSetup).toContain('-v "$PROJECT_DIR:/target"');
69+
expect(composeSetup).toContain("rm -rf /target/* /target/.[!.]* /target/..?*");
70+
});
71+
4972
it("does not force an external Dockerfile frontend pull", async () => {
5073
for (const path of dockerSetupDockerfilePaths) {
5174
const dockerfile = await readFile(join(repoRoot, path), "utf8");

0 commit comments

Comments
 (0)