serverless-framework - 如何在 sls 部署期间安装私有(private) npm github 包

标签 serverless-framework github-actions

我的 CI/CD 无服务器部署失败,因为它无法安装私有(private) npm 包。

Error --------------------------------------------------

npm install failed with code 1 npm ERR! code ENOENT npm ERR! syscall spawn git npm ERR! path git npm ERR! errno ENOENT npm ERR! enoent Error while executing: npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/private-org/private-repo.git npm ERR! enoent npm ERR! enoent npm ERR! enoent spawn git ENOENT npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in: 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)

From previous event: at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:505:22) at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:525:17) at ServerlessWebpack.BbPromise.bind.then.then.then (/github/workspace/node_modules/serverless-webpack/index.js:91:53) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) at process.topLevelDomainCallback (domain.js:126:23)

Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Issues: forum.serverless.com Your Environment Information --------------------------- Operating System: linux Node Version: 10.20.1 Framework Version: 1.54.0 Plugin Version: 3.6.12 SDK Version: 2.3.1 Components Core Version: 1.1.2 Components CLI Version: 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 key 安装私有(private)包。

然而,在无服务器部署期间,我收到上述错误并且无法安装私有(private) npm 包。有没有一种方法可以为无服务器操作指定 SSH key ?

最佳答案

我遇到了和你一样的错误,我错误地找到了解决方案。 在 circleCI 中,无服务器正在读取包含私有(private) npm 包授权 token 的 ~/.npmrc 文件,但它没有读取包含私有(private)公司包路径的本地项目 .npmrc 文件。

所以不小心将私有(private)路径复制到 ~/.npmrc 并且神奇地部署成功了。

之后,我更新我的 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

关于serverless-framework - 如何在 sls 部署期间安装私有(private) npm github 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62066641/

相关文章:

amazon-web-services - 将无服务器 API 网关 URL 作为参数传递给同一堆栈中的 Lambda 函数

serverless-framework - Serverless.yml 拒绝 cloudformation "Ref"函数

aws-lambda - 无服务器 : Custom Lambda Function name

r - 在使用适用于 macOS 的 GitHub Actions 进行测试之前如何安装 X11?

github - 如何将 github 操作输出保存到 repo?

amazon-web-services - 部署到 AWS S3 与 github 同步

node.js - AWS Lambda 错误 "Cannot find module ' mongodb'"

node.js - WebDriverIO 和 AWS Lambda

azure - GitHub actions 将错误版本的 Newtonsoft.Json nuget 包部署到 Azure

amazon-web-services - 如何使用 github 操作部署到 aws elastic beanstalk?