Given a Ruby on Rails project using WebPacker project, which folders need caching on a CI service to ensure system specs perform optimally? My build pipeline is currently caching public/packs-test
and tmp/cache/webpacker
.
Testing locally I see this behaviour:
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
This is promising - compilation times are 2 minutes initially, then 5 seconds subsequently. However, on CI I consistently see 2 minute runtimes for asset compilation. Here's the full list of folders I'm caching / restoring between runs:
public/packs-test
tmp/cache/webpacker
tmp/yarn
node_modules
Note: setting YARN_CACHE_FOLDER
ENV variable to tmp/yarn
and using CircleCI.
Edit:
To cache using the following snippets are used in the CircleCI configuration.
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
The following steps are working pretty well for me:
- 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With