Bundler 如何决定重新安装某些东西?

How Does Bundler Determine to Re-Install Something?

我正在使用 CI 工具(具体来说是 CircleCI)来缓存一些 Ruby gem,这样我就不必在每次构建时都重新安装它们.目前在第一个版本中我正在这样做:

gem install bundler
bundle install

其中安装了多个gem:

Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using public_suffix 3.0.2
Using addressable 2.5.2
Using bundler 1.16.1
Using mini_mime 1.0.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.2
Installing nokogiri 1.8.2 with native extensions

完成初始构建后,我将缓存捆绑器显示 gem 位置的目录:/opt/circleci/.rvm/gems/ruby-2.3.1/gems/ 及其内容。

下次 运行 我可以 cd /opt/circleci/.rvm/gems/ruby-2.3.1/gems/ 并显示缓存中已恢复的所有宝石。但是,如果我导航到我的 Gemfile 和 运行 bundle info nokogiri 或该文件夹中的任何其他 gem,它会显示错误:Could not find public_suffix-3.0.2 in any of the sources

如果我 运行 bundle installgem install gemnamehere gems 安装 again 这并不理想,因为目标是节省时间建造。我是否需要 运行 某种带有 bundle 的命令或 Ruby 让它知道这些 gem 已安装所以它不会再这样做?

如果这是一个愚蠢的问题,我深表歉意,我正在学习这个问题。

编辑:圈CI 根据要求配置:

  test:
    machine: true
    steps:  
      - run:
          # Installs PhantomJS
          name: Install phantomjs
          command: |
            if ! [ $(which phantomjs) ]; then                
              curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
            fi
      - checkout
      - restore_cache:
          keys:
            - v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
      - run:
          name: "Install Dependencies"
          command: |
            cd ~/project
            gem install bundler
            bundle install
      - save_cache:
          key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
          paths:
            - /opt/circleci/.rvm/gems/ruby-2.3.1/gems/
      - run:
          name: "Run  Snapshots"
          command: |
            cd ~/project
            yarn build
            cd ~/project/mocks/visual
            bundle exec ruby snapshots.rb

如果你尝试改变这部分会怎样?

- save_cache:
      key: v1-tc-gem-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
      paths:
        - vendor/bundle
  - persist_to_workspace:
      root: ~/project
      paths: vendor/bundle

解决方案是使用 bundle install --path vendor/cache 并缓存 vendor/cache 路径。