不要以 root 身份运行 Bundler - Elastic Beanstalk 上的 Rails6
Posted
技术标签:
【中文标题】不要以 root 身份运行 Bundler - Elastic Beanstalk 上的 Rails6【英文标题】:Don't run Bundler as root - Rails6 on Elastic Beanstalk 【发布时间】:2021-02-28 20:39:08 【问题描述】:我一直在尝试将 Rails 6 应用程序部署到 Elastic Beanstalk,并且一天多来一直遇到此 Bundle Root 错误。我已经阅读了我能找到的所有内容,但到目前为止没有任何效果。
[ERROR] 执行命令 [app-deploy] - [stage ruby application] 期间发生错误。停止运行命令。错误:在 Gemfile 中安装依赖项失败,错误命令 /bin/sh -c bundle install --local 失败,错误命令在 900 秒后超时。标准错误:不要以 root 身份运行 Bundler。如果需要,Bundler 可以要求 sudo,并且 以 root 身份安装您的捆绑软件将破坏所有非 root 用户的此应用程序 这台机器上的用户。
我的宝石文件:
git_source(:github) |repo| "https://github.com/#repo.git"
ruby '2.7.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.3'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like javascript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# 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.7'
gem 'sendgrid-ruby'
gem 'faker'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'will_paginate', '~> 3.1.0'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'sprockets', '~> 4.0'
gem 'devise'
gem 'bootstrap'
gem 'jquery-rails'
gem 'figaro'
gem 'rails-controller-testing'
gem 'validates_zipcode'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'minitest'
gem 'minitest-reporters'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', '>= 1.2016.7'
我的 .ebextension/fix_rails_6.config:
packages:
yum:
git: []
commands:
02_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
03_install_nodejs:
command: "yum -y install nodejs"
container_commands:
19_precompile:
command: "bundle exec rake assets:precompile"
还有我的环境属性:
BUNDLER_DEPLOYMENT_MODE true
BUNDLE_WITHOUT test:development
RACK_ENV production
RAILS_SKIP_ASSET_COMPILATION true
RAILS_SKIP_MIGRATION false
【问题讨论】:
我不认为“不要以 root 身份运行捆绑程序”是一个实际问题。这真的只是一个警告。您是否可以通过 Elastic Beanstalk 控制台下载日志并查看是否可以获得有关错误的更多信息?看起来它卡在安装 Gem 上。检查日志文件,看看是哪一个卡住了。 有这个错误,但我昨天将所有内容升级到 5.0.4 时忽略了它。 AWS 服务器和我的代码(包括 Gemfile.lock)现在都是 5.0.4opt/rubies/ruby-2.7.2/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:312:in `check_for_activated_spec!': You have already activated puma 5.0.4, but you r Gemfile requires puma 4.3.6. Prepending bundle exec to your command may solve this. (Gem::LoadError)
好吧——我再深入一点,好像挂在nio4r上,和puma有些关系?
我建议终止现有服务器并让它启动一个新实例,或者短期使用不可变部署策略,这样您每次都可以在干净的实例上部署,直到遇到问题解决了。
@downtownott 你有没有启动并运行它?我遇到了同样的错误。
【参考方案1】:
我猜你在部署的服务器上有一个旧的、过时的Gemfile.lock
,其中列出了不正确的 Gems 版本。
如果它在本地构建和运行,我建议您确保将 Gemfile.lock
文件与其余代码和 Gemfile
一起分发到您的服务器。
如果这不起作用,请从部署的服务器中删除 Gemfile.lock
,然后重试
【讨论】:
以上是关于不要以 root 身份运行 Bundler - Elastic Beanstalk 上的 Rails6的主要内容,如果未能解决你的问题,请参考以下文章