diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-04 00:06:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-04 00:06:59 +0300 |
commit | 037e06544afe9593e47f95b2b36f92480a54e34c (patch) | |
tree | c84613c0d45e4b83cde04389dd18921921308388 /doc/ci/caching | |
parent | e8e149fc945f6f78725f312254577fb03b7666ec (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/ci/caching')
-rw-r--r-- | doc/ci/caching/index.md | 156 |
1 files changed, 66 insertions, 90 deletions
diff --git a/doc/ci/caching/index.md b/doc/ci/caching/index.md index 09ecf565a83..d14c9563642 100644 --- a/doc/ci/caching/index.md +++ b/doc/ci/caching/index.md @@ -297,25 +297,20 @@ In this example, the job's cache policy is: ### Cache Node.js dependencies If your project uses [npm](https://www.npmjs.com/) to install Node.js -dependencies, the following example defines `cache` globally so that all jobs inherit it. +dependencies, the following example defines a default `cache` so that all jobs inherit it. By default, npm stores cache data in the home folder (`~/.npm`). However, you [can't cache things outside of the project directory](../yaml/index.md#cachepaths). Instead, tell npm to use `./.npm`, and cache it per-branch: ```yaml -# -# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Nodejs.gitlab-ci.yml -# -image: node:latest - -# Cache modules in between jobs -cache: - key: $CI_COMMIT_REF_SLUG - paths: - - .npm/ - -before_script: - - npm ci --cache .npm --prefer-offline +default: + image: node:latest + cache: # Cache modules in between jobs + key: $CI_COMMIT_REF_SLUG + paths: + - .npm/ + before_script: + - npm ci --cache .npm --prefer-offline test_async: script: @@ -328,13 +323,13 @@ You can use [`cache:key:files`](../yaml/index.md#cachekeyfiles) to compute the c key from a lock file like `package-lock.json` or `yarn.lock`, and reuse it in many jobs. ```yaml -# Cache modules using lock file -cache: - key: - files: - - package-lock.json - paths: - - .npm/ +default: + cache: # Cache modules using lock file + key: + files: + - package-lock.json + paths: + - .npm/ ``` If you're using [Yarn](https://yarnpkg.com/), you can use [`yarn-offline-mirror`](https://classic.yarnpkg.com/blog/2016/11/24/offline-mirror/) @@ -358,26 +353,21 @@ job: ### Cache PHP dependencies If your project uses [Composer](https://getcomposer.org/) to install -PHP dependencies, the following example defines `cache` globally so that +PHP dependencies, the following example defines a default `cache` so that all jobs inherit it. PHP libraries modules are installed in `vendor/` and are cached per-branch: ```yaml -# -# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/PHP.gitlab-ci.yml -# -image: php:7.2 - -# Cache libraries in between jobs -cache: - key: $CI_COMMIT_REF_SLUG - paths: - - vendor/ - -before_script: - # Install and run Composer - - curl --show-error --silent "https://getcomposer.org/installer" | php - - php composer.phar install +default: + image: php:7.2 + cache: # Cache libraries in between jobs + key: $CI_COMMIT_REF_SLUG + paths: + - vendor/ + before_script: + # Install and run Composer + - curl --show-error --silent "https://getcomposer.org/installer" | php + - php composer.phar install test: script: @@ -387,32 +377,24 @@ test: ### Cache Python dependencies If your project uses [pip](https://pip.pypa.io/en/stable/) to install -Python dependencies, the following example defines `cache` globally so that +Python dependencies, the following example defines a default `cache` so that all jobs inherit it. pip's cache is defined under `.cache/pip/` and is cached per-branch: ```yaml -# -# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml -# -image: python:latest +default: + image: python:latest + cache: # Pip's cache doesn't store the python packages + paths: # https://pip.pypa.io/en/stable/topics/caching/ + - .cache/pip + before_script: + - python -V # Print out python version for debugging + - pip install virtualenv + - virtualenv venv + - source venv/bin/activate -# Change pip's cache directory to be inside the project directory since we can -# only cache local items. -variables: +variables: # Change pip's cache directory to be inside the project directory since we can only cache local items. PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" -# Pip's cache doesn't store the python packages -# https://pip.pypa.io/en/stable/topics/caching/ -cache: - paths: - - .cache/pip - -before_script: - - python -V # Print out python version for debugging - - pip install virtualenv - - virtualenv venv - - source venv/bin/activate - test: script: - python setup.py test @@ -423,25 +405,20 @@ test: ### Cache Ruby dependencies If your project uses [Bundler](https://bundler.io) to install -gem dependencies, the following example defines `cache` globally so that all +gem dependencies, the following example defines a default `cache` so that all jobs inherit it. Gems are installed in `vendor/ruby/` and are cached per-branch: ```yaml -# -# https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Ruby.gitlab-ci.yml -# -image: ruby:2.6 - -# Cache gems in between builds -cache: - key: $CI_COMMIT_REF_SLUG - paths: - - vendor/ruby - -before_script: - - ruby -v # Print out ruby version for debugging - - bundle config set --local path 'vendor/ruby' # The location to install the specified gems to - - bundle install -j $(nproc) # Install dependencies into ./vendor/ruby +default: + image: ruby:2.6 + cache: # Cache gems in between builds + key: $CI_COMMIT_REF_SLUG + paths: + - vendor/ruby + before_script: + - ruby -v # Print out ruby version for debugging + - bundle config set --local path 'vendor/ruby' # The location to install the specified gems to + - bundle install -j $(nproc) # Install dependencies into ./vendor/ruby rspec: script: @@ -456,13 +433,14 @@ For example, a testing job might not need the same gems as a job that deploys to production: ```yaml -cache: - key: - files: - - Gemfile.lock - prefix: $CI_JOB_NAME - paths: - - vendor/ruby +default: + cache: + key: + files: + - Gemfile.lock + prefix: $CI_JOB_NAME + paths: + - vendor/ruby test_job: stage: test @@ -572,18 +550,19 @@ stages: - build - test -before_script: - - echo "Hello" +default: + cache: + key: build-cache + paths: + - vendor/ + before_script: + - echo "Hello" job A: stage: build script: - mkdir vendor/ - echo "build" > vendor/hello.txt - cache: - key: build-cache - paths: - - vendor/ after_script: - echo "World" @@ -591,10 +570,6 @@ job B: stage: test script: - cat vendor/hello.txt - cache: - key: build-cache - paths: - - vendor/ ``` If one machine has one runner installed, then all jobs for your project @@ -602,6 +577,7 @@ run on the same host: 1. Pipeline starts. 1. `job A` runs. +1. The cache is extracted (if found). 1. `before_script` is executed. 1. `script` is executed. 1. `after_script` is executed. |