Skip to content

Instantly share code, notes, and snippets.

@jufemaiz
Created July 7, 2014 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jufemaiz/32b90c69101e7c704d10 to your computer and use it in GitHub Desktop.
Save jufemaiz/32b90c69101e7c704d10 to your computer and use it in GitHub Desktop.
.ebextensions/rails.config
files:
# Make the appropriate directories
"/opt/elasticbeanstalk/hooks/appdeploy/pre/020_bootstrap.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# /opt/elasticbeanstalk/hooks/appdeploy/pre/01a_bootstrap.sh
. /opt/elasticbeanstalk/containerfiles/envvars
# Change ownership of the Application Base Directory
chown $EB_CONFIG_APP_USER:$EB_CONFIG_APP_USER -R $EB_CONFIG_APP_BASE
# Create directories in the application ondeck directory
su -c "mkdir -p $EB_CONFIG_APP_ONDECK/vendor $EB_CONFIG_APP_ONDECK/public" $EB_CONFIG_APP_USER
# Create directories in the support directory
su -c "mkdir -p $EB_CONFIG_APP_SUPPORT/vendor_bundle $EB_CONFIG_APP_SUPPORT/assets" $EB_CONFIG_APP_USER
# Remove the log directory to use support directory
su -c "rm -rf $EB_CONFIG_APP_ONDECK/log" $EB_CONFIG_APP_USER
# Set the vendor directory properly
su -c "chmod go-w $EB_CONFIG_APP_ONDECK/vendor" $EB_CONFIG_APP_USER
# Simlink those directories
su -c "ln -s $EB_CONFIG_APP_SUPPORT/vendor_bundle $EB_CONFIG_APP_ONDECK/vendor/bundle" $EB_CONFIG_APP_USER
su -c "ln -sf $EB_CONFIG_APP_SUPPORT/assets $EB_CONFIG_APP_ONDECK/public" $EB_CONFIG_APP_USER
su -c "ln -sf $EB_CONFIG_APP_SUPPORT/pids $EB_CONFIG_APP_ONDECK/tmp/pids" $EB_CONFIG_APP_USER
su -c "ln -sf $EB_CONFIG_APP_SUPPORT/logs $EB_CONFIG_APP_ONDECK/log" $EB_CONFIG_APP_USER
# Add log files
su -c "touch $EB_CONFIG_APP_ONDECK/log/$RACK_ENV.log" $EB_CONFIG_APP_USER
su -c "touch $EB_CONFIG_APP_ONDECK/log/cron_log.log" $EB_CONFIG_APP_USER
su -c "touch $EB_CONFIG_APP_ONDECK/log/cron_error.log" $EB_CONFIG_APP_USER
true
encoding: plain
# Bundle install using deployment
"/opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install_deployment.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/containerfiles/envvars
cd $EB_CONFIG_APP_ONDECK
if [ -f Gemfile ]; then
echo "running 'bundle install --deployment' with Gemfile:"
cat Gemfile
if [ -d $EB_CONFIG_APP_ONDECK/vendor/cache ]; then
su -c "/usr/local/bin/bundle install --local --deployment" $EB_CONFIG_APP_USER
# Incase there is a gem that is missing from the cache
su -c "/usr/local/bin/bundle install --deployment" $EB_CONFIG_APP_USER
else
su -c "/usr/local/bin/bundle install --deployment" $EB_CONFIG_APP_USER
fi
if [ $? != 0 ]; then
echo "ERROR: bundle install failed!"
exit 1
else
echo "bundle install succeeded"
fi
else
echo "no Gemfile found! Skipping bundle install stage!"
fi
if [ -f Gemfile.lock ]; then
echo "encountered a Gemfile.lock, setting proper permissions"
chown $EB_CONFIG_APP_USER:$EB_CONFIG_APP_USER Gemfile.lock
else
echo "no Gemfile.lock file found, so no permissions to set on it"
fi
true
encoding: plain
commands:
# Use bundle exec instead of rake directly
001_replace_rake_with_bundle_exec_rake:
cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre
command: perl -pi -e 's/(\/usr\/local\/bin\/)(rake)/$1bundle exec $2/' 11_asset_compilation.sh 12_db_migration.sh
#
01_backup_existing_bundle_command:
test: test -f /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh
cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre
command: mv 10_bundle_install.sh 10_bundle_install.sh.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment