在添加/删除 ENV 变量时,Elastic Beanstalk 导致我的 Rails 6 应用程序预编译资产损坏

2024-02-08

我可以使代码部署没有问题,一切正常。问题是当我使用 Elastic Beanstalk Web 配置表单或 EB CLI 添加/删除/修改 ENV 变量时。

Elastic Beanstalk 报告更改已成功完成,但是当我在浏览器中访问 Web 应用程序时,出现标准 Rails 错误“抱歉,出了点问题”。

通过 SSH 连接到服务器并查看日志文件,会显示与丢失资产相关的错误。查看应用程序的“公共”文件夹,不再有包含预编译资产的“资产”文件夹,该文件夹通常在我部署代码更改时出现。

我有以下可能相关的 ENV 设置:

RAILS_SERVE_STATIC_FILES: true
RAILS_SKIP_ASSET_COMPILATION: false
RACK_ENV: production
RAILS_ENV: production

我的生产环境配置:

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

为了解决这个问题,我只需重新部署最后提交的代码,部署过程会负责生成丢失的预编译资产。

有没有人遇到过这个问题或者对这里发生的事情有任何了解?


我遇到了同样的问题。

在 2020 年 8 月之前,我们无法挂钩这些事件,但在问题修复并为 AL2 发布平台后,它变得可以管理。

您可以使用以下命令挂钩 beanstalk 配置更改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/

部署这些脚本,并更改​​ beanstalk 的环境变量。

也可以看看。

  • https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
  • https://github.com/aws/elastic-beanstalk-roadmap/issues/59 https://github.com/aws/elastic-beanstalk-roadmap/issues/59
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在添加/删除 ENV 变量时,Elastic Beanstalk 导致我的 Rails 6 应用程序预编译资产损坏 的相关文章

随机推荐