Gitlab.com CI caching Rubygems

Hi!

I’m trying to cache my Ruby gems installation but the cache does not seem to stick.

Build output start and end look okay and have no warnings:

...
Checking cache for test/master...
Successfully extracted cache
...
...
Creating cache test/master...
Created cache

ls shows that dependencies are nicely on disk (about 70MB in size)

Here is a part of my .gitlab-ci.yml

test:
  stage: test
  image: "ruby:2.4"
  services:
    - postgres:latest
  variables:
    RAILS_ENV: test
    POSTGRES_DB: app_test
    DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
  cache:
    paths:
      - vendor/ruby/
  before_script:
    - ruby -v
    - bundle install -j $(nproc) --path vendor
    - ls -lah vendor
  script:
    - bundle exec rubocop .
    - bundle exec rails db:migrate
    - bundle exec rails db:seed
    - bundle exec rails test

This happens on DigitalOcean hosted shared runner. Is there to turn on more cache debugging output?

1 Like

Is it because the cache is not shared between runners - https://gitlab.com/gitlab-com/infrastructure/issues/919?

Hi @mihkel,

I also had this same problem running shared runners on GitlabCI, but now, it seems Gitlab is caching CI shared runners. Here’s the cache excerpt from my .gitlab-ci.yml config file:

.cache_bundler: &cache_bundler
  cache:
    untracked: true
    key: "$CI_BUILD_REF_NAME"
    paths:
      - cache/bundler/

.setup_test_env: &setup_test_env
  before_script:
    - bundle install --path=cache/bundler --without production --jobs $(nproc)  "${FLAGS[@]}"

main_app_spec:
  <<: *cache_bundler
  <<: *setup_test_env
  script:
    - bundle exec rspec