What is the recommended way to handle node.js private module dependencies? - node.js

I am currently working on an node.js app that is deployed on Elastic Beanstalk. It has started to reference a private module that is hosted on github as a private repository. Locally if I put a reference to it in the dependency section of my package.json like the following it works fine. I can run nom install, it downloads the module and the app works without issue.
"ModuleName": "git+https://TOKEN:x-oauth-basic#github.com/OWNER/REPO_NAME.git"
However, when I try to deploy to Beanstalk it fails with the following error:
2014-04-04 00:14:09,188 [DEBUG] (1630 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild'], 'returncode': 1, 'events': [{'msg': 'Failed to run npm install. Snapshot logs for more details.', 'timestamp': 1396570449, 'severity': 'ERROR'}, {'msg': 'Failed to run npm install. npm http GET https://registry.npmjs.org/express\nnpm ERR! not found: git\nnpm ERR! \nnpm ERR! Failed using git.\nnpm ERR! This is most likely not a problem with npm itself.\nnpm ERR! Please check if you have git installed and in your PATH.\n\nnpm ERR! System Linux 3.4.73-64.112.amzn1.x86_64\nnpm ERR! command "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/npm" "install"\nnpm ERR! cwd /tmp/deployment/appli', 'timestamp': 1396570449, 'severity': 'ERROR'}], 'msg': 'Error occurred during build: Command hooks failed\n'}], 'api_version': '1.0'}
From what I can tell by reading that it appears that git is not installed on the default linux AMI that Beanstalk uses. My question is what is the best way to handle this. Currently I'm considering the following two options:
Either use an AMI that has git installed or force the installation somehow during boot.
Create a build process that packages all my node_modules prior to deploying to Beanstalk.
Do these two options make sense or should I be considering another option? Is there a recommended way to handle this with Elastic Beanstalk or in the node ecosystem in general?

You can make sure that git is installed on the machine by adding a config file in the .ebextensions folder. See http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
If you add a file called .ebextensions/packages.config which contains the following:
#extra yum packages
packages:
yum:
git: []
This will install git on the machine before installation of your application.

Related

Stop EBS Linux 2 (Node.js) from trying to do npm install?

I'm trying to run a Node application on AWS Linux 2 on Elastic Beanstalk and need to install the dependencies using yarn. (My Node app causes errors if you try to use npm to install dependencies instead of yarn.)
I've already figured out how to set up a script in .platform/hooks/prebuild/ to get it to run yarn, but even though it's running the yarn installation, it still also tries to run npm install, which errors out, causing my deploy to fail.
So I need to figure out how to prevent the default npm install step from running.
(Does anyone know what file that command is run from in the AWS Linux 2 setup process? I was wondering if I could just add another script in .platform/hooks/prebuild/ that would modify that file to prevent the call to npm.)
yes, you can avoid npm install
When you deploy a node_modules directory to an Amazon Linux 2 Node.js platform version, Elastic Beanstalk assumes that you're providing your own dependency packages, and avoids installing dependencies specified in a package.json file.
source doc

NPM Authentication Error To Private Repo on jenkins build

I'm working on a Front End Application that relies on a dependency developed by our organization but is hosted in a separate repository. It's a bitbucket repo hosted by us and is private.
We're using NPM to manage this dependency, and install it via git+https://<the-dependency-repo>.com
This works in our local environment because our credentials are cached. Please note: WE CANNOT SWITCH TO SSH. I'm aware of the ssh solution, I have no control over account management, bitbucket access etc...
When the Jenkins CI runs, it pulls our application from it's repository using credentials stored in the Credentials Plugin, and runs npm install.
The Problem:
The install fails because of authentication failure during the npm install.
What I've tried so far:
Since the git credentials are stored in the Jenkins Credential Plugin, I have access to a git username/password combination.
The precise failure happens when npm attempts to run git ls-remote ...
To circumvent this authentication failure, I am able to run a shell command before the npm install:
git config credential.helper 'cache'
git fetch https://${USERPASSCOMBO}#<repo>
The good news is that this works! NPM is able to run git fetch ls-remote without error
The bad news is that the next command git clone -q <repo> fails.
I've attempted the same solution: adding the following prior to npm install:
git config credential.helper 'cache'
git ls-remote https://${USERPASSCOMBO}#<repo>
git clone https://${USERPASSCOMBO}#<repo>
note: these commands work as expected, prior to npm install
NPM install still fails however, producing the following error output:
[ERROR] npm ERR! Command failed: /bin/git clone -q https://<repo> /var/lib/jenkins/.npm/_cacache/tmp/git-clone-ed5ac1a9
[ERROR] npm ERR! warning: templates not found /tmp/pacote-git-template-tmp/git-clone-49feabe4
[ERROR] npm ERR! fatal: Authentication failed for '<repo>'
[ERROR] npm ERR!
Any help is greatly appreciated, even a pointer towards the right direction. I've exhausted trying everything I can think of.
Try installing from the repository with the URL git+https://user:password#<repo-url>.
Note that this leaves your password out in the open, so I suggest generating an app token or similar if your repository provider supports this.

Jenkins cannot run npm or pm2 by itself

So I have a Jenkins CI setup on an EC2 server. I have nodejs and npm installed. Weirdly, Jenkins can access them via the command line if I do something like:
sudo -u jenkins node -v
However, Jenkins cannot access them inside an actual build runtime, and I get the following errors:
npm: command not found
pm2: command not found
npm is definitely installed, and ec2-user/root users can access it. What PATH do I have to change so that Jenkins can access it too?
I think that if you use the nodejs plugin it will be easier to manage your node and npm in this box. Also, this plugin allows installing some global modules that possibly you will need to build your project:
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

Running Babel on NodeJS5.12.0 image inside the Docker for Windows

Well, I've been trying to run this over the past few days and whatever I do, it ends up in an error. Here's the scenario. I'm trying to run a dev environment base on Cory House's redux starter kit found here: https://github.com/coryhouse/pluralsight-redux-starter
To do this I did several things:
Installing Docker for Windows.
Selecting "D" as the Shared Drives in the Settings dialog and saving my "Windows 10" credentials so that Docker could access the "D" partition.
Opening up an elevated "PowerShell".
Pulling NodeJS:5.12.0 using the docker pull node:5.12.0 command.
Creating a container using the following command: docker run -it -v d:/temp:/www node:5.12.0 bash
Pulling the package.json, webpack.config.dev.js, .babelrc, and .eslintrc from https://github.com/coryhouse/pluralsight-redux-starter and copying them to the "d:\temp" folder on my Windows machine.
Changing from the root directory to "www" inside the bash.
Installing packages using npm install.
Everything seems to be installed correctly, except that at the end, I received the following error message:
67097 warn optional Skipping failed optional dependency /chokidar/fsevents:
67098 warn notsup Not compatible with your operating system or architecture: fsevents#1.0.14
67099 verbose stack Error: ENOTSUP: operation not supported on socket, symlink
'../acorn/bin/acorn' ->
'/www/node_modules/acorn-jsx/node_modules/.bin/acorn'
67099 verbose stack at Error (native)
67100 verbose cwd /www
67101 error Linux 4.4.15-moby
67102 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
67103 error node v5.12.0
67104 error npm v3.8.6
67105 error path ../acorn/bin/acorn
67106 error code ENOTSUP
67107 error errno -95
67108 error syscall symlink
67109 error nospc ENOTSUP: operation not supported on socket, symlink
'../acorn/bin/acorn' ->
'/www/node_modules/acorn-jsx/node_modules/.bin/acorn'
67110 error nospc This is most likely not a problem with npm itself
67110 error nospc and is related to insufficient space on your system.
67111 verbose exit [ -95, true ]
Anyway, I ignored the message and I entered npm start and the following error occurs:
npm info it worked if it ends with ok
npm info using npm#3.8.6
npm info using node#v5.12.0
npm info lifecycle pluralsight-redux-starter#1.0.0~prestart: pluralsight-redux-starter#1.0.0
> pluralsight-redux-starter#1.0.0 prestart /www
> babel-node tools/startMessage.js
sh: 1: babel-node: not found
I tried npm list | grep babel to make sure that babel is installed, correctly and it looks like it's there. So what is wrong here? Please note that I'm new to Docker, Linux, NodeJS and NPM.
Thank you
Had/have the same issue, symlinks isn't supported, you can avoid them by typing npm install --no-bin-links <package> but the problem is... babel requires the symlinks.
Best solution: Get rid of windows and get mac/linux
Possible Solution: I am going to try this soon and use digital ocean.
Create digital ocean droplet, connect to it without using sym links, then connect this to docker, then run your files in docker. So symlinks will be allowed between docker and the droplet, but aren't necessary between your windows machine and the droplet.
If you try this let me know, otherwise I'll hopefully remember to come back and follow up!
It looks like that Symlinks on shared volumes are not supported in Docker for Windows.

AWS Elastic Beanstalk Node.js npm install error

During the deployment of an application, npm install is unable to install a very particular dependency:
npm ERR! enoent ENOENT: no such file or directory, chmod '/tmp/deployment/application/node_modules/babel-core/node_modules/regexpu/node_modules/regjsparser/node_modules/jsesc/bin/jsesc'
I was able to find that above error by ssh'ing into the particular EC2 instance hosting my Node application and running npm install via the command below:
sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install 2
Then follows with this generic failure:
Failed to run npm install. Snapshot logs for more details.
No environment variable EB_EVENT_FILE found. Writing message to stderr.
Msg: Failed to run npm install. Snapshot logs for more details.
What's weird is that I've been able to deploy successfully once before, and am using the same exact configurations for that previous deployment. My only command is npm start within .ebextensions/.
Within my package.json, I changed all dev dependencies into dependencies, as webpack is building during prestart.
This all builds and runs locally, by the way. Also I'm using Node 4.2.1 and npm 2.14.7 on EB.
Any help would be awesome. Thanks!
I ended up just creating and deploying a Docker container to solve this issue. Deploying to the environment provided by EB is too nondeterministic - the dependency tree wasn't created correctly.

Resources