为啥我的 Rails 应用程序无法部署到 AWS Elastic Beanstalk?
Posted
技术标签:
【中文标题】为啥我的 Rails 应用程序无法部署到 AWS Elastic Beanstalk?【英文标题】:Why is my Rails App failing to deploy to AWS Elastic Beanstalk?为什么我的 Rails 应用程序无法部署到 AWS Elastic Beanstalk? 【发布时间】:2019-07-24 18:08:37 【问题描述】:当我将应用程序部署到他们的服务时,AWS Elastic Beanstalk 从不接受我的应用程序。我试图通过阅读日志来解决所有问题,但似乎没有任何效果。我的开发 IDE 是 Rubymine / ruby 2.4.5 / Rails 5.2.0 / Windows 10 Pro x64 / Bundler 版本 1.16.4。我收到的错误如下。如何将我的应用程序成功部署到 AWS Elastic Beanstalk? 在开发过程中,无论如何启动应用程序我都没有问题。我尝试以尽可能少的依赖项启动应用程序。我清除了资产缓存。我删除了不必要的文件。似乎没有什么能让 Elastic Beanstalk 满意。 (这是我第一次使用该服务)
注意事项:我正在为这个特定的应用程序使用 actioncable
database.yml
production:
adapter: postgresql
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
cable.yml
development:
adapter: async
test:
adapter: async
production:
adapter: postgresql
url: <%= ENV["REDIS_URL"] %>
channel_prefix: <%= ENV['CABLE_CHANNEL_PREFIX'] %>
宝石
ruby 2.4.5p335 (2018-10-18 revision 65137) [x64-mingw32]
错误日志:
-------------------------------------
/var/log/eb-commandprocessor.log
-------------------------------------
gem 'loofah-activerecord'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'rails', '5.2.0' # '~>5.1.1' 5.1.6
# Use postgresql as the database for Active Record
#gem 'derailed_benchmarks', group: :development
gem 'pg', '~> 1.1', '>= 1.1.4'
gem 'puma', '~> 2.16'
# Use SCSS for stylesheets
gem 'sass-rails'
# Use Uglifier as compressor for javascript assets
gem 'uglifier', '~> 4.1', '>= 4.1.20'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~>3.1.11', platforms: [:ruby, :x64_mingw, :mingw]
#gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', require: 'bcrypt'
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :test do
gem 'capybara', '~> 2.15', '>= 2.15.4'
gem 'factory_bot_rails', '~> 4.0'
gem 'guard-rspec'
gem 'rspec-rails', '~> 3.4', '>= 3.4.2'
gem 'rubocop-rspec'
gem 'stripe-ruby-mock', '~> 2.5.4', require: 'stripe_mock'
gem 'webmock'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
platform :mswin, :mingw, :x64_mingw do
gem 'tzinfo-data'
gem 'byebug', platforms: %i[mri mingw x64_mingw], group: :development
end
gem 'rubocop', require: false
+ '[' -d /var/app/ondeck/vendor/cache ']'
+ bundle install --deployment --local
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root users on this machine.
Your bundle only supports platforms ["x64-mingw32"] but your local platforms are
["ruby", "x86_64-linux"], and there's no compatible match between those two lists. (Executor::NonZeroExitStatus)
[2019-03-03T05:36:01.585Z] ERROR [27678] : Command CMD-AppDeploy failed!
[2019-03-03T05:36:01.586Z] INFO [27678] : Command processor returning results:
"status":"FAILURE","api_version":"1.0","results":["status":"FAILURE","msg":"(TRUNCATED)...ling your bundle as root will break this application for all non-root\nusers on this machine.\nYour bundle only supports platforms [\"x64-mingw32\"] but your local platforms are\n[\"ruby\", \"x86_64-linux\"], and there's no compatible match between those two\nlists. \nHook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":16,"events":[]],"truncated":"true"
[2019-03-03T05:39:21.557Z] DEBUG [27906] : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-03T05:39:21.557Z] DEBUG [27906] : Checking if the command processor should execute...
[2019-03-03T05:39:21.559Z] DEBUG [27906] : Checking whether the command is applicable to instance (i-02c427cad88fc3a3e)..
[2019-03-03T05:39:21.559Z] INFO [27906] : Command is applicable to this instance (i-02c427cad88fc3a3e)..
[2019-03-03T05:39:21.559Z] DEBUG [27906] : Checking if the received command stage is valid..
[2019-03-03T05:39:21.559Z] INFO [27906] : No stage_num in command. Valid stage..
[2019-03-03T05:39:21.560Z] INFO [27906] : Received command CMD-TailLogs: "execution_data"=>"*", "instance_ids"=>["i-02c43eeewfefwfw"], "data"=>"betetet--reeetetetete5", "command_name"=>"CMD-TailLogs", "api_version"=>"1.0", "resource_name"=>"AWSEBAutoScalingGroup", "request_id"=>"b100000-2222-2222-2222-22222222"
[2019-03-03T05:39:21.560Z] INFO [27906] : Command processor should execute command.
[2019-03-03T05:39:21.560Z] DEBUG [27906] : Storing current stage..
[2019-03-03T05:39:21.560Z] DEBUG [27906] : Stage_num does not exist. Not saving null stage. Returning..
[2019-03-03T05:39:21.560Z] DEBUG [27906] : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-03T05:39:21.560Z] DEBUG [27906] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2019-03-03T05:39:21.560Z] DEBUG [27906] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2019-03-03T05:39:21.561Z] INFO [27906] : Found enabled addons:
["logstreaming", "logpublish"].
[2019-03-03T05:39:21.562Z] INFO [27906] : Updating Command definition of addon logstreaming.
[2019-03-03T05:39:21.562Z] INFO [27906] : Updating Command definition of addon logpublish.
[2019-03-03T05:39:21.562Z] DEBUG [27906] : Loaded definition of Command CMD-TailLogs.
[2019-03-03T05:39:21.562Z] INFO [27906] : Executing CMD-TailLogs
[2019-03-03T05:39:21.562Z] INFO [27906] : Executing command: CMD-TailLogs...
[2019-03-03T05:39:21.562Z] INFO [27906] : Executing command CMD-TailLogs activities...
[2019-03-03T05:39:21.562Z] DEBUG [27906] : Setting environment variables..
[2019-03-03T05:39:21.562Z] INFO [27906] : Running AddonsBefore for command CMD-TailLogs...
[2019-03-03T05:39:21.563Z] DEBUG [27906] : Running stages of Command CMD-TailLogs from stage 0 to stage 0...
[2019-03-03T05:39:21.563Z] INFO [27906] : Running stage 0 of command CMD-TailLogs...
[2019-03-03T05:39:21.563Z] DEBUG [27906] : Loaded 1 actions for stage 0.
[2019-03-03T05:39:21.563Z] INFO [27906] : Running 1 of 1 actions: TailLogs...
【问题讨论】:
【参考方案1】:您的 Gemfile.lock
是在 Windows(x64-mingw32
平台)上生成的,并且包含与 Linux 不兼容的 gem 版本。但亚马逊只支持ruby
或x86_64-linux
平台。
Your bundle only supports platforms ["x64-mingw32"] but your local platforms are
["ruby", "x86_64-linux"], and there's no compatible match between those two lists.
这基本上意味着您根本无法在 Linux 机器(或 Mac)上使用当前的 Gemfile.lock
。您将需要在该操作系统上运行 bundle update
(而不是 bundle install
)以允许捆绑程序找到一组新的匹配 gem 版本。
当然,这有点冒险,因为您可能会在生产系统上运行其他 gem 版本,而不是在开发环境中,因此我建议在部署时实际切换到新版本之前再次运行测试。
当您计划定期开发 Ruby on Rails 应用程序时,我建议您切换到 Linux 作为您的本地开发环境。虚拟机中的 Linux 或通过 docker 映像可能是您的另一个选择。
【讨论】:
我完全同意。我不知道任何人如何从 Windows 开发 Rails 应用程序 - 光是想想就让我头疼。 我将使用我的 Ubuntu 实例创建一个模拟 Rails 5.2.0 应用程序。拉出默认值并将它们放在 gemfile 中...重新初始化 gems 并为 Linux 配置它们。谢谢。【参考方案2】:虽然您可能应该使用某种虚拟机来为生产环境开发 ruby/rails,但现在尝试在您的 gemfile 中更改它:
group :development do
gem 'byebug'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'web-console', '>= 3.3.0'
gem 'rubocop', require: false
end
您可以删除它来测试您的部署:
platform :mswin, :mingw, :x64_mingw do
gem 'tzinfo-data'
gem 'byebug', platforms: %i[mri mingw x64_mingw], group: :development
end
你应该只需要 rubocop 在开发中,所以也将它移到开发块中。
然后运行
bundle install
然后再次尝试部署
【讨论】:
以上是关于为啥我的 Rails 应用程序无法部署到 AWS Elastic Beanstalk?的主要内容,如果未能解决你的问题,请参考以下文章
Rails 部署到 AWS ElasticBeanstalk/RDS 失败
AWS Elastic Beanstalk 上的 Rails 应用程序:错误的 nginx 配置
在 AWS opsworks 部署应用程序。为啥随机部署失败?
部署后无法在 EC2 上运行 command rails 控制台
Rails 4 + Capistrano + AWS Net::SSH::AuthenticationFailed: 部署