fix: gracefully disable host-specific commands in Docker mode (#24)#27
fix: gracefully disable host-specific commands in Docker mode (#24)#27
Conversation
- Detect Docker context via /.dockerenv - Skip openclaw CLI presence/version checks in Docker - Suppress gateway process scanning (ps/pgrep) in monitor to prevent log pollution - Gracefully disable /api/kill, /api/gateway/restart, and /api/run/:id endpoints with clear error responses (Fixes #24 host execution issue)
|
@greptileai review please~ |
Greptile SummaryThis PR introduces comprehensive Docker-awareness across Clawbridge, gracefully disabling or stubbing out every host-scoped operation when the service is running in a container. All previously identified issues (IS_DOCKER guard ordering, strict env-var comparison, disk metric false-reporting,
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Browser (dashboard.js)
participant Config as config.js (IS_DOCKER)
participant Status as GET /api/status
participant Cron as GET /api/cron
participant Run as POST /api/run/:id
participant Kill as POST /api/kill
participant Restart as POST /api/gateway/restart
participant Monitor as monitor.js
participant Exec as Child Process (exec/pgrep/ps)
Note over Config: IS_DOCKER = /.dockerenv exists<br/>OR env IS_DOCKER in [true,1,yes]
Client->>Status: fetchStatus()
Status->>Monitor: checkSystemStatus(callback)
alt IS_DOCKER = true
Monitor-->>Status: finalizeStatus({}) [sync]<br/>cpu/mem/disk/gatewayPid/scripts = null<br/>unsupportedMonitoring = [all 5]
else IS_DOCKER = false
Monitor->>Exec: exec(df + pgrep + ps)
Exec-->>Monitor: stdout sections
Monitor-->>Status: finalizeStatus({diskUsage, gatewayPid, psOutput})
end
Status-->>Client: {cpu, mem, disk, gatewayPid, scripts,<br/>environment: {isDocker}, unsupportedMonitoring}
Client->>Client: render "N/A" for unsupported metrics<br/>update runtime-env label
Client->>Cron: fetchJobs()
Cron->>Cron: try fast path (state file)
alt state file readable
Cron-->>Client: [jobs array] (raw, no dockerMode flag)
Client->>Client: render jobs + run buttons
else state file missing/error AND IS_DOCKER
Cron-->>Client: {dockerMode: true, jobs: []}
Client->>Client: render "Unavailable in Docker Mode"
else state file missing AND not Docker
Cron->>Exec: exec(openclaw cron list --json)
Exec-->>Cron: stdout
Cron-->>Client: [jobs array]
end
Client->>Run: runJob(id) POST /api/run/:id
alt IS_DOCKER
Run-->>Client: 403 {error: "...Docker Mode..."}
Client->>Client: alert(error message)
else
Run->>Exec: execFile(openclaw cron run id)
Exec-->>Run: result
Run-->>Client: {status: triggered}
end
Client->>Kill: killAll() POST /api/kill {confirm:true}
alt IS_DOCKER
Kill-->>Client: 403 {error: "...Docker..."}
else
Kill->>Exec: pgrep + SIGTERM/SIGKILL
Kill-->>Client: {status: stopping, pids: [...]}
end
Client->>Restart: restartGateway() POST /api/gateway/restart
alt IS_DOCKER
Restart-->>Client: 403 {error: "...Docker containers..."}
else
Restart->>Exec: pkill + openclaw gateway start
Restart-->>Client: {status: restarted}
end
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Follow-up addressed in Changes made:
Verified with:
|
This PR fixes the issue where Clawbridge inside Docker attempts to execute host-level processes (like
openclaw,ps,pgrep, andpkill), resulting in errors and log pollution.Changes
IS_DOCKERcheck inconfig.js.monitor.js: Skips process scanning and openclaw version CLI fetching when containerized.process.js: Returns403JSON errors with clear instructions if a user attempts to kill or restart processes from the UI in Docker mode.cron.js: Disables manual cron job execution and CLI list fallback.Closes #24