问题
I can make code deployments no problem, everything works just fine. The problem is when I use either the Elastic Beanstalk web configuration form or the EB CLI to add/remove/modify ENV variables.
Elastic Beanstalk reports back that the change was made successfully however when I visit the web application in the browser I standard Rails error "Sorry, something went wrong".
SSH'ing into the server looking at the log files shows errors related to missing assets. Looking in the "public" folder of the application there is no longer an "assets" folder containing the precompiled assets which is normally present when I deploy a code change.
I have the following ENV settings in place which are likely relevant:
RAILS_SERVE_STATIC_FILES: true
RAILS_SKIP_ASSET_COMPILATION: false
RACK_ENV: production
RAILS_ENV: production
My production environment config:
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
config.assets.compile = false
config.active_storage.service = :amazon
config.force_ssl = ENV.fetch("FORCE_SSL", false)
config.ssl_options = { redirect: { exclude: ->(request) { request.path =~ /health-check/ } } }
config.log_level = :debug
config.log_tags = [:request_id]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
end
To fix the issue I just re-deploy the last committed code and the deployment process takes care of generating the missing precompiled assets.
Has anybody encountered this issue or have any insight into what is going on here? Thanks!
回答1:
I met a same problem.
Before 2020 Aug, We couldn't hook these events, but after the issue fixed and platform released for AL2, it became manageable.
You can hook beanstalk configuration changes with confighooks
.
Create .platform/confighooks/predeploy/01_assets_precompile.sh
like...
#!/bin/bash
source /root/.bash_profile
source <(sed -E -n 's/[^#]+/export &/ p' /opt/elasticbeanstalk/deployment/env)
cd /var/app/staging; bundle exec rake assets:precompile
chown -R webapp:webapp /var/app/staging/
Deploy these scripts, and change beanstalk's env vars.
See also.
- https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
- https://github.com/aws/elastic-beanstalk-roadmap/issues/59
来源:https://stackoverflow.com/questions/62600427/elastic-beanstalk-is-causing-my-rails-6-app-precompiled-assets-to-break-when-add