簡體   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