带有docker的Gitlab runner不会在本地缓存rails gem

Posted

技术标签:

【中文标题】带有docker的Gitlab runner不会在本地缓存rails gem【英文标题】:Gitlab runner with docker doesn't cache rails gems locally 【发布时间】:2020-12-12 12:40:39 【问题描述】:

我正在尝试在本地缓存 ruby​​ gem,以便我的 docker 运行得更快。

我发现了这个 8 个月大的帖子 Configure cache on GitLab runner 谈论本地缓存是不可能的。这仍然是真的还是我做错了?

我的 gitlab-ci.yml:

stages:
  - test
  
test:unit:
  stage: test
  image: ruby:2.5.8
  cache:
    key: gems
    untracked: true
    paths:
      - vendor/ruby
  services:
    - mysql:5.7
  variables:
    MYSQL_DB: inter_space_test
    MYSQL_USER: root
    MYSQL_ROOT_PASSWORD: root
    MYSQL_PASSWORD: ''
    MYSQL_HOST: mysql
    RAILS_ENV: test
  script:
    - bundle config set path 'vendor/ruby'
    - cp config/database.yml_ci config/database.yml
    - apt-get update && apt-get install -y nodejs
    - gem install bundler --no-document
    - bundle install -j $(nproc) --path vendor/ruby
    - ls -lah vendor/ruby/

    - bundle exec rake db:setup
    - bundle exec rake db:migrate
    - bundle exec rails test -d

我的配置 toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "main"
  url = "https://gitlab.com/"
  token = "1r1op5jJARn8akjaG-hs"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "ruby:2.5.8"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    cache_dir = "/vendor/ruby"
    volumes = ["/cache", "/vendor/ruby", "/var/cache/apt"]
    shm_size = 300000

【问题讨论】:

【参考方案1】:

我修好了。

这两行代码做到了:

- export BUNDLE_PATH="/vendor/ruby"
- bundle config set path '/vender/ruby'

【讨论】:

以上是关于带有docker的Gitlab runner不会在本地缓存rails gem的主要内容,如果未能解决你的问题,请参考以下文章

带有 Docker 和 shell 错误的 Gitlab Runner — 权限被拒绝

GitLab-CI Multi Runner php 作曲家缓存

docker中gitlab-runner配置

Gitlab-Runner:从主服务器克隆的权限被拒绝

gitlab-runner config for docker runner

使用多个 docker 守护进程运行 gitlab-runner