简体   繁体   English

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

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

I'm having some trouble configuring Gitlab CI to run firebase emulators.我在配置 Gitlab CI 以运行 firebase 模拟器时遇到了一些问题。 In particular, it's failing to install firebase-tools.特别是,它无法安装 firebase-tools。 This is the relevant part of my config这是我配置的相关部分

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

When trying to install firebase-tools I get this error from the 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.

Any suggestions on how to fix this?对于如何解决这个问题,有任何的建议吗?

You're actually encountering an issue that isn't necessarily related to gitlab-ci, but it actually related to node 14. Essentially that /root/.npm folder has bad permissions in node 14. You have three ways you can fix this:您实际上遇到了一个不一定与 gitlab-ci 相关的问题,但它实际上与节点 14 相关。本质上,/root/.npm 文件夹在节点 14 中具有错误权限。您可以通过三种方式解决此问题:

  1. Update to Node 15 (just change your image to node:15 ) which fixes the permission issue更新到 Node 15(只需将您的图像更改为node:15 )即可解决权限问题
  2. Allow node permissions to scan the folder.允许节点权限扫描文件夹。 This is insinuated by the error message you have in the above error where it tells you the directory can't be scanned.上述错误中的错误消息暗示了这一点,它告诉您无法扫描目录。 The easiest way to resolve this issue is to remove the -g off the second node install, which will make it deploy to the user folder instead of global.解决此问题的最简单方法是从第二个节点安装中删除-g ,这将使其部署到用户文件夹而不是全局文件夹。 Since you're rebuilding the container every time and using the same user each time, the -g to install globally is redundant in this case.由于您每次都在重建容器并且每次都使用相同的用户,因此在这种情况下全局安装的-g是多余的。
  3. Install Firebase using the standalone method to get the CLI instead of using NPM to install it.使用独立方法安装 Firebase 以获取 CLI,而不是使用 NPM 来安装它。 You can do this in a docker container using curl -sL firebase.tools | sed 's/sudo //g' | bash您可以在 docker 容器中执行此操作,使用curl -sL firebase.tools | sed 's/sudo //g' | bash curl -sL firebase.tools | sed 's/sudo //g' | bash

Hopefully this helps!希望这有帮助!

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

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