bundle clean 如何适应 CircleCI 缓存?
How does bundle clean fit into CircleCI cache?
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
before 缓存就位(恢复缓存之前的完整 gem 安装时间,这抵消了时间-节省缓存的好处)然后 运行 bundle clean
- 在已安装的 gems
上恢复缓存
- 不要做 任何事情(在
restore_cache
和 save_cache
步骤之间)
- 保存新缓存
我对这个过程的理解是否正确?
在我看来,restore_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
需要修改为
- run: bundle install && bundle clean
我很确定你是对的,这是 CircleCI 文档中的错字。我已经打开了一个 PR 来修复:https://github.com/circleci/circleci-docs/pull/2663
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
before 缓存就位(恢复缓存之前的完整 gem 安装时间,这抵消了时间-节省缓存的好处)然后 运行bundle clean
- 在已安装的 gems 上恢复缓存
- 不要做 任何事情(在
restore_cache
和save_cache
步骤之间) - 保存新缓存
我对这个过程的理解是否正确?
在我看来,restore_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
需要修改为
- run: bundle install && bundle clean
我很确定你是对的,这是 CircleCI 文档中的错字。我已经打开了一个 PR 来修复:https://github.com/circleci/circleci-docs/pull/2663