Capistrano 的损坏 Gemfile.lock 错误

Corrupt Gemfile.lock Error with Capistrano

我正在尝试使用 Capistrano 部署我的应用程序,但出现此错误:

Your Gemfile.lock is corrupt. The following gem is missing from the DEPENDENCIES
section: 'nokogiri'

我看到了这个问题,不幸的是,解决方案(切换 Bundler 版本)对我不起作用:

我试过:在将 nokogiri 添加到我的 gemfile 后删除 gemfile.lock(并执行 bundle _1.10.6_ install),但我仍然遇到相同的错误。

这是我的 gemfile:

source 'http://rubygems.org' 

gem 'rails', '4.2.5'
gem 'mysql2', '0.4.2'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails', '4.0.5'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc

gem 'whenever', '0.9.4', :require => false
gem 'simple_form', '3.2.0' 
gem 'devise', '3.5.2' 
gem 'omniauth-facebook', '3.0.0' 
gem "cocoon", '1.2.6' 
gem "paperclip", "~> 4.3" 
gem 'braintree', '2.55.0'
gem 'figaro', '~> 0.7.0'
gem 'activeadmin', github: 'activeadmin' 
gem 'aws-sdk-v1', '1.66.0'
gem 'transloadit-rails', '1.1.2' 
gem 'ratyrate', '1.2.2.alpha' 
gem "mediaelement_rails", '0.8.2' 
gem 'will_paginate', '~> 3.0.6' 
gem 'will_paginate-bootstrap', '1.0.1' 
gem 'ransack', '1.7.0' 
gem 'jquery-turbolinks', '2.1.0' 
gem 'meta-tags', '2.1.0' 
gem 'sitemap_generator', '5.1.0' 
gem 'nokogiri'

我的gemfile.lock:

GIT
  remote: git://github.com/activeadmin/activeadmin.git
  revision: ab1d8d1a4a1af748ae7009d9d725193d780d0059
  specs:
    activeadmin (1.0.0.pre2)
      arbre (~> 1.0, >= 1.0.2)
      bourbon
      coffee-rails
      formtastic (~> 3.1)
      formtastic_i18n
      inherited_resources (~> 1.6)
      jquery-rails
      jquery-ui-rails
      kaminari (~> 0.15)
      rails (>= 3.2, < 5.0)
      ransack (~> 1.3)
      sass-rails

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (4.2.5)
      actionpack (= 4.2.5)
      actionview (= 4.2.5)
      activejob (= 4.2.5)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.5)
      actionview (= 4.2.5)
      activesupport (= 4.2.5)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.5)
      activesupport (= 4.2.5)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.5)
      activesupport (= 4.2.5)
      globalid (>= 0.3.0)
    activemodel (4.2.5)
      activesupport (= 4.2.5)
      builder (~> 3.1)
    activerecord (4.2.5)
      activemodel (= 4.2.5)
      activesupport (= 4.2.5)
      arel (~> 6.0)
    activesupport (4.2.5)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    arbre (1.0.3)
      activesupport (>= 3.0.0)
    arel (6.0.3)
    aws-sdk-v1 (1.66.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
    bcrypt (3.1.10-x86-mingw32)
    bourbon (3.2.4)
      sass (~> 3.2)
      thor
    braintree (2.55.0)
      builder (>= 2.0.0)
    builder (3.2.2)
    chronic (0.10.2)
    climate_control (0.0.3)
      activesupport (>= 3.0)
    cocaine (0.5.8)
      climate_control (>= 0.0.3, < 1.0)
    cocoon (1.2.6)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.10.0)
    devise (3.5.2)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      responders
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    domain_name (0.5.25)
      unf (>= 0.0.5, < 1.0.0)
    erubis (2.7.0)
    execjs (2.6.0)
    faraday (0.9.2)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.10-x86-mingw32)
    figaro (0.7.0)
      bundler (~> 1.0)
      rails (>= 3, < 5)
    formtastic (3.1.3)
      actionpack (>= 3.2.13)
    formtastic_i18n (0.4.1)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    has_scope (0.6.0)
      actionpack (>= 3.2, < 5)
      activesupport (>= 3.2, < 5)
    hashie (3.4.3)
    hike (1.2.3)
    http-cookie (1.0.2)
      domain_name (~> 0.5)
    i18n (0.7.0)
    inherited_resources (1.6.0)
      actionpack (>= 3.2, < 5)
      has_scope (~> 0.6.0.rc)
      railties (>= 3.2, < 5)
      responders
    jbuilder (2.4.0)
      activesupport (>= 3.0.0, < 5.1)
      multi_json (~> 1.2)
    jquery-rails (4.0.5)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-turbolinks (2.1.0)
      railties (>= 3.1.0)
      turbolinks
    jquery-ui-rails (5.0.5)
      railties (>= 3.2.16)
    json (1.8.3)
    jwt (1.5.2)
    kaminari (0.16.3)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    mediaelement_rails (0.8.2)
      jquery-rails (>= 1.0)
      railties (>= 3.1)
    meta-tags (2.1.0)
      actionpack (>= 3.0.0)
    mime-types (2.99)
    mimemagic (0.3.0)
    mini_portile2 (2.0.0)
    minitest (5.8.3)
    multi_json (1.11.2)
    multi_xml (0.5.5)
    multipart-post (2.0.0)
    mysql2 (0.4.2-x86-mingw32)
    netrc (0.11.0)
    nokogiri (1.6.7.1-x86-mingw32)
      mini_portile2 (~> 2.0.0.rc2)
    oauth2 (1.0.0)
      faraday (>= 0.8, < 0.10)
      jwt (~> 1.0)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (~> 1.2)
    omniauth (1.3.1)
      hashie (>= 1.2, < 4)
      rack (>= 1.0, < 3)
    omniauth-facebook (3.0.0)
      omniauth-oauth2 (~> 1.2)
    omniauth-oauth2 (1.4.0)
      oauth2 (~> 1.0)
      omniauth (~> 1.2)
    orm_adapter (0.5.0)
    paperclip (4.3.2)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      cocaine (~> 0.5.5)
      mime-types
      mimemagic (= 0.3.0)
    polyamorous (1.3.0)
      activerecord (>= 3.0)
    quiet_assets (1.1.0)
      railties (>= 3.1, < 5.0)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.5)
      actionmailer (= 4.2.5)
      actionpack (= 4.2.5)
      actionview (= 4.2.5)
      activejob (= 4.2.5)
      activemodel (= 4.2.5)
      activerecord (= 4.2.5)
      activesupport (= 4.2.5)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.5)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.2)
      loofah (~> 2.0)
    railties (4.2.5)
      actionpack (= 4.2.5)
      activesupport (= 4.2.5)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.4.2)
    ransack (1.7.0)
      actionpack (>= 3.0)
      activerecord (>= 3.0)
      activesupport (>= 3.0)
      i18n
      polyamorous (~> 1.2)
    ratyrate (1.2.2.alpha)
    rdoc (4.2.1)
      json (~> 1.4)
    responders (2.1.1)
      railties (>= 4.2.0, < 5.1)
    rest-client (1.8.0-x86-mingw32)
      ffi (~> 1.9)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 3.0)
      netrc (~> 0.7)
    sass (3.2.19)
    sass-rails (4.0.5)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.2.2)
      sprockets (~> 2.8, < 3.0)
      sprockets-rails (~> 2.0)
    sdoc (0.4.1)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    simple_form (3.2.0)
      actionpack (~> 4.0)
      activemodel (~> 4.0)
    sitemap_generator (5.1.0)
      builder
    sprockets (2.12.4)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.3.3)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (1.4.1)
    transloadit (1.2.0)
      mime-types (~> 2.99)
      multi_json
      rest-client
    transloadit-rails (1.1.2)
      mime-types (~> 2.99)
      railties (>= 3)
      transloadit (>= 1.1.1)
    turbolinks (2.5.3)
      coffee-rails
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    tzinfo-data (1.2015.7)
      tzinfo (>= 1.0.0)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.1-x86-mingw32)
    warden (1.2.4)
      rack (>= 1.0)
    whenever (0.9.4)
      chronic (>= 0.6.3)
    will_paginate (3.0.7)
    will_paginate-bootstrap (1.0.1)
      will_paginate (>= 3.0.3)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  activeadmin!
  aws-sdk-v1 (= 1.66.0)
  braintree (= 2.55.0)
  cocoon (= 1.2.6)
  coffee-rails (~> 4.0.0)
  devise (= 3.5.2)
  figaro (~> 0.7.0)
  jbuilder (~> 2.0)
  jquery-rails (= 4.0.5)
  jquery-turbolinks (= 2.1.0)
  mediaelement_rails (= 0.8.2)
  meta-tags (= 2.1.0)
  mysql2 (= 0.4.2)
  nokogiri
  omniauth-facebook (= 3.0.0)
  paperclip (~> 4.3)
  quiet_assets
  rails (= 4.2.5)
  ransack (= 1.7.0)
  ratyrate (= 1.2.2.alpha)
  sass-rails (~> 4.0.3)
  sdoc (~> 0.4.0)
  simple_form (= 3.2.0)
  sitemap_generator (= 5.1.0)
  transloadit-rails (= 1.1.2)
  turbolinks (= 2.5.3)
  tzinfo-data
  uglifier (>= 1.3.0)
  whenever (= 0.9.4)
  will_paginate (~> 3.0.6)
  will_paginate-bootstrap (= 1.0.1)

BUNDLED WITH
   1.10.6

看起来您正在 Windows 机器上开发。我的猜测是您正在尝试部署到 Linux。很抱歉,这行不通。

您会注意到您的 Gemfile.lock 引用了 x86-mingw32 版本的 Nokogiri,它不能在服务器上使用。

不幸的是,没有简单的解决方案。 Heroku 通过在部署期间完全删除 Gemfile.lock 来解决这个问题,这会强制 Bundler re-resolve 所有依赖项。这行得通,但现在您的依赖项不再被锁定并且不可预测。 Heroku 会说:

Removing Gemfile.lock because it was generated on Windows. Bundler will do a full resolve so native gems are handled properly. This may result in unexpected gem versions being used in your app. In rare occasions Bundler may not be able to resolve your dependencies at all. https://devcenter.heroku.com/articles/bundler-windows-gemfile

您可以在 Capistrano 中执行类似的操作,使用一些自定义代码在 Bundler 任务运行之前删除 Gemfile.lock(或者只是从源代码管理中完全删除 Gemfile.lock)。您还必须更改 Bundler 参数以删除 --deployment 标志,否则当它看到缺少 Gemfile.lock 时它将失败。

或者您可以将开发环境切换到 Mac 或 Linux,例如通过使用 Linux VM 进行开发。