gitlab-runner kubernetes 缓存被忽略

gitlab-runner kubernetes cache is ignored

我有一个带有 gitlab-运行ner 10.3.0 和 kubernetes 执行器的 kubernetes 集群。 运行ner 的 config.toml 文件中没有定义 cache_dir。请注意,这与 docker 执行程序不同,因此卷解决方案不适用。

.gitlab-ci.yml 中,我配置了一个使用缓存的作业:

build:
  cache:
    key: "${PROJECT_NAME}"
    paths:
      - "node_modules/"
  script:
    - ls node_modules/ || echo "cache not there"
    - npm i
    - npm build
    - ...

当我 运行 这样做时,我看到正在拉取和创建缓存:

Cloning repository for some-branch with git depth set to 1...
Cloning into '/group/projectname'...
Checking out d03baa31 as some-branch...
Skipping Git submodules setup
Checking cache for projectname...
Successfully extracted cache
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
//
// ...work being done here... 
//
Creating cache projectname...
node_modules/: found 24278 matching files
Created cache
Job succeeded

但是,当我将另一个提交推送到该分支时,ls node_modules/ 仍然找不到缓存。

我搜索了文档,没有找到任何关于如何激活缓存的信息。 gitlab-运行ner-pod 也没有任何所谓的缓存文件,according to the documentation,配置中的 cache_dir 未被 kubernetes 执行程序使用。

但根据 this feature page,kubernetes 执行器 支持缓存。

那么怎么做呢?

由于 Kubernetes 的分布式特性,您将需要配置一个中央缓存位置(通常采用 S3 兼容对象存储的形式,如 AWS S3 or Minio). The reason behind this is explained in the Gitlab runner documentation(强调我的):

To speed up your builds, GitLab Runner provides a cache mechanism where selected directories and/or files are saved and shared between subsequent builds.

This is working fine when builds are run on the same host, but when you start using the Runners autoscale feature, most of your builds will be running on a new (or almost new) host, which will execute each build in a new Docker container. In that case, you will not be able to take advantage of the cache feature.

To overcome this issue, together with the autoscale feature, the distributed Runners cache feature was introduced.

It uses any S3-compatible server to share the cache between used Docker hosts. When restoring and archiving the cache, GitLab Runner will query the S3 server and will download or upload the archive.

为此,您可以在运行器配置中使用[runners.cache] section

[runners.cache]
  Type = "s3"
  ServerAddress = "s3.amazonaws.com"
  AccessKey = "AMAZON_S3_ACCESS_KEY"
  SecretKey = "AMAZON_S3_SECRET_KEY"
  BucketName = "runners"
  BucketLocation = "eu-west-1"
  Insecure = false
  Path = "path/to/prefix"
  Shared = false

OP 编辑​​: Installation instructions for Minio for gitlab-ci