Ruby "bundle install" Openshift 错误

Ruby "bundle install" error on Openshift

我对 Ruby 和通过远程工具部署应用程序的术语还很陌生。我试图在免费的 openshift 帐户上部署我的应用程序。而且我不 运行 申请。

当我 运行 应用程序时,我收到此错误:

You have already activated rack 1.5.2, but your Gemfile requires rack 1.6.0.
Using bundle exec may solve this. (Gem::LoadError)

所以我尝试 运行 bundle exec 但我遇到了另一个错误:

Gemfile syntax error:
/var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/Gemfile:24: 
syntax error, unexpected ':', expecting $end
gem 'sdoc', '~> 0.4.0', group: :doc

我想这可能是因为我在本地使用 Ruby 2.1.5 而 Open shift 运行s 默认使用 Ruby 2.0。

我发现了这个话题How can I force a bundle install on OpenShift Online when my RAILS_ENV is set to development? 但我不知道我是否做对了。我什至不知道把这个 pre_build 文件放在哪里。我试着把它放在 /var/lib/openshift/xxxxxxxxxxxxxxxxxxxxxxxxxx/app-root/runtime/repo/.openshift/action_hooks/ 下。但我不确定 runtime 是否正确。

编辑 1:

这是我的 Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
group: :doc do
    gem 'sdoc', '~> 0.4.0'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]

解决方案:

正如@Rajarshi Das 所说,我必须改变

gem 'sdoc', '~> 0.4.0', group: :doc

进入

group: :doc do
    gem 'sdoc', '~> 0.4.0'
end

我不知道为什么。也许是一些语法问题,因为我在本地使用 Ruby 2.1.5,并且不得不在生产环境中使用 2.0.0。之后我不得不 运行 gem install rails 即使我使用 rails 快速启动。最后我不得不手动添加到 Gemfile gem 'nokogiri'。最后我可以 运行 bundle install 应用程序开始工作了。

您可以通过以下方式简单解决错误

 group :doc do
    gem 'sdoc', '~> 0.4.0'
 end

对于平台

platforms :jruby, :mingw, :mswin do
  gem 'tzinfo-data'
end

Gemfile.lock 删除为 You have already activated rack 1.5.2, but your Gemfile requires rack 1.6.0

然后勾选bundle install

我 ssh 到 $app_root 目录

gem install rack

有效

确保您的分支正在用于部署

rhc app-configure --deployment-branch [BRANCH]

然后在你的开发环境更新gems

# bundle install

它会改变Gemfile.lock

$ git add -A $ git commit -am "Updating gemfile" $ git push

等待部署更新

我尝试了这里的大部分解决方案,但仍然卡住了。问题是为正在使用的 ruby 当前版本安装捆绑包。你会想在 app-root/runtime/repo 中做一个 gem install bundler。 那么RAILS_ENV=production bundle exec rails console

可以参考这个answer