繁体   English   中英

如何在 Gitlab CI Runner 中安装 Firebase 工具?

[英]How do you install Firebase tools in a Gitlab CI Runner?

我在配置 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.

对于如何解决这个问题,有任何的建议吗?

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

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

希望这有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM