捆绑包清理如何适应CircleCI缓存?

时间:2018-08-30 13:14:46

标签: circleci circleci-2.0

CircleCI文档包含一些有关在涉及缓存时为何应运行bundle clean的信息,但是我很难理解如何运行。我对Bundler (Ruby)部分中的代码块感到困惑: https://circleci.com/docs/2.0/caching/#bundler-ruby

有问题的代码块是:

- run: bundle install & bundle clean
- restore_cache:
    keys:
      # when lock file changes, use increasingly general patterns to restore cache
      - v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
      - v1-gem-cache-{{ arch }}-{{ .Branch }}-
      - v1-gem-cache-{{ arch }}-
- save_cache:
    paths:
      - ~/.bundle
    key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}

我将这个过程读为:

  • 运行bundle install 之前放置适当的缓存(还原缓存之前需要完整的gem安装时间,这抵消了缓存的省时优势),然后运行{{1 }}
  • 通过已安装的gem恢复缓存
  • 不要做任何事情(在bundle cleanrestore_cache步骤之间)
  • 保存新的缓存

我能正确理解该过程吗?

在我看来,save_cacherestore_cache步骤将无效,因为整个save_cache时间已经被用完了。

如果我了解事情,这会是一个更有效的过程吗?

bundle install

如果我不能正确理解这一点,谁能帮助澄清建议的代码块如何工作?

更新: 看起来也像

- restore_cache:
    keys:
      # when lock file changes, use increasingly general patterns to restore cache
      - v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
      - v1-gem-cache-{{ arch }}-{{ .Branch }}-
      - v1-gem-cache-{{ arch }}-
- run: bundle install & bundle clean
- save_cache:
    paths:
      - ~/.bundle
    key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}

需要修改为

- run: bundle install & bundle clean

1 个答案:

答案 0 :(得分:2)

我很确定您是正确的,这是CircleCI文档中的错字。我已经打开了一个PR,以解决:https://github.com/circleci/circleci-docs/pull/2663