Skip to content

feat(env): add configurable port overrides via environment variables - #683

Closed
jnun wants to merge 3 commits into
NVIDIA:mainfrom
jnun:feat/configurable-ports-v3
Closed

jnun wants to merge 3 commits into
NVIDIA:mainfrom
jnun:feat/configurable-ports-v3

Conversation

@jnun

@jnun jnun commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add bin/lib/ports.js — central port configuration that reads NEMOCLAW_GATEWAY_PORT, NEMOCLAW_DASHBOARD_PORT, NEMOCLAW_VLLM_PORT, and NEMOCLAW_OLLAMA_PORT from environment variables with validation and sensible defaults
  • Replace all hardcoded port literals in the JS source with configurable constants
  • Follows the existing process.env.NEMOCLAW_* pattern used by NEMOCLAW_MODEL, NEMOCLAW_PROVIDER, and NEMOCLAW_GPU

Problem

The default ports (8080, 8000, 18789) conflict with common services (Jenkins, Django, Tomcat, K8s dashboards). Users have no way to change them without editing source code.

Fix

One new file (bin/lib/ports.js, 23 lines), five surgical edits. No new infrastructure, no .env file loading, no shell script changes. Environment variables override defaults:

$ export NEMOCLAW_GATEWAY_PORT=8081
$ nemoclaw onboard

Validation rejects invalid values (non-integer, out of range 1024-65535).

Files changed

File Change
bin/lib/ports.js New — env var reader with validation
bin/nemoclaw.js Import + use DASHBOARD_PORT
bin/lib/onboard.js Import + replace port literals
bin/lib/local-inference.js Import + replace port literals
bin/lib/nim.js Import + replace port literals
bin/lib/preflight.js Import + replace port literals

Test plan

  • npx vitest run — 214/219 pass (5 pre-existing failures in install-preflight.test.js)
  • node bin/nemoclaw.js onboard with NEMOCLAW_GATEWAY_PORT=8081 — gateway starts on configured port
  • node bin/nemoclaw.js --help / --version — CLI smoke test
  • Default ports work when no env vars are set

Supersedes #652.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Replaced hardcoded ports with a centralized, environment-configurable port configuration (dashboard, gateway, vLLM, Ollama) with sensible defaults.
    • Health checks, startup/probe commands, dashboard URL, and port-availability checks now respect configured ports and validate port values.

jnun and others added 2 commits March 22, 2026 20:29
Allow users to override default service ports (NEMOCLAW_GATEWAY_PORT,
NEMOCLAW_DASHBOARD_PORT, NEMOCLAW_VLLM_PORT, NEMOCLAW_OLLAMA_PORT)
through environment variables. This prevents conflicts when default
ports are already in use on the host.

New file:
- bin/lib/ports.js — central port config with env var overrides
  and validation (range 1024-65535)

Modified files:
- bin/nemoclaw.js — use DASHBOARD_PORT for port forwarding
- bin/lib/onboard.js — use port constants for gateway, dashboard,
  inference detection, and Ollama startup
- bin/lib/local-inference.js — use VLLM_PORT and OLLAMA_PORT for
  health checks, base URLs, and error messages
- bin/lib/nim.js — use VLLM_PORT for NIM container port mapping
- bin/lib/preflight.js — use DASHBOARD_PORT as default check

Follows the existing process.env.NEMOCLAW_* pattern used by
NEMOCLAW_MODEL, NEMOCLAW_PROVIDER, and NEMOCLAW_GPU.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db8b65dc-3b60-409a-9f47-7bbc7ebbb2c9

📥 Commits

Reviewing files that changed from the base of the PR and between 0d231db and 8174545.

📒 Files selected for processing (1)
  • bin/lib/ports.js
✅ Files skipped from review due to trivial changes (1)
  • bin/lib/ports.js

📝 Walkthrough

Walkthrough

Centralizes port configuration by adding bin/lib/ports.js (env-driven port constants) and replaces hardcoded ports across onboarding, local inference, preflight, and nim container logic to use those exported constants.

Changes

Cohort / File(s) Summary
Port Configuration Module
bin/lib/ports.js
New module adding parsePort() and exporting DASHBOARD_PORT, GATEWAY_PORT, VLLM_PORT, OLLAMA_PORT sourced from NEMOCLAW_* env vars with validated numeric fallbacks.
Local inference & CLI helpers
bin/lib/local-inference.js, bin/lib/nim.js, bin/lib/onboard.js
Replaced hardcoded vLLM/Ollama ports (8000/11434) with VLLM_PORT/OLLAMA_PORT in base URLs, health checks, curl commands, warmup/probe endpoints, and container reachability logic. (startNimContainer and waitForNimHealth default param updated to VLLM_PORT.)
Application / startup checks
bin/lib/preflight.js, bin/nemoclaw.js
Replaced hardcoded dashboard port (18789) with DASHBOARD_PORT in port-availability checks and OpenShell port-forward invocation. Also updated gateway arg construction to use GATEWAY_PORT where applicable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nudged the ports from stone to vine,
Env-vars now guide each little line.
No more hard hops, I dance and sing,
Configured springs in every spring! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: introducing environment variable-based configuration for service ports across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bin/lib/ports.js`:
- Around line 9-13: The port validation currently uses parseInt on raw which
allows strings like "8081abc" to pass; update the validation in the function
that parses environment ports (the block creating `parsed` from `raw`) to first
ensure `raw` matches /^\d+$/ (digits-only) and only then convert using
`Number(raw)` (not parseInt), keeping the existing range check (>=1024 &&
<=65535) and throwing the same Error message when validation fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31500cfe-58e2-4ff5-81fc-f8bfee7826e0

📥 Commits

Reviewing files that changed from the base of the PR and between ffa1283 and 0d231db.

📒 Files selected for processing (6)
  • bin/lib/local-inference.js
  • bin/lib/nim.js
  • bin/lib/onboard.js
  • bin/lib/ports.js
  • bin/lib/preflight.js
  • bin/nemoclaw.js

Comment thread bin/lib/ports.js Resolved
…iables

- Tighten parsePort validation: reject non-digit strings (e.g. "8081abc")
  that parseInt silently accepted; use regex + Number() instead
- Add JSDoc to parsePort and all exported constants (docstring coverage)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@wscurran

Copy link
Copy Markdown
Contributor

Thanks for the suggested feature, adding configurable port overrides via environment variables could be really useful for users, I'll make sure to review it carefully.

@prekshivyas

Copy link
Copy Markdown
Collaborator

Hey @jnun — thanks for the original design here! We needed this for a BAC Korea deployment and couldn't wait, so we rebased your approach onto latest main in #1645 with you as co-author. The core ports.js module and env var pattern are yours — we just kept the original defaults (8080, 8000) to avoid breaking existing setups.

Feel free to review #1645 if you'd like. Thanks again for the solid foundation!

@prekshivyas

Copy link
Copy Markdown
Collaborator

Closing in favor of #1645 which rebases this approach onto latest main. Original design credited to @jnun as co-author. Thank you!

@prekshivyas prekshivyas closed this Apr 8, 2026
cv added a commit that referenced this pull request Apr 13, 2026
…1645)

## Summary

- Add `bin/lib/ports.js` as central port configuration module
- All hardcoded service ports can now be overridden via environment
variables
- Defaults are unchanged — zero regression for existing setups

| Env var | Default | Service |
|---------|---------|---------|
| `NEMOCLAW_GATEWAY_PORT` | 8080 | OpenShell gateway |
| `NEMOCLAW_DASHBOARD_PORT` | 18789 | Dashboard UI |
| `NEMOCLAW_VLLM_PORT` | 8000 | vLLM/NIM inference |
| `NEMOCLAW_OLLAMA_PORT` | 11434 | Ollama inference |

Ports are validated to be non-privileged (1024–65535).

### Usage

```bash
export NEMOCLAW_DASHBOARD_PORT=19000
nemoclaw onboard
```

## Related Issue

Closes #684
Based on the approach from PR #683 by @jnun — thank you for the original
design.

Supersedes #683 (rebased on latest main with correct defaults).
Consider closing #703, #357 (subsumed by this).

## Test plan

- [ ] `npm test` passes (135 tests in cli + onboard)
- [ ] `nemoclaw onboard` works with default ports (no regression)
- [ ] Set `NEMOCLAW_DASHBOARD_PORT=19000`, verify dashboard uses port
19000
- [ ] Set invalid port (e.g., `NEMOCLAW_GATEWAY_PORT=abc`), verify
startup fails with clear error

Signed-off-by: Prekshi Vyas <[email protected]>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized, configurable ports for dashboard, gateway, vLLM and
Ollama via environment variables with validated defaults.

* **Improvements**
* Startup, health checks, diagnostics, uninstall and helper flows now
honor configured ports and enforce numeric/range validation with
fail-fast errors.

* **Tests**
* Added unit and end-to-end tests covering port parsing, boundaries and
override scenarios; CI job added to run E2E port-override tests.

* **Chore**
* Added compatibility shim to surface built artifacts and documented the
default dashboard port in the container build.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Prekshi Vyas <[email protected]>
Signed-off-by: Aaron Erickson <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: jnun <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Aaron Erickson <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@prekshivyas prekshivyas self-assigned this Apr 13, 2026
ericksoa added a commit to cheese-head/NemoClaw that referenced this pull request Apr 14, 2026
…VIDIA#1645)

## Summary

- Add `bin/lib/ports.js` as central port configuration module
- All hardcoded service ports can now be overridden via environment
variables
- Defaults are unchanged — zero regression for existing setups

| Env var | Default | Service |
|---------|---------|---------|
| `NEMOCLAW_GATEWAY_PORT` | 8080 | OpenShell gateway |
| `NEMOCLAW_DASHBOARD_PORT` | 18789 | Dashboard UI |
| `NEMOCLAW_VLLM_PORT` | 8000 | vLLM/NIM inference |
| `NEMOCLAW_OLLAMA_PORT` | 11434 | Ollama inference |

Ports are validated to be non-privileged (1024–65535).

### Usage

```bash
export NEMOCLAW_DASHBOARD_PORT=19000
nemoclaw onboard
```

## Related Issue

Closes NVIDIA#684
Based on the approach from PR NVIDIA#683 by @jnun — thank you for the original
design.

Supersedes NVIDIA#683 (rebased on latest main with correct defaults).
Consider closing NVIDIA#703, NVIDIA#357 (subsumed by this).

## Test plan

- [ ] `npm test` passes (135 tests in cli + onboard)
- [ ] `nemoclaw onboard` works with default ports (no regression)
- [ ] Set `NEMOCLAW_DASHBOARD_PORT=19000`, verify dashboard uses port
19000
- [ ] Set invalid port (e.g., `NEMOCLAW_GATEWAY_PORT=abc`), verify
startup fails with clear error

Signed-off-by: Prekshi Vyas <[email protected]>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized, configurable ports for dashboard, gateway, vLLM and
Ollama via environment variables with validated defaults.

* **Improvements**
* Startup, health checks, diagnostics, uninstall and helper flows now
honor configured ports and enforce numeric/range validation with
fail-fast errors.

* **Tests**
* Added unit and end-to-end tests covering port parsing, boundaries and
override scenarios; CI job added to run E2E port-override tests.

* **Chore**
* Added compatibility shim to surface built artifacts and documented the
default dashboard port in the container build.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Prekshi Vyas <[email protected]>
Signed-off-by: Aaron Erickson <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: jnun <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Aaron Erickson <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
ColinM-sys pushed a commit to ColinM-sys/NemoClaw that referenced this pull request Apr 14, 2026
…VIDIA#1645)

## Summary

- Add `bin/lib/ports.js` as central port configuration module
- All hardcoded service ports can now be overridden via environment
variables
- Defaults are unchanged — zero regression for existing setups

| Env var | Default | Service |
|---------|---------|---------|
| `NEMOCLAW_GATEWAY_PORT` | 8080 | OpenShell gateway |
| `NEMOCLAW_DASHBOARD_PORT` | 18789 | Dashboard UI |
| `NEMOCLAW_VLLM_PORT` | 8000 | vLLM/NIM inference |
| `NEMOCLAW_OLLAMA_PORT` | 11434 | Ollama inference |

Ports are validated to be non-privileged (1024–65535).

### Usage

```bash
export NEMOCLAW_DASHBOARD_PORT=19000
nemoclaw onboard
```

## Related Issue

Closes NVIDIA#684
Based on the approach from PR NVIDIA#683 by @jnun — thank you for the original
design.

Supersedes NVIDIA#683 (rebased on latest main with correct defaults).
Consider closing NVIDIA#703, NVIDIA#357 (subsumed by this).

## Test plan

- [ ] `npm test` passes (135 tests in cli + onboard)
- [ ] `nemoclaw onboard` works with default ports (no regression)
- [ ] Set `NEMOCLAW_DASHBOARD_PORT=19000`, verify dashboard uses port
19000
- [ ] Set invalid port (e.g., `NEMOCLAW_GATEWAY_PORT=abc`), verify
startup fails with clear error

Signed-off-by: Prekshi Vyas <[email protected]>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized, configurable ports for dashboard, gateway, vLLM and
Ollama via environment variables with validated defaults.

* **Improvements**
* Startup, health checks, diagnostics, uninstall and helper flows now
honor configured ports and enforce numeric/range validation with
fail-fast errors.

* **Tests**
* Added unit and end-to-end tests covering port parsing, boundaries and
override scenarios; CI job added to run E2E port-override tests.

* **Chore**
* Added compatibility shim to surface built artifacts and documented the
default dashboard port in the container build.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Prekshi Vyas <[email protected]>
Signed-off-by: Aaron Erickson <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: jnun <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
Co-authored-by: Aaron Erickson <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: ColinM-sys <[email protected]>
@wscurran wscurran added feature PR adds or expands user-visible functionality and removed enhancement: feature labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PR adds or expands user-visible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants