Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure cache on GitLab runner

I don't manage to configure a cache directory, but somehow it does not work. I'm not even sure it takes the config.toml file.

my config.toml:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  cache_dir = /tmp/gitlab-runner-cache

... both on /etc/gitlab-runner/config.toml and in ~/.gitlab-runner/config.toml

my .gitlab-ci.yml:

image: docker:latest
services:
  - docker:dind

cache:
  key: "myCache"
  paths:
    - ${CI_PROJECT_DIR]/.m2/

variables:
  DOCKER_DRIVER: overlay
  MAVEN_OPTS: -Dmaven.repo.local=${CI_PROJECT_DIR}/.m2

stages:
  - build
  - acceptance

maven-build:
  image: maven:3.3-jdk-8
  stage: build
  script: "mvn clean package"
  artifacts:
    paths:
      - target/*.jar

maven-acceptance:
  dependencies:
    - maven-build
  image: maven:3.3-jdk-8
  stage: acceptance
  script: "mvn verify"

When I try: gitlab-runner exec shell maven-build

I get the error:

ERROR: Could not create cache adapter               error=cache factory not found: factory for cache adapter "" was not registered

The build is successful, but the .m2 repository is not cached...

Therefore, I have 2 questions:

  1. How to know if gitlab-runner actually takes my config.yml?
  2. What is a correct config for caching?

Thanks in advance!

like image 354
laurent exsteens Avatar asked Feb 21 '19 17:02

laurent exsteens


People also ask

Where is GitLab runner cache?

By default, they are stored locally in the machine where the Runner is installed and depends on the type of the executor. Locally, stored under the gitlab-runner user's home directory: /home/gitlab-runner/cache/<user>/<project>/<cache-key>/cache.

What is GitLab runner cache?

It's a set of files that a job can download before running and upload after execution. By default, the cache is stored in the same place where GitLab Runner is installed. If the distributed cache is configured, S3 works as storage.

Where is GitLab runner config file?

You can find the config. toml file in: /etc/gitlab-runner/ on *nix systems when GitLab Runner is executed as root (this is also the path for service configuration)


1 Answers

I ran into the same issue just now. I am not sure which version of Gitlab you use, but version 12 supports either an S3-compatible storage or GCS as the cache provider (see thes docs), but no local cache folder like cache_dir = /tmp/gitlab-runner-cache.

The issue I had was, that I forgot to add Type = "s3" to the [runners.cache]section of the Runner configuration:

  [runners.cache]
    Type = "s3"
    Shared = true
    [runners.cache.s3]
      ServerAddress = ...
like image 156
Kevin Woblick Avatar answered Sep 19 '22 14:09

Kevin Woblick