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://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
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.
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?
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
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 }}
Related
We have set up a deployment process for our Nuxt 3 website and the Github Action goes in error when it tries to build the app.
Error:
> build
> nuxt build
npm ERR! code ENOENT
npm ERR! syscall spawn sh
npm ERR! path /home/***/work/my-website-repo-name/my-website-repo-name
npm ERR! errno -2
npm ERR! enoent spawn sh 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! /home/***/.npm/_logs/2022-11-21T11_35_50_456Z-debug-0.log
Error: Process completed with exit code 254.
And the following is our yml file:
name: CI
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Setup Node 16.x
uses: actions/setup-node#v3
with:
node-version: 16.x
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build server
run: npm run build
- name: Deploying
uses: appleboy/scp-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: ".output"
target: ${{ secrets.PATH }}
In the local environment there are no errors when building the app, we have also tried to set the same node version with no luck.
Finally I managed to find the problem: somehow it works if I remove the PATH secret from the target in the last step and I replace it with the actual server path
I have a design token JSON file (written to the standards spec).
I have written a GitHub Action to transform the JSON into CSS variables using a NPM dependency called Design Tokens CLI. I just want it to run an NPM script and then publish the output CSS file the script generates to the NPM registry. The npm run tokenize script does the transpilation.
name: CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 12
- run: npm install
- run: npm run tokenize
- uses: JS-DevTools/npm-publish#v1
with:
token: ${{ secrets.NPM_ACCESS_TOKEN }}
This is the first time I've written an action and I don't really know what I'm doing. I am getting the following error:
/home/runner/work/tokens-test/tokens-test/node_modules/fs-jetpack/lib/find.js:50
const err = new Error(`Path you want to find stuff in doesn't exist ${path}`);
^
Error: Path you want to find stuff in doesn't exist /home/runner/work/tokens-test/tokens-test/example/tokens-layout
at generatePathDoesntExistError (/home/runner/work/tokens-test/tokens-test/node_modules/fs-jetpack/lib/find.js:50:15)
at Object.findSyncInit [as sync] (/home/runner/work/tokens-test/tokens-test/node_modules/fs-jetpack/lib/find.js:111:11)
at Object.find (/home/runner/work/tokens-test/tokens-test/node_modules/fs-jetpack/lib/jetpack.js:138:19)
at file:///home/runner/work/tokens-test/tokens-test/node_modules/design-tokens-cli/utils/transform.js:23:10
at Array.forEach (<anonymous>)
at Command.transform (file:///home/runner/work/tokens-test/tokens-test/node_modules/design-tokens-cli/utils/transform.js:19:21)
at Command.listener [as _actionHandler] (/home/runner/work/tokens-test/tokens-test/node_modules/commander/lib/command.js:482:17)
at /home/runner/work/tokens-test/tokens-test/node_modules/commander/lib/command.js:1264:65
at Command._chainOrCall (/home/runner/work/tokens-test/tokens-test/node_modules/commander/lib/command.js:1158:12)
at Command._parseCommand (/home/runner/work/tokens-test/tokens-test/node_modules/commander/lib/command.js:1264:27) {
code: 'ENOENT'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tokens#1.0.0 tokenize: `designTokens transform`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tokens#1.0.0 tokenize script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-10-06T18_20_19_895Z-debug.log
Error: Process completed with exit code 1.
There is a public NPM package in the Github Package Registry im trying to install using Github Actions.
I have added a .npmrc file next to my package.json with the line #instacart:registry=https://npm.pkg.github.com.
I have added the package to dependencies in my package.json;
"dependencies": {
"#instacart/radium": "^0.26.6"
}
My Github Actions workflow is as follows;
name: Install
on: push
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 16
- run: npm install
I am able to run npm install locally without any problem, but the Github Actions workflow fails;
> Run npm install
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-08-05T09_29_15_323Z-debug-0.log
Error: Process completed with exit code 1.
Why is this error appearing? Why is it working fine locally, but not in the Github Actions workflow? Why is it asking for login credentials when the package is public?
Any help is much appreciated:)
A personal access token with the read:packages scope is required to download and install public packages from the GitHub npm registry. See docs for details.
You need to set GITHUB_ENV in your step env (the GITHUB_TOKEN secret is automatically filled by GitHub):
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 16
- name: Install dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm install
and you also need to give read permission to your repository in package settings:
I have 2 repository. One is main, second is dependency package.
In main project in .gitlab-ci.yml I have:
install_dependency:
stage: install-dep
before_script:
- npm config set strict-ssl false
- ls -la
script:
- git config --global http.sslverify false
- npm config set #my-package:registry https://${TOKEN_USERNAME}:${TOKEN_PASSWORD}#HOST/PACKAGE/PACKAGE.git
- npm i git+https://${TOKEN_USERNAME}:${TOKEN_PASSWORD}#HOST/react.git#master
Dependecy have package.json that should install using `npm -i" as dependecy:
package/mypackage: git+https://${TOKEN_USERNAME}:${TOKEN_PASSWORD}#HOST/react.git#master
A problem is that CI did not recognize path:
$ npm i git+https://${TOKEN_USERNAME}:${TOKEN_PASSWORD}#HOST/react.git#master
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep npm WARN tar ENOENT: no such file or directory, open '/root/.npm/_cacache/tmp/git-clone-7b8b3c6a/node_modules/.staging/uglify-js-ce069d2e/lib/compress.js'
Use self-hosted https://verdaccio.org/ to publish NPM package solves that issue.
For publishing into Gitlab it should upgrade Gitlab package (silver ediiton).
I'm really new to the world of DevOps and want to dip my toes in the water. That's why I've been trying to set up a simple GitHub Action where my site automatically gets deployed to Firebase when I push to master but something goes wrong during the build phase:
Run npm run build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/ChezMout/ChezMout/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/ChezMout/ChezMout/package.json'
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! /home/runner/.npm/_logs/2020-01-12T12_04_27_341Z-debug.log
##[error]Process completed with exit code 254.
This is my basic workflow:
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to Firebase
uses: w9jds/firebase-action#v1.1.0
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: chez-mout
Is there something I'm doing blatantly wrong?
npm install is unable to find the package.json file. Please make sure it exists in the root folder of your repository. (And is under version control and valid).