I'm using Ruby 2.7 on Elastic Beanstalk, as described here in AWS docs . I'm running Rails 6.1.4.1. Rake is 13.0.6.
Whether or not Beanstalk executes db:migrate
is supposed to depend on the value of RAILS_SKIP_MIGRATIONS
, which defaults to false. I have made double-sure it is true by including it in my .ebextensions
setup, which I see executing:
commands:
01_install_yarn:
command: npm install yarn -g
02_symlink_yarn:
command: ln -s -f "$(npm bin --global)"/yarn /usr/bin/yarn
03_install_dependencies:
command: yum install postgresql-devel
option_settings:
aws:elasticbeanstalk:application:environment:
RAILS_SKIP_MIGRATIONS: false
In fact, I know for sure the value is false , because I can see it on the Beanstalk instance when I connect to it.
If you ssh to the host and run sudo cat /opt/elasticbeanstalk/deployment/env
, you see a dump of the environment -- all those config params, as well as injected RDS variables. Very handy for debugging:
$ sudo cat /opt/elasticbeanstalk/deployment/env
PATH=/opt/elasticbeanstalk/.rbenv/shims:/opt/elasticbeanstalk/.rbenv/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
RACK_ENV=production
RAILS_SKIP_MIGRATIONS=false
RAILS_SKIP_ASSET_COMPILATION=false
BUNDLE_WITHOUT=test:development
(etc)
However, /var/log/eb-engine.log
consistently skips migrations and shows this:
2021/11/11 23:17:52.261630 [INFO] Running command /bin/su webapp -c bundle exec /opt/elasticbeanstalk/config/private/checkforraketask.rb db:migrate
2021/11/11 23:17:57.083890 [INFO] Found db:migrate task in Rakefile
2021/11/11 23:17:57.083955 [INFO] Skipping db:migrate task (RAILS_SKIP_MIGRATIONS=true).
2021/11/11 23:17:57.083968 [INFO] Executing instruction: configure log streaming
It is showing true instead of false. And I cannot for the life of me figure out why.
I may sidestep this with a container_command
to force the task to execute, but I really want to know what's up. Is this a bug in Beanstalk? I can't seem to trace it any further; checkforraketask
just looks like this:
require 'rake'
Dir.chdir '/var/app/staging'
Rake.application.init
Rake.application.load_rakefile
tasks = Rake.application.tasks.collect(&:name)
exit 0 if tasks.include? ARGV[0]
exit 1
And Rakefile
like this:
require_relative "config/application"
Rails.application.load_tasks
There are no tasks in lib/tasks
, so I assume this output comes from that last line? I'm stuck. How do I get Beanstalk to recognize the correct value and run the migration?
I too would love to know the answer to this question.
As a workaround I created the following ebextension to solve the problem:
.ebextensions/03_rake-db-migrate.config
container_commands:
rake_db_migrate:
command: "RAILS_ENV=production bundle exec rake db:migrate"
Are you skipping asset compilation (RAILS_SKIP_ASSET_COMPILATION=true)?
In my case, when is true, the migrations are skipping too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.