Installing global node packages over Amazon Elastic Beanstalk (EBS) - node.js

I have a node application deployed over amazon EBS and it was working fine till I wrote a gulp task to be executed before deploying the application. now this gulp task needs gulp to be installed globally on server.
I wrote container command in EBS config file to install gulp globally but I get following error while deploying the application,
Command npm (npm install -g gulp) failed
My config file looks something like this:
packages:
yum:
libcurl: []
libcurl-devel: []
container_commands:
npm:
command: "npm install -g gulp"
updatefunders:
command: "./update_data.sh"
I am kind of stuck with this and this issue is preventing us from deploying gulp related updates to EBS. Any help would be greatly appreciated.

Related

how to set grunt variable env path

I am trying to set grunt for my node.js project and I have followed below steps:
1)I have installed node.js and it is working fine.
2)Installed git.
3)Installed grun by running: npm install -g grunt-cli.
C:\Users\user\Downloads\bpost-gs-api-1.1.1>npm install -g grunt-cli
C:\Users\user\AppData\Roaming\npm\grunt -> C:\Users\891153\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
C:\Users\user\AppData\Roaming\npm
`-- grunt-cli#1.2.0
Now I have run the cmd grunt -version, I got below error:
grunt is not recognized as an internal or external command,
operable program or batch file.
Can you please help me to set up grunt for my project. How to setup variable env and how to setup path etc.
Appreciate your help
https://gruntjs.com/getting-started
In order to get started, you'll want to install Grunt's command line interface (CLI) globally. You may need to use sudo (for OSX, *nix, BSD etc) or run your command shell as Administrator (for Windows) to do this.
npm install -g grunt-cli
This will put the grunt command in your system path, allowing it to be run from any directory.
Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.
start from reading this:
https://gruntjs.com/installing-grunt
If you need a specific version of Grunt or a Grunt plugin, run npm install grunt#VERSION --save-dev where VERSION is the version you need.
for better understood on how to start setup a grunt project: https://gruntjs.com/getting-started#preparing-a-new-grunt-project
A typical setup will involve adding two files to your project: package.json and the Gruntfile.
package.json: This file is used by npm to store metadata for projects published as npm modules. You will list grunt and the Grunt plugins your project needs as devDependencies in this file.
Gruntfile: This file is named Gruntfile.js or Gruntfile.coffee and is used to configure or define tasks and load Grunt plugins. When this documentation mentions a Gruntfile it is talking about a file, which is either a Gruntfile.js or a Gruntfile.coffee.

serverless: command not found in ubuntu 16.04

I am trying to set up the AWS Serverless framework in Ubuntu 16.04 LTS. I installed Node.js and have also installed Serverless using the following command: npm install -g serverless in the terminal.
But when I try to run serverless it returns an error saying serverless: command not found. Below is a screenshot for reference:
Try running,
npm config set prefix /usr/local
and then,
npm i -g serverless
If the above options are not working (due to insufficient access or sudo access), following one will definitely work as it's saving the serverless into your local.
npm install serverless --save-dev
node ./node_modules/serverless/bin/serverless deploy
Reference link - https://serverless.com/framework/docs/providers/aws/guide/services/
Was getting the same error serverless: command not found but instead of NPM was using YARN. To fix it had to execute (or better add to your ~/.bash_profile):
export PATH="$PATH:$(yarn global bin)"
then, if not already installed:
yarn global add serverless
my recomendation here is to allways install the serverless framework as a dev dependency (npm install serverless --save-dev) specially if you're working in a team where each member can have its own version of the framework. After that, you can call the framework using npm scripts. For example, you can create a new entry in the scripts section like this: "deploy" : "serverless deploy" and call it using npm run deploy.
Try with the following order
npm config set prefix /usr/local
sudo npm i -g serverless
sudo /usr/bin/node /usr/local/lib/node_modules/serverless/node_modules/tabtab/src/cli.js install --name serverless --auto
Another option, following this post, is to try npx serverless ...

Install npm package globally on AWS Elastic Beanstalk

I'm trying to install an npm package globally on elastic beanstalk. This is what my config file looks like which I wrote based on this documentation.
container_commands:
install_phantom:
command: "npm install phantomjs -g"
And when I deploy to Elastic Beanstalk I get this error
Command failed on instance. Return code: 1 Output: Error occurred
during build: Command install_phantom failed .
Based on the answer given here, have you tried:
container_commands:
install_phantom:
command: "export PATH=$PATH; npm install phantomjs -g"
The environment variable for the node installation is NODE_HOME, so you should do this, to run npm or node in a container command in your config files:
container_commands:
install_phantom:
command: bash -c "PATH=$PATH:$NODE_HOME/bin npm install phantomjs -g"

Continuous integration and deployment of Node.js application on Bamboo

The application I want to implement continuous deployment on Bamboo has node modules and bower component dependencies. On the bamboo server nodejs, npm have been installed.
There are only three tasks on default job:
Source Code Checkout
Build dependencies:
npm install
bower install
Deploy to the staging server
The problem is on the second task, bamboo fails with the message "No failed tests found, a possible compilation error occurred." I don't even run any tests.
The log file is not explanatory at all:
Starting task 'Build dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
Failing task since return code of [/bin/sh /home/ubuntu/bamboo-installation/temp/WEB-WEB-JOB1-8-ScriptBuildTask-4430338079602360707.sh] was 1 while expected 0
Ok, I solved the problem. The issue was the wrong node (which obviously messed things up) was installed on the bamboo server. Uninstalled the wrong one and everything worked as expected.
Good to see you solved it.
There is a setup I use and which could prevent further problems with CI:
export npm_config_prefix=.npm/
export PATH=.npm/bin:$PATH
export CI=true
npm install -g bower
bower install
npm install
This installs bower (and others like grunt-cli if you want) in your project folder so you can e.g. have a specific version, sets CI=true as advised in bower docs, and then installs all dependencies.
Bamboo AMI originally have npm version 1.4.28 installed and you are probably using a more recent version on you development environment. I had the same issue and resolved it by creating a script task to update npm version on the very beginning of my build process. Here is the script:
# update npm
curl -O -L https://npmjs.org/install.sh
chmod +x install.sh
sudo PATH=$PATH:/opt/node-0.10/bin ./install.sh

Compile less files and minify js files in node.js project on AWS Elastic Beanstalk

I am using the Eb Command Line Interface to deploy a node.js project to AWS Elastic Beanstalk. I am using git for version control. So the command I run to deploy is simply 'git aws.push'.
Locally, I am using grunt to compile css files from less files and also minify and cmobine js files.
I don't want to include the *.min.css files or *.min.js files in my git repository but would rather have them recompiled on AWS after deployment.
Is there a way to do this? Maybe with a .ebextensions hook or something?
I am not familiar with grunt, but I guess what you would have to do is install nodejs and grunt on elastic beanstalk and then running your grunt commands once the container is set up.
In a ebextensions hook such as .ebextensions/grunt.config you could do the following :
commands:
01-install-nodejs-npm:
command: "yum install -y --enablerepo=epel nodejs npm"
02-install-grunt:
command: "npm install -g grunt-cli"
container_commands:
01-compilecss-minifyjs:
command: "grunt build mytask"
leader_only: true
The commands would make sure nodejs, npm and grunt are installed. The container_commands are executed from within your repository's home directory, so the "source" files for your grunt build should be available from there.
Again - I don't work with grunt and can't tell if this would actually work, but I hope it helps anyway.

Resources