I know that you can run tasks as part of each deploy, but I only want to bootstrap the database once.
I used the information provided at this address to create a script that will run AFTER migrations and after each deploy: http://www.emind.co/how-to/how-to-run-rake-dbseed-in-amazon-elastic-beanstalk
I preferred this method so that I could keep track of the file on the EC2 instance. When I initially deployed this on my old servers (which were running Linux <1.0.9) I had no issue. However, I recently had to upgrade the server machines to 64bit Amazon Linux 2014.03 v1.0.9 running Ruby 2.0 (Puma) and the script began to fail. It will likely fail if you are using different Linux versions.
The key here is /usr/local/bin/ to your rake command to use the proper rake. I took this directly from the other scripts found at /opt/elasticbeanstalk/hooks/appdeploy/pre/:
#.ebextensions/db_seed.config
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/13_db_seed.sh":
mode: "00755"
owner: root
group: root
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/containerfiles/envvars
cd $EB_CONFIG_APP_ONDECK
su -c "leader_only /usr/local/bin/rake db:seed" $EB_CONFIG_APP_USER ||
echo "Rake task failed to run, skipping seeding."
true
It should be noted that this script is still not correct as I am not running "bundle exec rake" which is highly advised if you plan to run any rake command (it's a feature request currently on AWS for other scripts). If you wish to have ALL scripts run the bundle exec before "rake" take a look at the .config files posted here: https://github.com/alienfast/elastic-beanstalk
If this still doesn't work for you, I suggest sshing to one of your EC2 instances that are running your app, or deploy a new one running the same Linux/Ruby version and navigate to the "/opt/elasticbeanstalk/hooks/appdeploy/pre/" to see what the other scripts are doing.
I hope others find this useful!