添加/删除ENV变量时,Elastic Beanstalk导致我的Rails 6应用程序预编译资产损坏 [英] Elastic Beanstalk is causing my Rails 6 app precompiled assets to break when adding/removing ENV variables

查看:56
本文介绍了添加/删除ENV变量时,Elastic Beanstalk导致我的Rails 6应用程序预编译资产损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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报告说该更改已成功完成,但是当我在浏览器中访问Web应用程序时,我的标准Rails错误为抱歉,出了点问题".

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进入服务器,查看日志文件,显示与资产丢失有关的错误.在公众"中寻找应用程序文件夹中不再存在资产"文件夹.包含预编译资产的文件夹,该文件夹通常在我部署代码更改时出现.

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.

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

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

我的生产环境配置:

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!

推荐答案

我遇到了同样的问题.

在2020年8月之前,我们无法钩住这些事件,但是在解决了该问题并为AL2发布了平台之后,它变得可以管理了.

Before 2020 Aug, We couldn't hook these events, but after the issue fixed and platform released for AL2, it became manageable.

您可以使用 confighooks 挂钩beantalk的配置更改.

You can hook beanstalk configuration changes with confighooks.

像这样创建 .platform/confighooks/predeploy/01_assets_precompile.sh ...

#!/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/

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

Deploy these scripts, and change beanstalk's env vars.

另请参阅.

这篇关于添加/删除ENV变量时,Elastic Beanstalk导致我的Rails 6应用程序预编译资产损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆