Ansible install npm package name from source binary (.tgz) - node.js

I need to install npm using ansible. I am Referring to Ansible 2.3 : http://docs.ansible.com/ansible/npm_module.html
I have packed npm module using npm pack coffee-script and have coffee-script.tgz. now I want to install it using npm by using that file.
The closest thing I can find is :
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: coffee-script
registry: 'http://registry.mysite.com'
But how to install from local file because my server doesn't have internet connection, hence I need to pack and install from the binary file.
I want to do something like this
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: coffee-script
global : yes
source: '/usr/local/coffee-script.tgz'

Please use this:
- name: Install "coffee-script" node.js package from custom registry.
npm:
name: /usr/local/coffee-script.tgz
path: /app/location
global: yes

I ended up using npmbox which solve my problem perfectly.
from my machine I run command npmbox coffee-script which give me coffee-script.npmbox
then I paste to my offline server and run npmunbox -g coffee-script.npmbox
But you need to install npmunbox on your offline server too.
run : npmbox npmbox on your online machine
paste npmbox.npmbox it to offline server
run : tar --no-same-owner --no-same-permissions -xvzf npmbox.npmbox (or using unarhieve command in ansible)
run : npm install --global --cache ./.npmbox.cache --optional --cache-min 99999999999 --shrinkwrap false npmbox
now you can install any npm package offline using npmunbox <package_name>.npmbox (for example : npmunbox pm2.npmbox or npmunbox coffee-script.npmbox

You can user module npm for offline installation.
- name: Install node.js package from custom registry.
npm:
name: "/tmp/pm2-3.5.1.tgz"
global: yes
For multiple installation you can use loop.
Sample tasks:
- name: Find all tgz files in temporary directory
find:
paths: "{{ tmp_node.path }}"
patterns: "*.tgz"
register: node_files
- set_fact:
node_list: "{{ node_files.files | map(attribute='path') | list }}"
- name: Install node.js package from custom registry.
npm:
name: "{{ item }}"
global: yes
loop: "{{ node_list | flatten(1) }}"
Where node_list it's list of .tgz npm packages placed in role in directory files.

Related

Github Actions and npm - npm: command not found

I've created a action for a deployment on github actions. This all works with composer install and git pulling the master branch. However on my digital ocean droplet, I get the issue
bash: line 4: npm: command not found
If i ssh into my server i can use npm perfectly fine. This was installed via nvm and uses the latest version but for some reason its not accessable via the action.
My deployment script is
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy Laravel APP
uses: appleboy/ssh-action#v0.1.4
with:
host: ${{secrets.SSH_HOST}}
key: ${{secrets.SSH_KEY}}
username: ${{ secrets.SSH_USER }}
script: |
cd /var/www/admin
git pull origin master
composer install
npm install
npm run prod
I presume this is more to do with the setup from nvm as i can use this via ssh but as they use the same user to log in via ssh, i can't seem to see an issue.
Any ideas how I can resolve this issue to give access/allow github actions to use npm?
I didn't find a solution for the nvm issue, installing npm via a different way resoleved this issue.
I had the same issue, and finally found the solution.
I could solve the issue by adding the following lines before running npm commands.
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
These commands helps the terminal fix the node path installed by nvm.
Reference link is here.

GitHub action with access to private repo

I would like to run the CI part of my Node / Ionic project where I just yesterday added a custom capacitor plugin - repo A.
This plugin sits in repo B.
On my dev machine I added B as
npm install https://PERSONAL_ACCESS_TOKEN#github.com/ME/B.git --save
to project A.
package.json now contains
"B": "git+https://PERSONAL_ACCESS_TOKEN#github.com/ME/B.git",
and I pushed this to my current merge request.
However, the CI pipeline is telling me now:
npm install
shell: /usr/bin/bash -e {0}
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://***#github.com/ME/B.git
npm ERR!
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/ME/B.git/' not found
npm ERR!
Project B is a private repo. My account owns both repos and I am using my newly created Personal Access Token.
What should I check? I can pull the repo on my local, but there I am setup with my git+ssh env credentials too, so it might work just because of that...
Check first if you need your GitHub username:
https://myGitHubUsername:PERSONAL_ACCESS_TOKEN#github.com/ME/B.git
^^^^^^^^^^^^^^^^^
Then, if you need the token in the git+https URL:
"How to use private GitHub repo as npm dependency" mentions the use of npm-cli-login instead:
- name: Login to GitHub private NPM registry
env:
CI_ACCESS_TOKEN: ${{ secrets.NAME_OF_YOUR_ACCESS_TOKEN_SECRET }}
shell: bash
run: |
npm install -g npm-cli-login
npm-cli-login -u "USERNAME" -p "${CI_ACCESS_TOKEN}" -e "EMAIL" -r "https://npm.pkg.github.com" -s "#SCOPE"
Most answers that I have seen to install private GitHub repo
"package": "git+https://PERSONAL_ACCESS_TOKEN:x-oauth-basic#github.com/username/packge.git"
or
"package": "https://PERSONAL_ACCESS_TOKEN:x-oauth-basic#github.com/username/packge.git"
This works in local, however, if you are using actions/checkout#v2 in your github Action then you need to use persist-credentials:false like the following.
- uses: actions/checkout#v2
with:
persist-credentials: false
otherwise, you'll get an error message remote: Repository not found.
other ways to install private github repo
if you are using ssh like following
"package": "git+ssh://git#github.com/username/packge.git"
then you have to use the ssh-agent in your github action like this
- uses: webfactory/ssh-agent#v0.5.4
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
here SSH_PRIVATE_KEY is a private key from public-private key pair generated using ssh-keygen and the public key is added as a deploy key in the private repo that you are trying to install as an npm package. for more information about this, you can check the official doc

CircleCI: Use nodejs version 12

My CircleCI file is provided:
version: 2.1
orbs:
node: circleci/node#4.1.0
aws-cli: circleci/aws-cli#2.0.3
eb: circleci/aws-elastic-beanstalk#2.0.1
jobs:
build:
docker:
- image: "cimg/base:stable"
steps:
- node/install
- checkout
- aws-cli/setup
- eb/setup
- run:
name: Check current version of node
command: node -v
- run:
name: Get and install node version manager.
command: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
- run:
name: Install Node version 12 using NVM
command: nvm install 12
- run:
name: Use Node version 12
command: nvm use 12
- run:
name: Back-End Install
command: |
npm run backend:install
- run:
name: Front-End Install
command: |
npm run frontend:install
- run:
name: Back-End Build
command: |
npm run backend:build
- run:
name: Front-End Build
command: |
npm run frontend:build
- run:
name: Back-End Deploy
command: |
npm run backend:deploy
- run:
name: Front-End Deploy
command: |
npm run frontend:deploy
During the setup, the CircleCI install node version of v16.9.0 and I need to use v12. So, I run additional command to use v12 using NVM.
Is there easier way to use specific version of the Node during the time of setup?
Using cimg with node version as a docker image should work. You don't have to manually install using nvm.
jobs:
build:
docker:
- image: cimg/node:12.16
https://hub.docker.com/r/cimg/node
I'm using cimg/node:16.13.2 and it works fine.
I think the issue was with the orbs as after I update to the node: circleci/node#4.7.0, I had no issue with NodeJS installation and build the project.
This makes sense as the cI/CD pipeline not suppose to run the software and hence, the NodeJS version should be irrelevent.

Appveyor - Cannot find module 'canvas'

My dev machines (Ubuntu & Windows) do build and test https://github.com/Codeuctivity/PdfjsSharp without any problem, but Appveyor complains while testing that there is a dependency missing:
Error: Cannot find module 'canvas'
The build logs a succesfull install of canvas:
> canvas#2.6.1 install C:\projects\pdfjssharp\PdfjsSharp\node_modules\canvas
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
[canvas] Success: "C:\projects\pdfjssharp\PdfjsSharp\node_modules\canvas\build\Release\canvas.node" is installed via remote
added 100 packages from 50 contributors and audited 100 packages in 6.246s
18 packages are looking for funding
What do I miss here? Seems like there is some appveyor specific issue here, isnt it?
Switched over to Travis CI using that .travis.yml
language: csharp
mono: none
dotnet: 3.1.401
script:
- dotnet restore
- dotnet build -c Release
after_success:
- dotnet test
deploy:
skip_cleanup: true
provider: script
script: dotnet nuget push ./PdfjsSharp/bin/Release/PdfjsSharp.*.*nupkg -k $NUGET_API -s https://api.nuget.org/v3/index.json
on:
branch: master

yarn command not found in gitlab ci

I am trying to configure my gitlab-ci to use yarn install instead of npm install
My current gitlab-ci.yml looks like:
image: node:6.9.4
cache:
paths:
- node_modules/
- .yarn
before_script:
- apt-get update -qq && apt-get install -qy libelf1
stages:
- test
test_core:
stage: test
script:
- yarn config set cache-folder .yarn
- yarn install
- npm run build
- npm run test
tags:
- 2gb
But the build fails with the error:
/bin/bash: line 48: yarn: command not found
is there something I am missing?
I tried installing yarn with:
curl -o- -L https://yarnpkg.com/install.sh | bash
this gave me same error, probably because I need to reload the bash environment for the yarn command to become available.
The above config works perfect with npm install.
Please help me resolve this. If there is something missing in my config file or there is something wrong with the gitlab-ci.
Thanks.
Solved it by using the latest official node docker image.
Since image: 6.10.0, yarn is installed by default in the image.
But if you need node-gyp to build any package, it needs to be installed by adding a line to the script:
yarn global add node-gyp
Add the following to your ci script after yarn got installed:
export PATH=$HOME/.yarn/bin:$PATH
I use image:node:latest and sometimes it prompts the error. Clear Runner Caches do the job for me. Maybe the runner did not recover to the correct state after doing other jobs.
I solved it by using npx (package runner). It's better then extending docker-image only for this purpose
npx yarn someCommand

Resources