Skip to content

add cache in CI/CD description #6089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/content/configuration/cache.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,43 @@ module.exports = {
```

W> Don't share the cache between calls with different options.

## Setup cache in CI/CD system

Filesystem cache allows to share cache between builds in CI. To setup cache:

- CI should have an option to share cache between builds.
- CI should run job in the same absolute path. This is important since webpack cache files store absolute paths.

### GitLab CI/CD

Common config could looks like

```yaml
variables:
# fallback to use "main" branch cache, requires GitLab Runner 13.4
CACHE_FALLBACK_KEY: main

# this is webpack build job
build-job:
cache:
key: '$CI_COMMIT_REF_SLUG' # branch/tag name
paths:
# cache directory
# make sure that you don't run "npm ci" in this job or change default cache directory
# otherwise "npm ci" will prune cache files
- node_modules/.cache/webpack/
```

### Github actions

```yaml
- uses: actions/cache@v3
with:
# cache directory
path: node_modules/.cache/webpack/
key: ${{ GITHUB_REF_NAME }}-webpack-build
# fallback to use "main" branch cache
restore-keys: |
main-webpack-build
```