【问题标题】:How do you install Firebase tools in a Gitlab CI Runner?如何在 Gitlab CI Runner 中安装 Firebase 工具?
【发布时间】:2021-11-18 14:31:43
【问题描述】:

我在配置 Gitlab CI 以运行 firebase 模拟器时遇到了一些问题。特别是,它无法安装 firebase-tools。这是我配置的相关部分

unit-test-job: # This job runs in the test stage.
  image: node:14.14.0
  artifacts:
    paths:
      - "test-results.xml"
    reports:
      junit: "test-results.xml"
  stage: test
  script:
    - apt-get update && apt-get install -y openjdk-8-jdk
    - npm i
    - npm i -g firebase-tools
    - firebase use $MY_PROJECT
    - echo "Running unit tests..."
    - npm run test:ci

在尝试安装 firebase-tools 时,我从 CI 收到此错误

$ npm i -g firebase-tools
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
> re2@1.16.0 install /usr/local/lib/node_modules/firebase-tools/node_modules/re2
> install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR || npm run rebuild
Trying https://github.com/uhop/node-re2/releases/download/1.16.0/linux-x64-83.br ...
Writing to build/Release/re2.node ...
Trying https://github.com/uhop/node-re2/releases/download/1.16.0/linux-x64-83.gz ...
Writing to build/Release/re2.node ...
Building locally ...
npm ERR! code EACCES
npm ERR! syscall scandir
npm ERR! path /root/.npm/_logs
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 65534:0 "/root/.npm"
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/root/.npm/_logs'
}
> re2@1.16.0 rebuild /usr/local/lib/node_modules/firebase-tools/node_modules/re2
> node-gyp rebuild
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/14.14.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/re2/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase-tools/node_modules/re2/.node-gyp'
gyp ERR! System Linux 5.4.109+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/firebase-tools/node_modules/re2
gyp ERR! node -v v14.14.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! re2@1.16.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the re2@1.16.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

关于如何解决此问题的任何建议?

【问题讨论】:

    标签: npm gitlab-ci gitlab-ci-runner firebase-tools


    【解决方案1】:

    您实际上遇到的问题不一定与 gitlab-ci 相关,但它实际上与节点 14 相关。本质上,/root/.npm 文件夹在节点 14 中的权限不正确。您可以通过三种方式解决这个问题:

    1. 更新到节点 15(只需将您的图像更改为 node:15)修复了权限问题
    2. 允许节点权限扫描文件夹。这是由您在上述错误中的错误消息暗示的,它告诉您无法扫描目录。解决此问题的最简单方法是从第二个节点安装中删除 -g,这将使其部署到用户文件夹而不是全局文件夹。由于您每次都在重建容器并且每次都使用相同的用户,因此在这种情况下,全局安装的 -g 是多余的。
    3. 使用独立方法安装 Firebase 以获取 CLI,而不是使用 NPM 来安装它。您可以使用 curl -sL firebase.tools | sed 's/sudo //g' | bash 在 docker 容器中执行此操作

    希望这会有所帮助!

    【讨论】:

    • 由于节点 15 不是 LTS 分支,我宁愿避免这种情况。我也尝试不使用 -g 并且遇到了一个不同的问题,即找不到 firebase。我认为它需要全局安装?
    • 不想更新到节点 15 是公平的。如果您使用用户方法安装,您只需要找到firebase 可执行文件(它应该在~/node_modules/firebase-tools/lib/bin/firebase.js),您可以从那里调用它或将该文件夹添加到路径。或者,我为您添加了第三个选项,即通过跳过整个 NPM 问题的独立方法安装 firebase 工具。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多