1
votes

My CI/CD serverless deploy is failing because its not able to install a private npm package.

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://[email protected]/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/[email protected]
      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/[email protected] so the first npm install works fine here and it manages to install the private package using the SSH key provided.

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?

2

2 Answers

1
votes

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.

So accidentally copy the private path to the ~/.npmrc and magically it the deployment t was successful.

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

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/[email protected]
      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 }}