Hi all, I am currently trying to set up a caching mechanism to improve the pipelines of my NodeJs application.
For example, this is how I am currently using it in Github actions for my open source repositories.
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
What is the recommended way to do this using buildkite? I could not find any information in the documentation. Thanks!
We’ve built a plugin internally just for this purpose (save/restore yarn & npm cache between builds): https://github.com/peakon/s3-cache-buildkite-plugin
1 Like
jhealy
November 6, 2020, 1:13am
3
We don’t have an official caching method that’s equivalent to GitHub Actions approach, but there’s a number of plugins that work in a similar way.
@vitalii ’s plugin is a good option. Another I’ve seen folks get positive results with https://github.com/gencer/cache-buildkite-plugin
Searching for “cache” on https://buildkite.com/plugins might turn up some other options.
Sidenote: @vitalii - it’d be great to have peakon’s plugin listed in the plugin directory! If you’re up for it, there’s some instructions here: https://buildkite.com/docs/plugins/directory
2 Likes
I’m using the gencer/cache
plugin.
My config looks like this.
cache_plugin_config: &cache_plugin_config
backend: tarball
key: "deps-{{ checksum 'yarn.lock' }}"
tarball:
path: '/tmp/buildkite-cache'
max: 7 # Optional. Removes tarballs older than 7 days.
paths:
- ./node_modules/
- ./packages/*/node_modules
steps:
- label: ':eslint:'
commands:
- './ci yarn install --frozen-lockfile'
- './ci yarn lint:web'
plugins:
- gencer/cache#v2.3.3: *cache_plugin_config
- label: ':jest:'
commands:
- './ci yarn install --frozen-lockfile'
- './ci yarn test:web --ci'
plugins:
- gencer/cache#v2.3.3: *cache_plugin_config
You can find more plugins here: https://buildkite.com/plugins
1 Like