Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebPacker CI Caching Required Folders

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
like image 342
Kevin Sylvestre Avatar asked Jun 15 '18 22:06

Kevin Sylvestre


1 Answers

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
like image 146
swrobel Avatar answered Oct 12 '22 00:10

swrobel