Skip to content

fix(docker): fall back to image's default userDir via NODE_RED_CLI_DEFAULT_USERDIR - #32

Merged
tbrandenburg merged 1 commit into
mainfrom
fix/31-docker-default-userdir
Sep 6, 2026
Merged

fix(docker): fall back to image's default userDir via NODE_RED_CLI_DEFAULT_USERDIR#32
tbrandenburg merged 1 commit into
mainfrom
fix/31-docker-default-userdir

Conversation

@tbrandenburg

Copy link
Copy Markdown
Owner

Issues fixed

Closes #31

Summary

--docker previously never pointed Node-RED's userDir at a community image's own pre-populated default userDir (e.g. /data in agentic-workflow-dev-env), forcing redundant --node-modules re-installs even when a package was already baked into the image.

This adds an opt-in env-var convention, resolved inside the container by the existing shared runFlowInvocation() in src/run-envelope.js:

  • New env var: NODE_RED_CLI_DEFAULT_USERDIR. Image authors set this to their own conventional userDir path.
  • Precedence:
    1. Explicit --user-dir always wins (unchanged).
    2. Else, if NODE_RED_CLI_DEFAULT_USERDIR is set and points at an existing directory: used as userDir, never deleted afterward (image-owned).
    3. Else: falls back to today's ephemeral tmpdir — zero behavior change for every image that doesn't opt in.
    4. If the env var is set but invalid (missing/not-a-directory/inaccessible): fails open — logs a one-line stderr warning and falls back to the ephemeral tmpdir, rather than aborting.
  • No new CLI flag needed.

Files changed

  • src/run-envelope.js: resolveDefaultUserDir() helper + precedence wiring in runFlowInvocation.
  • bin/node-red-cli-sandbox-entry.js: doc-comment only.
  • bin/node-red-cli.js: one-line HELP_TEXT note for image authors.
  • README.md: documents the new convention under --docker.
  • test/unit/run-envelope.unit.test.js (new): unit coverage for resolveDefaultUserDir (unset / valid dir / nonexistent path / file-not-dir).
  • test/integration/run-envelope.integration.test.js: env-var userDir used + never removed; explicit --user-dir precedence.
  • test/integration/docker.integration.test.js: real-Docker regression test reproducing the issue's exact scenario (pre-baked module discovered via --docker alone) + precedence test (--user-dir overrides the env var).

Validation

  • make lint — pass
  • make format — pass
  • make test130/130 passed, 0 skipped (Docker was available in the CI/dev environment, so all new Docker integration tests actually ran against real containers, not skipped)
  • make audit — 0 vulnerabilities (ran as part of make ci via the pre-push hook)

E2E coverage

No e2e changes needed — this is a Docker/env-var wiring concern already covered by the new Docker integration tests, per the issue's own agreed testing strategy (integration-level, real Docker + real embedded Node-RED, is the right layer; full test/e2e/ example-flow run adds no additional signal here).

Risks / follow-ups

  • Low risk: fully opt-in (image must set the env var), fails open on misconfiguration, and every existing test path (which doesn't set the var) is unchanged.
  • Follow-up (out of scope for this repo): the reference image ghcr.io/tbrandenburg/agentic-workflow-dev-env would need its own change to export NODE_RED_CLI_DEFAULT_USERDIR=/data to benefit from this.

Unrelated issues found

  • None.

@tbrandenburg
tbrandenburg merged commit ad70365 into main Sep 6, 2026
7 checks passed
tbrandenburg added a commit that referenced this pull request Sep 6, 2026
…e + --docker-userdir override (#34)

Reverts the NODE_RED_CLI_DEFAULT_USERDIR env-var convention from #31/#32,
which required community image authors to opt in and was confirmed
dead-on-arrival for the motivating agentic-workflow-dev-env image.

Replaces it with:
- a best-effort /data auto-probe (sandbox entrypoint only) that validates
  node_modules/* and node_modules/@*/* (following symlinks) for a
  package.json declaring a "node-red" key before trusting the path
- an explicit --docker-userdir <path> CLI flag as a reliable, zero-guessing
  override for any convention
- a 4-level userDir precedence: --user-dir > --docker-userdir >
  auto-probed /data > ephemeral default
- a clearer --node-modules preflight error when combined with
  --docker-userdir/auto-probe without an explicit --user-dir

Closes #33

Co-authored-by: Tom Brandenburg <t_bh@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant