给出一个使用WebPacker项目的Ruby on Rails项目,哪些文件夹需要在CI服务上进行缓存以确保系统规格达到最佳性能?我的构建管道当前正在缓存public/packs-test
和tmp/cache/webpacker
。
在本地测试,我看到此行为:
time rake assets:precompile RAILS_ENV=test # 2.0m
time rake assets:precompile RAILS_ENV=test # 5.0s
rm -rf ./public/packs-test ./tmp/cache/webpacker
time rake assets:precompile RAILS_ENV=test # 2.0m
这很有希望-编译时间最初是2分钟,然后是5秒。但是,在CI上,我始终看到2分钟的运行时间来进行资产编译。这是我在运行之间缓存/还原的文件夹的完整列表:
public/packs-test
tmp/cache/webpacker
tmp/yarn
node_modules
注意:将YARN_CACHE_FOLDER
ENV变量设置为tmp/yarn
并使用CircleCI。
编辑:
在CircleCI配置中使用以下片段来缓存。
type: cache-restore
keys:
- assets-{{ .Branch }}-{{ .Revision }}
- assets-{{ .Branch }}
- assets
type: cache-save
key: assets-{{ .Branch }}-{{ .Revision }}
paths:
- public/packs-test
- tmp/cache/webpacker
- tmp/yarn
- node_modules
以下步骤对我来说效果很好:
- restore_cache:
name: Restore webpacker cache
keys:
- v1-webpacker-{{ .Branch }}-
- v1-webpacker-
- restore_cache:
name: Restore compiled packs
key: v1-packs-{{ checksum "tmp/cache/webpacker/last-compilation-digest-test" }}
- save_cache:
name: Store webpacker cache
key: v1-webpacker-{{ .Branch }}-{{ epoch }}
paths:
- tmp/cache/webpacker
- save_cache:
name: Store compiled packs
key: v1-packs-{{ checksum "tmp/cache/webpacker/last-compilation-digest-test" }}
paths:
- public/packs-test