Skip to content

Instantly share code, notes, and snippets.

@luisacarrion
Created February 7, 2017 20:41
Show Gist options
  • Save luisacarrion/0e1f4ba3f9b336414efa3cf3ab1014cc to your computer and use it in GitHub Desktop.
Save luisacarrion/0e1f4ba3f9b336414efa3cf3ab1014cc to your computer and use it in GitHub Desktop.
AWS Elastic Beanstalk .ebextensions - rake db:seed based on 12_db_migration.sh
files:
# Files in the location /opt/elasticbeanstalk/hooks/appdeploy/pre/
# are executed before the app is deployed and are executed in alphabetical order.
"/opt/elasticbeanstalk/hooks/appdeploy/pre/13_db_seed.sh":
mode: "000755"
owner: root
group: root
content: |
# The content of this file is based on the content of /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh
#!/usr/bin/env bash
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
. $EB_SUPPORT_DIR/envvars
RAKE_TASK="db:seed"
. $EB_SCRIPT_DIR/use-app-ruby.sh
cd $EB_APP_STAGING_DIR
if su -s /bin/bash -c "bundle exec $EB_SCRIPT_DIR/check-for-rake-task.rb $RAKE_TASK" $EB_APP_USER; then
su -s /bin/bash -c "leader_only bundle exec rake db:seed" $EB_APP_USER
else
echo "No $RAKE_TASK task in Rakefile, skipping database seeding."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment