Launch Grunt on ElasticBeanstalk

I have a node application that requires grunt to create an “assembly” before the application can execute successfully. (concat / minification / revving of the source code, etc. is performed). This works for me on an EC2 instance with SSH access, because I can just SSH into the directory and run Grunt as part of the deployment process. However, to automate this, I now move the application to ElasticBeanstalk, and it is difficult for me to get the application to run grunt successfully. The reason for migrating to EB is to keep SSH keys turned off by live servers so that these EB instances are configured without ssh access.

There seems to be no official documentation, can someone point me in a good direction to be able to achieve the above? I need grunt to execute before the application is launched so that the application has available files (otherwise it will be 404).

+8
amazon-web-services amazon-ec2 elastic-beanstalk
source share
2 answers

Running grunt will be very similar to running gulp, so I will include my configuration below.

This is located inside the .ebextensions folder in the root of my project named 01run.config . You may have several configuration files, they will work in alphabetical order (hence 01 at the beginning.)

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

commands: 01get_sudo: command: echo Defaults:root \!requiretty >> /etc/sudoers 02npm_install: command: sudo yum -y --enablerepo=epel install nodejs npm 03npm_install_bower: command: sudo npm install -g bower 04npm_install_gulp: command: sudo npm install -g gulp 05yum_install_git: command: sudo yum -y --enablerepo=epel install git container_commands: 01bower_install: command: sudo bower install --allow-root 02gulp_sass: command: sudo gulp sass 
  • Get access to sudo
  • install node.js and npm using yum
  • install the gazebo (my gulp process needs a gazebo)
  • install gulp
  • install git (necessary for the gazebo)
  • I then run the two container commands that occur after installing npm and before running npm:
    • bower installation
    • gulp sass

In your case, you just uninstall bower and git installs, install grunt-cli, and then run grunt.


After that, I removed the need for the above process by doing all this before deploying and transferring the embedded 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.

+12
source share

This doesn’t answer the question exactly, but according to Kevin B.’s last comment, I perform tasks, including assembly, outside of the Elastic Beanstalk and use .ebignore to control the deployment. When .ebignore is present, eb deploy follows it instead of .gitignore . This allows me to control the build process outside of Elastic Beanstalk, while saving build artifacts from my git repository.

For example, if build artifacts go to .build /

.gitignore

 node_modules .elastic_beanstalk ... .build 

.ebignore

 node_modules .elastic_beanstalk ... .git 

Remember to add .git to .ebignore so that the local git repository metadata is not deployed. In addition, I found that eb deploy evaluates all subfolders in the excluded folder, which slows down deployment unnecessarily. I had to temporarily move node_modules to another location before running eb deploy in order to speed it up.

+1
source share

All Articles