繁体   English   中英

sls部署时如何安装私有npm github package

[英]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.

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