为什么在 `bundle --deployment` 之后不能在生产环境中找到 gem?

Why can't bundle find gems in production after `bundle --deployment`?

以下是我的问题的摘要: 我建立了一个新服务器 我安装了 Rubinius 和其他一些东西 as documented here。 我部署了。该站点已准备好进行多次部署。 在某些时候,我遇到了问题并开始尝试 运行dom 解决方案。我 运行 遇到了捆绑程序的问题,无法解决。 沮丧的是,我建立了一个全新的服务器。我仍然有问题。这表明我的代码或我的 capist运行o 脚本有问题...但是我在开发中没有遇到任何捆绑程序问题,我回到了早期工作的 capist运行o 脚本并且没有快乐。所以我很困惑。如有任何想法,我们将不胜感激。

Xena 是第二台机器。这是我在部署后得到的:

production@xena:~/lexicon/current$ ruby -v
rubinius 2.4.1 (2.1.0 b332f133 2014-12-04 3.4 JI) [x86_64-linux-gnu]

Capist运行o 运行 这个命令,但我又做了一次只是为了显示结果:

production@xena:~/lexicon/current$ /usr/local/bin/chruby-exec rbx-2.4.1 -- bundle install --binstubs /home/production/lexicon/shared/bin --path /home/production/lexicon/shared/bundle --without development test --deployment
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.1
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Using activesupport 4.2.0
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using nokogiri 1.6.5
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.5
Using loofah 2.0.1
Using rails-html-sanitizer 1.0.1
Using actionview 4.2.0
Using rack 1.6.0
Using rack-test 0.6.3
Using actionpack 4.2.0
Using globalid 0.3.0
Using activejob 4.2.0
Using mime-types 2.4.3
Using mail 2.6.3
Using actionmailer 4.2.0
Using activemodel 4.2.0
Using arel 6.0.0
Using activerecord 4.2.0
Using bcrypt 3.1.9
Using climate_control 0.0.3
Using cocaine 0.5.5
Using commonjs 0.2.7
Using execjs 2.2.2
Using tilt 1.4.1
Using haml 4.0.6
Using hike 1.2.3
Using thor 0.19.1
Using railties 4.2.0
Using jquery-rails 4.0.3
Using jquery-ui-rails 5.0.3
Using less 2.6.0
Using less-rails 2.6.0
Using libv8 3.16.14.7
Using multi_json 1.10.1
Using mysql2 0.3.17
Using net-ssh 2.7.0
Using paperclip 4.2.1
Using polyamorous 1.1.0
Using psych 2.0.9
Using puma 2.10.2
Using bundler 1.7.11
Using sprockets 2.12.3
Using sprockets-rails 2.2.2
Using rails 4.2.0
  ing ransack 1.6.1
▽sing redcarpet 3.2.2
Using ref 1.0.5
Using rollbar 1.4.0
Using simple_form 3.1.0
Using therubyracer 0.12.1
Using twitter-bootstrap-rails 3.2.1 from https://github.com/seyhunak/twitter-bootstrap-rails.git (at master)
Using uglifier 2.7.0
Using valuable 0.9.9
Using warden 1.2.3
Using will_paginate 3.0.7
Using will_paginate-bootstrap 1.0.1
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into /home/production/lexicon/shared/bundle

然后我尝试 运行 rails:

production@xena:~/lexicon/current$ bin/rails c
Could not find i18n-0.7.0 in any of the sources
Run `bundle install` to install missing gems.

也许通过捆绑器?:

production@xena:~/lexicon/current$ bundle exec rails c
bundler: command not found: rails
Install missing gem executables with `bundle install`

我的捆绑器配置。我知道 rubinius 和 psych 有一些奇怪的问题,但这似乎没问题:

production@xena:~/lexicon/current$ vim .bundle/config
--- !ruby/hash-with-ivars
elements:
  BUNDLE_FROZEN: '1'
  BUNDLE_PATH: "/home/production/lexicon/shared/bundle"
  BUNDLE_BIN: "/home/production/lexicon/shared/bin"
  BUNDLE_WITHOUT: development:test
  BUNDLE_DISABLE_SHARED_GEMS: '1'
ivars:
  :@capacity: 16
  :@max_entries: 12
  :@entries: !ruby/object:Rubinius::Tuple {}
  :@state: &1 !ruby/object:Hash::State
    tail: &5 !ruby/object:Hash::Bucket
      link:
      state: *1
      value: '1'
      previous: &2 !ruby/object:Hash::Bucket
        link:
        state: *1

好吧,让我们确保那里有一些宝石:

production@xena:~/lexicon/current$ ls /home/production/lexicon/shared/bundle/rbx/2.1/bin/
erubis  lessc     puma     rackup  rake       sprockets  tilt
haml    nokogiri  pumactl  rails   redcarpet  thor

似乎是对的...

production@xena:~/lexicon/current$ ls /home/production/lexicon/shared/bundle/rbx/2.1/gems

actionmailer-4.2.0            net-ssh-2.7.0
actionpack-4.2.0              nokogiri-1.6.5
actionview-4.2.0              paperclip-4.2.1
activejob-4.2.0               polyamorous-1.1.0
activemodel-4.2.0             psych-2.0.9
activerecord-4.2.0            puma-2.10.2
activesupport-4.2.0           rack-1.6.0
arel-6.0.0                    rack-test-0.6.3
bcrypt-3.1.9                  rails-4.2.0
builder-3.2.2                 rails-deprecated_sanitizer-1.0.3
climate_control-0.0.3         rails-dom-testing-1.0.5
cocaine-0.5.5                 rails-html-sanitizer-1.0.1
commonjs-0.2.7                railties-4.2.0
erubis-2.7.0                  rake-10.4.2
execjs-2.2.2                  ransack-1.6.1
globalid-0.3.0                redcarpet-3.2.2
haml-4.0.6                    ref-1.0.5
hike-1.2.3                    rollbar-1.4.0
i18n-0.7.0                    simple_form-3.1.0
jquery-rails-4.0.3            sprockets-2.12.3
jquery-ui-rails-5.0.3         sprockets-rails-2.2.2
json-1.8.2                    therubyracer-0.12.1
less-2.6.0                    thor-0.19.1
less-rails-2.6.0              thread_safe-0.3.4
libv8-3.16.14.7-x86_64-linux  tilt-1.4.1
loofah-2.0.1                  tzinfo-1.2.2
mail-2.6.3                    uglifier-2.7.0
mime-types-2.4.3              valuable-0.9.9
mini_portile-0.6.2            warden-1.2.3
minitest-5.5.1                will_paginate-3.0.7
multi_json-1.10.1             will_paginate-bootstrap-1.0.1
mysql2-0.3.17

如果您能帮助找出为什么捆绑器找不到它刚刚放置的文件,我们将不胜感激。

添加到您的 Gemfile:gem 'i18n', '~> 0.7.0'

然后运行bundle update i18n

在#rubinius 上的 brixen 和 yorickpeterse 的帮助下,我们发现造成这种混乱的根本原因是 psych 高于 2.0.8。

#with rbx 2.4.1 and psych 2.0.8
rbx-2.4.1 :003 > YAML.dump({fu: 'bar'})
=> "---\n:fu: bar\n"

但是当你更新版本时问题就来了:

rbx-2.4.1 :005 > YAML.dump({fu: 'bar'})
=> "--- !ruby/hash-with-ivars\nelements:\n  :fu: bar\nivars:\n  :@entries: !ruby/object:Rubinius::Tuple {}\n  :@capacity: 16\n  :@size: 1\n  :@max_entries: 12\n  :@state: &1 !ruby/object:Hash::State\n    compare_by_identity: false\n    head: &2 !ruby/object:Hash::Bucket\n      key_hash: 2112643688174279348\n      value: bar\n      link: \n      state: *1\n      key: :fu\n    tail: *2\n  :@mask: 15\n"

Capistrano 在创建 .bundle/config 时发出 YAML。似乎 Capistrano 无法读取其配置文件的 "creative" 版本,因此它返回到默认值。

在我的生产机器上安装 psych 2.0.6 并更正我的 gemfile 后,我就能够成功部署。

参考资料