[英]How to install a private npm github package during sls deploy
我的 CI/CD 無服務器部署失敗,因為它無法安裝私有 npm package。
錯誤 - - - - - - - - - - - - - - - - - - - - - - - - - -
npm 安裝失敗,代碼 1 npm ERR:代碼 ENOENT npm ERR:系統調用生成 git npm ERR。 路徑 git npm 錯誤。 errno ENOENT npm 錯誤。 enoent 執行時出錯:npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/private-org/private-repo.git npm 錯誤! enoent npm 錯誤! enoent npm 錯誤! enoent spawn git ENOENT npm 錯誤! enoent 這與 npm 找不到文件有關。 npm 錯誤! 優雅的
npm ERR:此運行的完整日志可在 npm ERR 中找到。 /github/home/.npm/_logs/2020-05-28T13_30_18_595Z-debug.log
at ChildProcess.child.on.exitCode (/github/workspace/node_modules/serverless-webpack/lib/utils.js:91:16) at ChildProcess.emit (events.js:198:13) at ChildProcess.EventEmitter.emit (domain.js:448:20) at maybeClose (internal/child_process.js:982:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
來自之前的事件:在 PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:505:22) 在 PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/ classes/PluginManager.js:525:17) 在 ServerlessWebpack.BbPromise.bind.then.then.then (/github/workspace/node_modules/serverless-webpack/index.js:91:53) 在 runCallback (timers.js:705) :18) 在 tryOnImmediate (timers.js:676:5) 在 processImmediate (timers.js:658:5) 在 process.topLevelDomainCallback (domain.js:126:23)
獲得支持---------------------------------------- 文檔:文檔。 serverless.com 錯誤:github.com/serverless/serverless/issues 問題:forum.serverless.com 您的環境信息---------------------------- - 操作系統:linux 節點版本:10.20.1 框架版本:1.54.0 插件版本:3.6.12 SDK 版本:2.3.1 組件核心版本:1.1.2 組件 CLI 版本:1.4.0
deploy:
name: deploy
needs: test
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- uses: webfactory/ssh-agent@v0.2.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: npm install
run: npm install
- name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SLS_DEBUG: true
通常我使用 webfactory/ssh-agent@v0.2.0 解決這個問題,所以第一個 npm 安裝在這里工作正常,它設法使用提供的 SSH 密鑰安裝私有 package。
但是,在無服務器部署期間,我遇到了上述錯誤,它無法安裝私有 npm package。有沒有一種方法可以指定 SSH 密鑰供無服務器操作使用?
我有和你一樣的錯誤,我錯誤地找到了解決方案。 在 circleCI 中,無服務器正在讀取包含私有 npm 包授權令牌的 ~/.npmrc 文件,但它沒有讀取包含私有公司包路徑的本地 project.npmrc 文件。
所以不小心將私有路徑復制到 ~/.npmrc 並且神奇地部署 t 成功了。
之后我只更新我的 circleCI 步驟以獲取 ~/.npmrc 中的兩條信息
step_login_github_packages: &step_login_github_packages
name: Log in to Github Packages
command: |
echo "//npm.pkg.github.com/:_authToken=$GITHUB_PACKAGES_TOKEN" >> ~/.npmrc
echo "@my-company:registry=https://npm.pkg.github.com/my-company" >> ~/.npmrc
我想出了一個解決方案,但這意味着我不得不放棄無服務器操作。
deploy:
name: deploy
needs: test
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- uses: webfactory/ssh-agent@v0.2.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: deploy
run: |
npm i -g serverless
npm install
serverless config credentials --provider aws --key $AWS_ACCESS_KEY_ID --secret $AWS_SECRET_ACCESS_KEY
sls deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.