简体   繁体   English

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

[英]How to install a private npm github package during sls deploy

My CI/CD serverless deploy is failing because its not able to install a private npm package.我的 CI/CD 无服务器部署失败,因为它无法安装私有 npm package。

Error --------------------------------------------------错误 - - - - - - - - - - - - - - - - - - - - - - - - - -

npm install failed with code 1 npm ERR: code ENOENT npm ERR: syscall spawn git npm ERR. npm 安装失败,代码 1 npm ERR:代码 ENOENT npm ERR:系统调用生成 git npm ERR。 path git npm ERR.路径 git npm 错误。 errno ENOENT npm ERR. errno ENOENT npm 错误。 enoent Error while executing: npm ERR! enoent 执行时出错:npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/private-org/private-repo.git npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/private-org/private-repo.git npm 错误! enoent npm ERR! enoent npm 错误! enoent npm ERR! enoent npm 错误! enoent spawn git ENOENT npm ERR! enoent spawn git ENOENT npm 错误! enoent This is related to npm not being able to find a file. enoent 这与 npm 找不到文件有关。 npm ERR! npm 错误! enoent优雅的

npm ERR: A complete log of this run can be found in. npm ERR. npm ERR:此运行的完整日志可在 npm ERR 中找到。 /github/home/.npm/_logs/2020-05-28T13_30_18_595Z-debug.log /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)来自之前的事件:在 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)

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获得支持---------------------------------------- 文档:文档。 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

Usually i solve this using a webfactory/ssh-agent@v0.2.0 so the first npm install works fine here and it manages to install the private package using the SSH key provided.通常我使用 webfactory/ssh-agent@v0.2.0 解决这个问题,所以第一个 npm 安装在这里工作正常,它设法使用提供的 SSH 密钥安装私有 package。

However during serverless deploy i get the above error and it cannot install the private npm package. Is there a way i can specify an SSH key for serverless action to use?但是,在无服务器部署期间,我遇到了上述错误,它无法安装私有 npm package。有没有一种方法可以指定 SSH 密钥供无服务器操作使用?

I had the same errors as you did and by mistake, I found the solution.我有和你一样的错误,我错误地找到了解决方案。 In circleCI, serverless was reading the ~/.npmrc file that was containing the authorization token for private npm packages, but it was not reading the local project.npmrc file that was containing the path for the private company packages.在 circleCI 中,无服务器正在读取包含私有 npm 包授权令牌的 ~/.npmrc 文件,但它没有读取包含私有公司包路径的本地 project.npmrc 文件。

So accidentally copy the private path to the ~/.npmrc and magically it the deployment t was successful.所以不小心将私有路径复制到 ~/.npmrc 并且神奇地部署 t 成功了。

After that I just update my circleCI step to get both pieces of information in the ~/.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

Ive come up with a solution but it meant i had to move away from the serverless action.我想出了一个解决方案,但这意味着我不得不放弃无服务器操作。

  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.

相关问题 无服务器部署 - Function 未找到 - sls 部署 - Serverless deploy - Function not found - sls deploy 我该如何解决这个错误? 我正在尝试在 AWS 上部署存根 API。 我已经解雇了 sls deploy 命令 - How can I fix this error? I am trying to deploy stub API on AWS. I have fired sls deploy command 使用 sls deploy --stage dev 部署时未将阶段添加到端点 - stage is not added to the endpoint when deploy with sls deploy --stage dev 类型错误:ctx.sls.service.package.include.push 不是函数 - TypeError: ctx.sls.service.package.include.push is not a function 如何在 Windows 中设置 SLS_DEBUG? - How to set SLS_DEBUG in windows? API 网关 URL(端点 ID)在“sls deploy”后更改,端点未出现在 API 网关中 - API Gateway URL (endpoint id) Changed after “sls deploy” and endpoint is not appearing in API Gateway 如何在单独的步骤中打包和部署无服务器框架代码? - How to package and deploy serverless framework code in separate steps? 如何使用无服务器部署包含 package.json? - How to include package.json using serverless deploy? 在无服务器部署上调用 github 工作流 - Invoke github workflow on serverless deploy 如何使用 github 操作部署具有多个包的无服务器 mono 存储库。json? - How to use github action to deploy a serverless mono repo with multiple packages.json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM