Skip to content

fix(connectors): fall back to user-level npm prefix when global dir not writable - #406

Merged
jubaoliang merged 1 commit into
TencentCloud:developfrom
veenyi:upstream-fix-cli-install
Aug 25, 2026
Merged

fix(connectors): fall back to user-level npm prefix when global dir not writable#406
jubaoliang merged 1 commit into
TencentCloud:developfrom
veenyi:upstream-fix-cli-install

Conversation

@veenyi

@veenyi veenyi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

问题

Octop 常以非 root 用户运行在 NAS / 容器主机(如飞牛 FnOS 应用中心服务)上,此时 npm 全局目录(/usr/local)不可写。点击连接器的"安装 CLI"执行 npm install -g @wecom/cli 会失败:

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@wecom'

导致企微 / 飞书连接器 CLI 在这些环境无法安装。

修复

  • 安装前读取 npm 全局 prefix(npm config get prefix)并检测是否可写。
  • 不可写时用 --prefix ~/.npm-global 安装到用户级目录(无需 sudo、不修改用户 npmrc)。
  • 降级安装后,把用户级 npm bin 目录注入进程 PATH(服务启动时 + 状态检查时),使 shutil.which 和连接器 CLI 子进程都能找到命令。
  • 新增单元测试:可写路径保持原行为、不可写自动降级、PATH 注入幂等(跨平台,Windows 兼容 expanduser)。

说明

纯 bugfix:全局目录可写时(常见 Docker 场景)行为完全不变。CI 全绿(Linux + Windows)。

…s not writable

Octop often runs as a non-root user on NAS/container hosts where the npm
global prefix (/usr/local) is not writable, so `npm install -g @wecom/cli`
fails with EACCES (exit 243). This change:

- Detects the configured npm global prefix and its writability before
  installing connector CLIs (wecom-cli / lark-cli)
- Falls back to a user-level prefix (~/.npm-global) with --prefix when the
  global dir is not writable, without touching the user's npmrc
- Injects the user-level npm bin dir into the in-process PATH at server
  startup and on status checks, so shutil.which and CLI subprocess calls
  find the binaries
- Adds unit tests covering the fallback, the writable-path behavior and
  the PATH injection (cross-platform, honors USERPROFILE on Windows)
veenyi added a commit to veenyi/octop-fnos that referenced this pull request Aug 25, 2026
… tighten process kill

Addresses review feedback:

- Extract find_python312 / fix_ownership_and_perms / free_octop_ports into a
  single shared library scripts/fnos/common.sh (injected into both packages'
  cmd/common.sh by build-fpk.sh at package time) instead of duplicating them
  across 7 docker/native lifecycle scripts
- Tighten the leftover-process cleanup: only kill processes under this
  install dir (TRIM_APPDEST), no more broad 'pgrep -f octop' that could kill
  other users' / other installs' processes
- Root README: add an 'FnOS Installation' section pointing to fnos/README.md
  and noting the initial credentials + the TencentCloud#406 dependency for non-root CLI
  installs
@veenyi
veenyi changed the base branch from main to develop August 25, 2026 06:18
@jubaoliang
jubaoliang merged commit 988db77 into TencentCloud:develop Aug 25, 2026
5 checks passed
jubaoliang pushed a commit that referenced this pull request Aug 25, 2026
* feat(fnos): add FnOS (飞牛 NAS) app packaging for Docker and native installs

Adds the packaging tree to build Octop as a FnOS app center package (.fpk):

- fnos/: Docker-deployable FPK (thin wrapper that runs the Octop image
  via docker-compose on the NAS)
- fnos-native/: native FPK that runs Octop directly on the FnOS host with
  the system Python 3.12 runtime (no Docker required)
- scripts/build-fpk.sh: generic FPK build helper using the official fnpack
  CLI (injects the version from pyproject.toml into the manifest)

Both packages share the same app version as pyproject.toml. Container image
name is referenced as ghcr.io/TencentCloud/octop:latest — maintainers can
republish under their own namespace; the per-repo CI (image build + release
workflow) is intentionally left out of this PR.

* feat(fnos): first-use guide — fixed initial credentials admin/Octop123 with docs

- The previous default password 'octop' does not satisfy the password
  policy (>=8 chars incl. letters and digits) enforced by 'octop init',
  so the bootstrap admin could not be created
- Switch the default to Octop123, identical to the official Docker image
- Manifest install text now prints the initial account/password and tells
  users to change it after first login
- fnos/README.md gains a 'First use' section (credentials table + change
  password guidance) so users never need to dig into data directories

* ci(fnos): add FnOS packaging pipeline as a fork-maintainer template

Provides a complete CI template that builds the Octop Docker image,
the Docker .fpk and the native .fpk, then publishes GitHub releases
(fixed version + rolling latest):

- Trigger: workflow_dispatch only, so it never auto-runs on upstream
- Image namespace referenced as ghcr.io/TencentCloud/octop (placeholder;
  fork maintainers replace with their own)
- Iteration numbering, changelog generation (install-first, no-merges,
  capped at 30 entries) and rolling release management included

* refactor(fnos): dedupe lifecycle scripts into scripts/fnos/common.sh; tighten process kill

Addresses review feedback:

- Extract find_python312 / fix_ownership_and_perms / free_octop_ports into a
  single shared library scripts/fnos/common.sh (injected into both packages'
  cmd/common.sh by build-fpk.sh at package time) instead of duplicating them
  across 7 docker/native lifecycle scripts
- Tighten the leftover-process cleanup: only kill processes under this
  install dir (TRIM_APPDEST), no more broad 'pgrep -f octop' that could kill
  other users' / other installs' processes
- Root README: add an 'FnOS Installation' section pointing to fnos/README.md
  and noting the initial credentials + the #406 dependency for non-root CLI
  installs

* feat(fnos): transparent app icons (512/256/64) — remove white background for dark/light themes

---------

Co-authored-by: veenyi <veenyi@users.noreply.github.com>
@veenyi

veenyi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

说明:为方便中文团队沟通,本 PR 描述已更新为中文。后续讨论请直接使用中文。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants