【问题标题】:Can I use an old Gemlock file contents as new Gem file?我可以将旧的 Gemlock 文件内容用作新的 Gem 文件吗?
【发布时间】:2018-11-20 06:54:03
【问题描述】:

我有一个运行 Ruby 1.9.3、Rails 4.2.4 和 MongoDB 3.0 的旧 ROR 应用程序。我需要将其移至 Ruby 2.2.2、Rails 4.5 和 MongoDB 3.2。

我接手了这个项目,因此代码目前正在托管服务上运行。我已经下载了源代码。但是,我想在我的机器上使用需要更新的项目中的 Gem 文件在本地构建一个简单的脚手架应用程序。首先,项目的 gem 文件没有列出 gem 的特定版本,所以如果我尝试使用 bundler,它会尝试获取所有较新版本的 gem。该项目的 Gemlock 文件确实包含正在使用的版本号。

我的问题是我可以使用 gemlock 文件的内容(复制 + 粘贴)到我的本地 Gem 文件中,然后运行 ​​bundler。这会正常工作,这意味着它会获得正确的 gem(生产服务器上使用的版本)吗?我了解其中一些 gem 版本可能已被删除。我想我只是将那些从 gem 文件中注释掉然后运行 ​​bundle install 直到它工作。

    GIT
  remote: https://github.com/stripe/stripe-ruby
  revision: df2e36287d88726c6a03ec6c1fdc19b5d6e2b274
  specs:
    stripe (1.27.2)
      json (~> 1.8.1)
      rest-client (~> 1.4)

PATH
  remote: ./vendor/plugins/mongoid-encrypted-fields-1.2.2
  specs:
    mongoid-encrypted-fields (1.2.2)
      mongoid

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.4)
      actionview (= 4.2.4)
      activesupport (= 4.2.4)
      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.4)
      activesupport (= 4.2.4)
      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.4)
      activesupport (= 4.2.4)
      globalid (>= 0.3.0)
    activemodel (4.2.4)
      activesupport (= 4.2.4)
      builder (~> 3.1)
    activerecord (4.2.4)
      activemodel (= 4.2.4)
      activesupport (= 4.2.4)
      arel (~> 6.0)
    activesupport (4.2.4)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    addressable (2.3.8)
    aescrypt (1.0.0)
    arel (6.0.3)
    aws-sdk (1.66.0)
      aws-sdk-v1 (= 1.66.0)
    aws-sdk-v1 (1.66.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
    axiom-types (0.1.1)
      descendants_tracker (~> 0.0.4)
      ice_nine (~> 0.11.0)
      thread_safe (~> 0.3, >= 0.3.1)
    bcrypt (3.1.10)
    bson (3.2.4)
    bson_ext (1.5.1)
    builder (3.2.2)
    chronic (0.10.2)
    coercible (1.0.0)
      descendants_tracker (~> 0.0.1)
    columnize (0.9.0)
    commander (4.3.5)
      highline (~> 1.7.2)
    daemons (1.2.3)
    debugger (1.6.8)
      columnize (>= 0.3.1)
      debugger-linecache (~> 1.2.0)
      debugger-ruby_core_source (~> 1.3.5)
    debugger-linecache (1.2.0)
    debugger-ruby_core_source (1.3.8)
    descendants_tracker (0.0.4)
      thread_safe (~> 0.3, >= 0.3.1)
    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.24)
      unf (>= 0.0.5, < 1.0.0)
    equalizer (0.0.11)
    erubis (2.7.0)
    ethon (0.8.0)
      ffi (>= 1.3.0)
    eventmachine (1.0.8)
    excon (0.45.4)
    execjs (2.6.0)
    factory_girl (4.5.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.5.0)
      factory_girl (~> 4.5.0)
      railties (>= 3.0.0)
    faraday (0.9.1)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.10)
    gcm (0.1.0)
      httparty
      json
    geocoder (1.2.11)
    gibberish (1.4.0)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    grape (0.13.0)
      activesupport
      builder
      hashie (>= 2.1.0)
      multi_json (>= 1.3.2)
      multi_xml (>= 0.5.2)
      rack (>= 1.3.0)
      rack-accept
      rack-mount
      virtus (>= 1.0.0)
    hashids (1.0.2)
    hashie (3.4.2)
    highline (1.7.7)
    houston (2.2.3)
      commander (~> 4.1)
      json
    http-cookie (1.0.2)
      domain_name (~> 0.5)
    httparty (0.13.7)
      json (~> 1.8)
      multi_xml (>= 0.5.2)
    i18n (0.7.0)
    ice_nine (0.11.1)
    iron_core (1.0.9)
      rest (>= 3.0.4)
    iron_worker_ng (1.6.6)
      bundler
      iron_core (>= 1.0.6)
      rubyzip (>= 1.0.0)
    jquery-rails (4.0.5)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (1.8.3)
    jwt (1.5.1)
    kaminari (0.16.3)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    libv8 (3.16.14.11)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    mandrill-api (1.0.53)
      excon (>= 0.16.0, < 1.0)
      json (>= 1.7.7, < 2.0)
    mime-types (2.6.2)
    mimemagic (0.3.1)
    mini_portile (0.6.2)
    minitest (5.8.1)
    mongo (2.1.1)
      bson (~> 3.0)
    mongoid (5.0.0)
      activemodel (~> 4.0)
      mongo (~> 2.1)
      origin (~> 2.1)
      tzinfo (>= 0.3.37)
    multi_json (1.11.2)
    multi_xml (0.5.5)
    multipart-post (2.0.0)
    net-http-persistent (2.9.4)
    netrc (0.10.3)
    newrelic-grape (2.0.0)
      grape
      newrelic_rpm
    newrelic_rpm (3.13.2.302)
    nexmo (3.0.0)
    nokogiri (1.6.6.2)
      mini_portile (~> 0.6.0)
    oauth2 (1.0.0)
      faraday (>= 0.8, < 0.10)
      jwt (~> 1.0)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (~> 1.2)
    opentok (2.3.3)
      activesupport (>= 2.0)
      addressable (~> 2.3)
      httparty (~> 0.13.1)
    origin (2.1.1)
    orm_adapter (0.5.0)
    rack (1.6.4)
    rack-accept (0.4.5)
      rack (>= 0.4)
    rack-cors (0.4.0)
    rack-mount (0.8.3)
      rack (>= 1.0.0)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.4)
      actionmailer (= 4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      activemodel (= 4.2.4)
      activerecord (= 4.2.4)
      activesupport (= 4.2.4)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.4)
      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)
    rails_12factor (0.0.3)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.4)
    rails_stdout_logging (0.0.4)
    railties (4.2.4)
      actionpack (= 4.2.4)
      activesupport (= 4.2.4)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.4.2)
    ref (2.0.0)
    responders (2.1.0)
      railties (>= 4.2.0, < 5)
    rest (3.0.6)
      net-http-persistent (>= 2.9.1)
      netrc
    rest-client (1.8.0)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 3.0)
      netrc (~> 0.7)
    rmagick (2.15.4)
    rubyzip (1.1.7)
    sendgrid-ruby (1.1.6)
      faraday (~> 0.9)
      mimemagic
      smtpapi (~> 0.1)
    smtpapi (0.1.0)
    sprockets (3.3.5)
      rack (> 1, < 3)
    sprockets-rails (2.3.3)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    therubyracer (0.12.2)
      libv8 (~> 3.16.14.0)
      ref
    thin (1.6.4)
      daemons (~> 1.0, >= 1.0.9)
      eventmachine (~> 1.0, >= 1.0.4)
      rack (~> 1.0)
    thor (0.19.1)
    thread_safe (0.3.5)
    timecop (0.8.0)
    twilio-ruby (4.4.0)
      builder (>= 2.1.2)
      jwt (~> 1.0)
      multi_json (>= 1.3.0)
    typhoeus (0.8.0)
      ethon (>= 0.8.0)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.1)
    virtus (1.0.5)
      axiom-types (~> 0.1)
      coercible (~> 1.0)
      descendants_tracker (~> 0.0, >= 0.0.3)
      equalizer (~> 0.0, >= 0.0.9)
    warden (1.2.3)
      rack (>= 1.0)

PLATFORMS
  ruby

DEPENDENCIES
  aescrypt
  aws-sdk (~> 1)
  bson_ext
  chronic
  debugger
  devise
  execjs
  factory_girl_rails
  gcm
  geocoder
  gibberish (~> 1.4.0)
  grape
  hashids
  houston
  iron_worker_ng
  jquery-rails
  kaminari
  mail
  mandrill-api
  mongo
  mongoid (~> 5.0.0)
  mongoid-encrypted-fields!
  newrelic-grape
  newrelic_rpm
  nexmo
  oauth2
  opentok (~> 2.2)
  rack-cors
  rails (~> 4.2.4)
  rails_12factor
  rmagick
  sendgrid-ruby
  stripe!
  therubyracer
  thin
  timecop
  twilio-ruby
  typhoeus
  uglifier

【问题讨论】:

    标签: ruby-on-rails rubygems bundler


    【解决方案1】:

    您无需担心 Gemfile.lock 文件,首先您在 Gemfile 中更改需要更新的 gem 版本,这将在 bundle 更新后更新 Gemfile.lock。

    例如更改 Gemfile 以更新 Rails 版本

    gem 'rails', '4.2.4'
    

    gem 'rails', '4.5.0'
    

    只需 bundle update rails 这将更新 rails gem 及其依赖项。

    但是你只想更新没有依赖关系的rails(至少不推荐像Rails这样的gem)

    e.g. bundle update --source rails  
    

    参考bundle update命令

    PS:您可以在 Gemfile 中添加 ruby​​ 版本(=2.2.2),如果您使用的是 rvm,它将自动切换 ruby​​ 版本。

    【讨论】:

    • 我想我可能把你弄糊涂了。我还不想更新我的应用程序。我首先要做的是创建一个新应用程序,它与生产中使用的当前 gem 相同(包括正在使用的确切版本号)。我想做一个测试并更新这个新应用程序,看看当我将新应用程序切换到 2.2.2 和 rails 4.5 时需要更新哪些 gem。然后我计划查找需要更新的 GEMS 的最低版本是什么。去查看那些 Gem,看看现在需要的 (2.2.2/4.5) 与当前生产应用现在使用的之间发生了哪些变化。
    • 我们的测试收敛率为 0%,所以我想知道发生了什么变化。去修复任何代码。然后在生产级代码上执行实际的包更新命令,应用程序应该有更少的错误。
    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多