Skip to content

Instantly share code, notes, and snippets.

@thebadmonkeydev
Forked from igorescobar/rails_db_migrate.sh
Created November 7, 2017 08:32
Show Gist options
  • Save thebadmonkeydev/16b6e0f7a44f2faac11fb8175bf1e424 to your computer and use it in GitHub Desktop.
Save thebadmonkeydev/16b6e0f7a44f2faac11fb8175bf1e424 to your computer and use it in GitHub Desktop.
The correct way to run rails db migration on AWS Beanstalk (Docker Container Environment)
#!/bin/bash
# .ebextensions/scripts/db_migrate.sh
. /opt/elasticbeanstalk/hooks/common.sh
EB_SUPPORT_FILES=$(/opt/elasticbeanstalk/bin/get-config container -k support_files_dir)
EB_CONFIG_DOCKER_ENV_ARGS=()
while read -r ENV_VAR; do
EB_CONFIG_DOCKER_ENV_ARGS+=(--env "$ENV_VAR")
done < <($EB_SUPPORT_FILES/generate_env)
echo "Running migrations for aws_beanstalk/staging-app"
docker run --rm "${EB_CONFIG_DOCKER_ENV_ARGS[@]}" -t aws_beanstalk/staging-app bundle exec rake db:migrate || echo "The Migrations failed to run."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment