leaksterrr leaksterrr - 1 year ago 139
Node.js Question

Run Grunt on ElasticBeanstalk

I have a node application that requires grunt to do a "build" before the application can be executed successfully. (runs concat/minification/revving of source code etc). I've got this running on an EC2 instance with SSH access as I can just SSH into the directory and run Grunt as part of the deployment process. However to automate this I'm now moving the application to ElasticBeanstalk and I'm having difficulty getting the application to run grunt successfully. The reason for the move to EB is to keep SSH keys OFF live servers so these EB instances are setup with no ssh access.

There seems to be no official documentation available, could anybody point me in a good direction to be able to achieve the above? I need grunt to execute before the application is started so that the application has the files available (otherwise there'll be a 404).

Answer Source

Running grunt would be very similar to running gulp, so, i'll include my config below.

This is inside a .ebextensions folder at the root of my project, named 01run.config. You can have multiple config files, they will run in alphabetical order (hence the 01 at the beginning.)

This basically just instructs the process to run these commands in order, again, it's done in alphabetical order, so I named them accordingly.

    command: echo Defaults:root \!requiretty >> /etc/sudoers
    command: sudo yum -y --enablerepo=epel install nodejs npm
    command: sudo npm install -g bower
    command: sudo npm install -g gulp
    command: sudo yum -y --enablerepo=epel install git
    command: sudo bower install --allow-root
    command: sudo gulp sass
  1. Get sudo access
  2. install node.js and npm with yum
  3. install bower (my gulp process needed bower)
  4. install gulp
  5. install git (needed by bower)
  6. i then run two container commands, which happen after npm install and before npm start:
    1. bower install
    2. gulp sass

In your case, you'd simply remove bower and git installs, install grunt-cli, and then run grunt.

Since doing this, I've removed the need for the above process by doing it all up front before deploying and committing the built files to the git repository. It was at least a good learning experience that gives me much more control over my ec2 instances deployed by beanstalk.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download