Skip to content

Commit 15e69de

Browse files
authored
Merge branch 'master' into db_update-crowdin-tags-4
2 parents 4db2e96 + 30f1793 commit 15e69de

17 files changed

+293
-487
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ jekyll/_config_override.yml
4141
markdownlint-results.json
4242
.tool-versions
4343

44+
# former submodule
45+
src-shared/
46+
4447
# output for docs-platform
4548
json/

jekyll/_cci2/caching.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Caching is one of the most effective ways to make jobs faster on CircleCI. By re
1515
* TOC
1616
{:toc}
1717

18-
![caching data flow]({{ site.baseurl }}/assets/img/docs/caching-dependencies-overview.png)
18+
![caching data flow]({{site.baseurl}}/assets/img/docs/caching-dependencies-overview.png)
1919

2020
Caching is particularly useful with **package dependency managers** such as Yarn, Bundler, or Pip. With dependencies restored from a cache, commands like `yarn install` need only download new or updated dependencies, rather than downloading everything on each build.
2121

@@ -40,7 +40,7 @@ The Docker images used for CircleCI jobs are automatically cached on the server
4040
**Warning:** Although several examples are included below, caching strategies need to be carefully planned for each individual project. Copying and pasting the code examples will not always be appropriate for your needs.
4141
{: class="alert alert-warning"}
4242

43-
For information about caching and reuse of unchanged layers of a Docker image, see the [Docker Layer Caching]({{ site.baseurl }}/2.0/docker-layer-caching/) document.
43+
For information about caching and reuse of unchanged layers of a Docker image, see the [Docker Layer Caching]({{site.baseurl}}/2.0/docker-layer-caching/) document.
4444

4545
## How caching works
4646
{: #how-caching-works }
@@ -55,7 +55,7 @@ Caching is about achieving a balance between reliability and getting maximum per
5555
### Saving cache
5656
{: #saving-cache }
5757

58-
CircleCI manual dependency caching requires you to be explicit about what you cache and how you cache it. See the [save cache section]({{ site.baseurl }}/2.0/configuration-reference/#save_cache) of the Configuring CircleCI document for additional examples.
58+
CircleCI manual dependency caching requires you to be explicit about what you cache and how you cache it. See the [save cache section]({{site.baseurl}}/2.0/configuration-reference/#save_cache) of the Configuring CircleCI document for additional examples.
5959

6060
To save a cache of a file or directory, add the `save_cache` step to a job in your `.circleci/config.yml` file:
6161

@@ -72,7 +72,7 @@ CircleCI imposes a 900-character limit on the length of a `key`. Be sure to keep
7272
The path for directories is relative to the `working_directory` of your job. You can specify an absolute path if you choose.
7373

7474
**Note:**
75-
Unlike the special step [`persist_to_workspace`]({{ site.baseurl }}/2.0/configuration-reference/#persist_to_workspace), neither `save_cache` nor `restore_cache` support globbing for the `paths` key.
75+
Unlike the special step [`persist_to_workspace`]({{site.baseurl}}/2.0/configuration-reference/#persist_to_workspace), neither `save_cache` nor `restore_cache` support globbing for the `paths` key.
7676

7777
### Restoring cache
7878
{: #restoring-cache }
@@ -100,7 +100,57 @@ Each line in the `keys:` list manages _one cache_ (each line does **not** corres
100100

101101
The first key concatenates the checksum of `package-lock.json` file into the string `v1-npm-deps-`. If this file changed in your commit, CircleCI would see a new cache key.
102102

103-
The next key does not have a dynamic component to it. It is simply a static string: `v1-npm-deps-`. If you would like to invalidate your cache manually, you can bump `v1` to `v2` in your `config.yml` file. In this case, you would now have a new cache key `v2-npm-deps`, which triggers the storing of a new cache.
103+
The next key does not have a dynamic component to it. It is simply a static string: `v1-npm-deps-`. If you would like to invalidate your cache manually, you can bump `v1` to `v2` in your `.circleci/config.yml` file. In this case, you would now have a new cache key `v2-npm-deps`, which triggers the storing of a new cache.
104+
105+
## Basic example of Yarn package manager caching
106+
{: #basic-example-of-yarn-package-manager-caching }
107+
108+
[Yarn](https://yarnpkg.com/) is an open-source package manager for JavaScript. The packages it installs can be cached, which can speed up builds, but, more importantly, can reduce errors related to network connectivity.
109+
110+
Please note, the release of Yarn 2.x comes with a the ability to do [Zero Installs](https://yarnpkg.com/features/zero-installs). If you are using Zero Installs, you should not need to do any special caching within CircleCI.
111+
112+
If you are using Yarn 2.x _without_ Zero Installs, you can do something like the following:
113+
114+
{% raw %}
115+
```yaml
116+
#...
117+
- restore_cache:
118+
name: Restore Yarn Package Cache
119+
keys:
120+
- yarn-packages-{{ checksum "yarn.lock" }}
121+
- run:
122+
name: Install Dependencies
123+
command: yarn install --immutable
124+
- save_cache:
125+
name: Save Yarn Package Cache
126+
key: yarn-packages-{{ checksum "yarn.lock" }}
127+
paths:
128+
- .yarn/cache
129+
- .yarn/unplugged
130+
#...
131+
```
132+
{% endraw %}
133+
134+
If you are using Yarn 1.x, you can do something like the following:
135+
136+
{% raw %}
137+
```yaml
138+
#...
139+
- restore_cache:
140+
name: Restore Yarn Package Cache
141+
keys:
142+
- yarn-packages-{{ checksum "yarn.lock" }}
143+
- run:
144+
name: Install Dependencies
145+
command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
146+
- save_cache:
147+
name: Save Yarn Package Cache
148+
key: yarn-packages-{{ checksum "yarn.lock" }}
149+
paths:
150+
- ~/.cache/yarn
151+
#...
152+
```
153+
{% endraw %}
104154

105155
## Caching and open source
106156
{: #caching-and-open-source }
@@ -116,9 +166,9 @@ If your project is open source/available to be forked and receive PRs from contr
116166

117167
If a job fetches data at any point, it is likely that you can make use of caching. The most important dependencies to cache during a job are the libraries on which your project depends. For example, cache the libraries that are installed with `pip` in Python or `npm` for Node.js. The various language dependency managers, for example `npm` or `pip`, each have their own paths where dependencies are installed. See our Language guides and [demo projects]({{site.baseurl}}/2.0/demo-apps/) for the specifics for your stack.
118168

119-
Tools that are not explicitly required for your project are best stored on the Docker image. The Docker image(s) prebuilt by CircleCI have tools preinstalled that are generic for building projects using the relevant language. For example, the `circleci/ruby:2.4.1` image includes useful tools like git, openssh-client, and gzip.
169+
Tools that are not explicitly required for your project are best stored on the Docker image. The Docker image(s) prebuilt by CircleCI have tools preinstalled that are generic for building projects using the relevant language. For example, the `cimg/ruby:3.1.2` image includes useful tools like git, openssh-client, and gzip.
120170

121-
![Caching Dependencies]( {{ site.baseurl }}/assets/img/docs/cache_deps.png)
171+
![Caching Dependencies]({{site.baseurl}}/assets/img/docs/cache_deps.png)
122172

123173
We recommend that you verify that the dependencies installation step succeeds before adding caching steps. Caching a failed dependency step will require you to change the cache key in order to avoid failed builds due to a bad cache.
124174

@@ -269,7 +319,7 @@ There are many different approaches to utilizing caching in monorepos. The follo
269319

270320
Caches cannot be cleared. If you need to generate a new set of caches you can update the cache key, similar to the previous example. You might wish to do this if you have updated language or build management tool versions.
271321

272-
Updating the cache key on save and restore steps in your '.circleci/config.yml' file will then generate new sets of caches from that point onwards. Please note that older commits using the previous keys may still generate and save cache, so it is recommended that you rebase after the 'config.yml' changes when possible.
322+
Updating the cache key on save and restore steps in your `.circleci/config.yml` file will then generate new sets of caches from that point onwards. Please note that older commits using the previous keys may still generate and save cache, so it is recommended that you rebase after the 'config.yml' changes when possible.
273323

274324
If you create a new cache by incrementing the cache version, the "older" cache is still stored. It is important to be aware that you are creating an additional cache. This method will increase your storage usage. As a general best practice, you should review what is currently being cached and reduce your storage usage as much as possible.
275325

jekyll/_cci2/getting-started-guide-experimental.md

Lines changed: 0 additions & 197 deletions
This file was deleted.

0 commit comments

Comments
 (0)