EMBER_CLI_PROD_ASSETS 设置为 1 会在预编译资源时崩溃

来自 New installs will default to Ember CLI builds in Production - #36 by david

嗨,团队,

在尝试将 EMBER_CLI_PROD_ASSETS 设置为 1 时,我在预编译资源时遇到了以下问题(版本 2.9.0.beta2 commit: d2de058ff51f204fcf85c86a00750a59505af3bb):

yarn run v1.22.17
$ /var/www/discourse/app/assets/javascripts/node_modules/.bin/ember build -prod
WARNING: Node v16.13.2 is not tested against Ember CLI on your platform. We recommend that you use the most-recent "Active LTS" version of Node.js. See https://git.io/v7S5n for details.
DEPRECATION: The integration of jQuery into Ember has been deprecated and will be removed with Ember 4.0. You can either opt-out of using jQuery, or install the `@ember/jquery` addon to provide the jQuery integration. Please consult the deprecation guide for further details: https://emberjs.com/deprecations/v3.x#toc_jquery-apis
A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)
    at new SystemError (node:internal/errors:233:5)
    at new NodeError (node:internal/errors:336:7)
    at Object.userInfo (node:os:347:11)
    at summarizeProcess (/var/www/discourse/app/assets/javascripts/node_modules/console-ui/lib/summarize-process.js:17:15)
    at writeError (/var/www/discourse/app/assets/javascripts/node_modules/console-ui/lib/write-error.js:114:3)
    at UI.writeError (/var/www/discourse/app/assets/javascripts/node_modules/console-ui/lib/index.js:167:20)
    at CLI.logError (/var/www/discourse/app/assets/javascripts/node_modules/ember-cli/lib/cli/cli.js:318:13)
    at CLI.run (/var/www/discourse/app/assets/javascripts/node_modules/ember-cli/lib/cli/cli.js:253:12)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async module.exports (/var/www/discourse/app/assets/javascripts/node_modules/ember-cli/lib/cli/index.js:145:12) {
  code: 'ERR_SYSTEM_ERROR',
  info: {
    errno: -2,
    code: 'ENOENT',
    message: 'no such file or directory',
    syscall: 'uv_os_get_passwd'
  },
  errno: [Getter/Setter],
  syscall: [Getter/Setter]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

有什么线索知道为什么会发生这种情况吗?

此致,
Ismael

1 个赞

这是使用安装指南进行的生产安装吗?

可以尝试重新构建吗?

1 个赞

重新构建实例后仍未成功。我更想知道是什么导致了 uv_os_get_passwd 调用,或者更普遍地是什么导致了这个错误,它是否期望系统/设置中设置了任何特定的用户?

此致,
Ismael

您是如何运行 Discourse 镜像的?是否有任何额外的安全标志?

沿着这条线索,问题在于 Ember-CLI 构建失败了,而在尝试打印错误时,它又抛出了另一个异常,掩盖了真正的错误。

您能否进入 Discourse 镜像并尝试:

node
const os = require('os');
os.userInfo().shell

1 个赞

有趣的是,当我执行你的建议时,我得到了这个(如果目的是以 root 以外的随机用户访问任何内部库系统,这是完全有道理的):

node
欢迎使用 Node.js v16.13.2。
输入“ .help”以获取更多信息。

> const os = require('os');
undefined

> os.userInfo().shell
Uncaught:
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at new SystemError (node:internal/errors:233:5)
    at new NodeError (node:internal/errors:336:7)
    at Object.userInfo (node:os:347:11) {
  code: 'ERR_SYSTEM_ERROR',
  info: {
    errno: -2,
    code: 'ENOENT',
    message: 'no such file or directory',
    syscall: 'uv_os_get_passwd'
  },
  errno: [Getter/Setter: -2],
  syscall: [Getter/Setter: 'uv_os_get_passwd']
}

>

你是如何运行 Discourse 镜像的?是否有任何额外的安全标志?

我们一直在使用基于 OpenShift 的容器化解决方案,其中 Discourse 以随机用户 ID 运行。到目前为止没有问题,方法与官方安装指南非常相似。
当然,我们可以通过将 EMBER_CLI_PROD_ASSETS 设置为 0 来绕过此问题,资产会像以前一样预编译,但迟早,如果你打算朝这个方向发展,如果当前预编译过程被放弃,这可能会给这类解决方案带来真正的问题。

所以这里有几个问题:

  • 你是否有一个关于放弃(如果确实如此)旧式资产预编译的 ETA?
  • 是否有办法以不同的方式访问 os 机制,或者考虑不同的方法,以便使用随机用户 ID 的容器化解决方案仍然可以工作?

非常感谢你的关注,非常感激。

祝好,
Ismael

1 个赞

我们将在未来几周内移除 EMBER_CLI_PROD_ASSETS

我们不直接使用它,而是通过一个依赖项的依赖项的依赖项……我认为这是一个奇怪的调用,但我们对此控制力不大。

1 个赞

请注意,您看到的错误不是实际错误。
这是在尝试向您显示实际错误时发生的错误……

3 个赞

这与 Issue with non 'username' defined · Issue #2373 · nodejs/node-gyp · GitHubos.userInfo throws if no username in docker container · Issue #25714 · nodejs/node · GitHub 中的问题完全相同。

通过使用随机用户 ID,node 在加载 os 系统相关实用方法和属性时会报错。

只是确认一下,旧的方式将被完全弃用/移除,对吗?

此致,
Ismael

1 个赞

是的,在上面的帖子之后我明白了。除非团队采取任何特殊行动/检查来允许这样做,否则我认为使用随机用户 ID 的时代已经结束了。

祝好,
Ismael

1 个赞

是的,正是如此。我们多年来一直在逐步推出这个新的资源管道,以便我们能够跟踪 EmberJS 项目的建议,并且不那么特立独行。我们已经处于推出的最后阶段。

2 个赞

好的,一切都清楚了。

一如既往,非常感谢您提供详细信息,非常感激。

此致,
Ismael

1 个赞

供记录,也许对某些人有用。至少有一种方法可以让 ember cli 按预期使用随机 uid 工作,那就是确保在运行 rake assets:precompile 操作时,分配的随机 uid 在 /etc/passwd 下有一个条目。

类似这样:

if [ `id -u` -ge 10000 ]; then
  cat /etc/passwd | sed -e "s/^discourse:/builder:/" > /tmp/passwd
  echo "discourse:x:`id -u`:`id -g`:,,,:/home/discourse:/bin/bash" >> /tmp/passwd
  cat /tmp/passwd > /etc/passwd
  rm /tmp/passwd
fi

因此,命令 app/assets/javascripts/discourse run ember build -prod(来自 discourse/assets.rake at tests-passed · discourse/discourse · GitHub)将使其生效。

yarn run v1.22.17
$ /discourse/app/assets/javascripts/node_modules/.bin/ember build -prod
WARNING: Node v16.13.2 is not tested against Ember CLI on your platform. We recommend that you use the most-recent "Active LTS" version of Node.js. See https://git.io/v7S5n  for details.
DEPRECATION: The integration of jQuery into Ember has been deprecated and will be removed with Ember 4.0. You can either opt-out of using jQuery, or install the `@ember/jquery` addon to provide the jQuery integration. Please consult the deprecation guide for further details: https://emberjs.com/deprecations/v3.x#toc_jquery-apis
- Building
Environment: production
- Building
- building...
[WARN] (broccoli-terser-sourcemap) Minifying "assets/chunk.529.6ee9018498e97f872147.js" took: 24288ms (more than 20,000ms)
...

我还注意到这个操作相当耗费资源,仅仅预编译就消耗了近 2GB 的内存 :scream:

此致,
Ismael

2 个赞

上周它使用了超过 4GB 的内存,但我们最近设法在 1GB 内存/2GB 交换服务器上运行它。

4 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.