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).
This does not exactly answer the question, but in line with Kevin B's last remark, I do grunt tasks, including build, outside of 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 keeping build artifacts out of my git repo.For example, if build artifacts go to .build/
.gitignore
.ebignore
Remember to add
.git
in .ebignore to prevent local git repo metadata from getting deployed. Also, I find thateb deploy
evaluates all subfolders within an excluded folder, slowing the deployment unnecessarily. I had to temporarily move node_modules elsewhere before runningeb deploy
to speed it up.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.
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.