Repository navigation
fix: bake CHAT_UI_URL into Docker build for remote dashboard access #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -543,6 +543,22 @@ async function createSandbox(gpu) { | |
| run(`cp -r "${path.join(ROOT, "scripts")}" "${buildCtx}/scripts"`); | ||
| run(`rm -rf "${buildCtx}/nemoclaw/node_modules"`, { ignoreError: true }); | ||
|
|
||
| // If CHAT_UI_URL is set, bake it into the Dockerfile copy so the build-time | ||
| // config generator writes the correct allowedOrigins. Without this, remote | ||
| // browsers hit "origin not allowed". | ||
| // Ref: https://github.com/NVIDIA/NemoClaw/issues/795 | ||
| const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789'; | ||
| if (chatUiUrl !== 'http://127.0.0.1:18789') { | ||
| if (/^https?:\/\/[a-zA-Z0-9._:-]+(\/[a-zA-Z0-9._/~%-]*)?$/.test(chatUiUrl)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex is duplicated in |
||
| const dfPath = path.join(buildCtx, "Dockerfile"); | ||
| let df = fs.readFileSync(dfPath, "utf-8"); | ||
| df = df.replace(/^ARG CHAT_UI_URL=.*/m, `ARG CHAT_UI_URL=${chatUiUrl}`); | ||
| fs.writeFileSync(dfPath, df); | ||
| } else { | ||
| console.log(" Warning: CHAT_UI_URL contains invalid characters — using default (localhost)"); | ||
| } | ||
| } | ||
|
|
||
| // Create sandbox (use -- echo to avoid dropping into interactive shell) | ||
| // Pass the base policy so sandbox starts in proxy mode (required for policy updates later) | ||
| const basePolicyPath = path.join(ROOT, "nemoclaw-blueprint", "policies", "openclaw-sandbox.yaml"); | ||
|
|
@@ -554,7 +570,7 @@ async function createSandbox(gpu) { | |
| // --gpu is intentionally omitted. See comment in startGateway(). | ||
|
|
||
| console.log(` Creating sandbox '${sandboxName}' (this takes a few minutes on first run)...`); | ||
| const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789'; | ||
| // chatUiUrl was declared above (used for Dockerfile sed). | ||
| const envArgs = [`CHAT_UI_URL=${shellQuote(chatUiUrl)}`]; | ||
| if (process.env.NVIDIA_API_KEY) { | ||
| envArgs.push(`NVIDIA_API_KEY=${shellQuote(process.env.NVIDIA_API_KEY)}`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -189,13 +189,34 @@ cp -r "$REPO_DIR/nemoclaw-blueprint" "$BUILD_CTX/nemoclaw-blueprint" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cp -r "$REPO_DIR/scripts" "$BUILD_CTX/scripts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf "$BUILD_CTX/nemoclaw/node_modules" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If CHAT_UI_URL is set (e.g. by brev-setup.sh or the user), bake it into the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Dockerfile copy so the build-time config generator writes the correct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # allowedOrigins. Without this, remote browsers hit "origin not allowed". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ref: https://github.com/NVIDIA/NemoClaw/issues/795 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "${CHAT_UI_URL:-}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$CHAT_UI_URL" =~ ^https?://[a-zA-Z0-9._:-]+(/[a-zA-Z0-9._/~%-]*)?$ ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sed -i.bak "s|^ARG CHAT_UI_URL=.*|ARG CHAT_UI_URL=${CHAT_UI_URL}|" "$BUILD_CTX/Dockerfile" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -f "$BUILD_CTX/Dockerfile.bak" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info "CHAT_UI_URL baked into build: ${CHAT_UI_URL}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| warn "CHAT_UI_URL contains invalid characters — using default (localhost)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build the optional runtime env args (CHAT_UI_URL for nemoclaw-start.sh display). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHAT_UI_ENV="" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "${CHAT_UI_URL:-}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHAT_UI_ENV="CHAT_UI_URL=$CHAT_UI_URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Capture full output to a temp file so we can filter for display but still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # detect failures. The raw log is kept on failure for debugging. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE_LOG=$(mktemp /tmp/nemoclaw-create-XXXXXX.log) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set +e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2086 # intentional word-split on CHAT_UI_ENV (validated URL, no spaces) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openshell sandbox create --from "$BUILD_CTX/Dockerfile" --name "$SANDBOX_NAME" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --provider nvidia-nim \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- env NVIDIA_API_KEY="$NVIDIA_API_KEY" >"$CREATE_LOG" 2>&1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- env NVIDIA_API_KEY="$NVIDIA_API_KEY" $CHAT_UI_ENV >"$CREATE_LOG" 2>&1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE_RC=$? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The word-splitting approach works but requires a shellcheck suppression and is fragile if the regex ever allows spaces. Consider using a bash array instead — more idiomatic and avoids the suppression entirely:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf "$BUILD_CTX" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the default URL is repeated as a magic string here and must match the Dockerfile
ARGdefault. If the Dockerfile default ever changes, this comparison silently breaks. Consider extracting a constant: