CircleCI宝石缓存 [英] CircleCI gems caching

查看:115
本文介绍了CircleCI宝石缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以缓存宝石,这样 bundle install 不会为每个构建安装一堆宝石?这需要5分钟,每个构建,这是太多。



我已经将此添加到 circle.yml config:

 依赖项:
cache_directories:
- /home/ubuntu/.rvm/gems /ruby-2.1.2/gems/

这是由 bundle show gem_name 其中放置了所有系统宝石。



在添加系统写入这样的日志之后:

 恢复缓存v4 / company / repo_name / dependency / circle-ci / 42 / mGWhlYQIxyOy0GZtt4QmCw __。tar.gz 
恢复home / ubuntu / repo_name /主页/ ubuntu / .m2,主页/ ubuntu / .go_workspace,主页/ ubuntu / .gradle,主页/ ubuntu / .rvm / gems / ruby​​-2.1.2 / gems

因此,就我所知,它将系统宝石和宝石恢复到供应商/ bundle ,但是,我仍然看到了这一点(这需要很长时间):

 安装rake 10.4。 2 
安装i18n 0.7.0
安装json 1.8.2
安装minitest 5.5.1
...

而不是

 使用rake 10.4.2 
using i18n 0.7.0
使用json 1.8.2
使用minitest 5.5.1
...

所以,它似乎应该起作用,但事实并非如此。什么可能是错误的?解决方案很简单:CircleCI在默认情况下运行一些命令,并在默认情况下缓存gems在 vendor / bundle ,所以不需要添加任何东西到 cache_directories



这些默认命令是 bundle check --path = vendor / bundle || bundle install --path = vendor / bundle --jobs = 4 --retry = 3 ,它检查缓存目录中是否存在gem,如果它们不存在,就安装它们。 b
$ b

在我的例子中,我有多个应用程序(主应用程序,通用UI,API客户端和API模拟)组成的项目分成4个不同的回购站。他们大多需要 bundle install 命令。



我唯一要做的就是将所有 bundle install 命令(总是安装gems)替换为 bundle check --path = vendor / bundle || bundle install --path = vendor / bundle --jobs = 4 --retry = 3 。在这种情况下,只有在第一次运行测试时才安装所有宝石,并且以下所有构建都使用先前缓存的宝石。


Is it possible to cache gems, so that bundle install will not install bunch of gems for every build? This takes 5 minutes on every build, that is too much.

I've added this to the circle.yml config:

dependencies:
  cache_directories:
    - "/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/"

This is the common directory which is provided by bundle show gem_name where all system gems are put.

After this addition system writes such log:

restoring cache v4/company/repo_name/dependency/circle-ci/42/mGWhlYQIxyOy0GZtt4QmCw__.tar.gz
restoring home/ubuntu/repo_name/vendor/bundle, home/ubuntu/.m2, home/ubuntu/.ivy2, home/ubuntu/.go_workspace, home/ubuntu/.gradle, home/ubuntu/.rvm/gems/ruby-2.1.2/gems

So, as far as I understand, it restores system gems and gems installed into vendor/bundle, however, I still see this (and this takes a lot of time):

Installing rake 10.4.2
Installing i18n 0.7.0
Installing json 1.8.2
Installing minitest 5.5.1
...

instead of

using rake 10.4.2
using i18n 0.7.0
using json 1.8.2
using minitest 5.5.1
...

So, it seems, it should work, but it does not. What can be wrong?

解决方案

The solution is simple: CircleCI runs some commands by default and caches gems also by default in vendor/bundle, so there is no need to add anything to cache_directories.

Among those default commands is bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3, that checks presence of gems in the cache directory and installs them if they are not there.

In my case I had project consisting of multiple applications (main application, common UI, API client and API mock) split into 4 different repos. Most of them needed bundle install commands.

The only thing I had to do is to replace all my bundle install commands (that always installs gems) with bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3. In such case all gems are installed only the first time I run tests and all the following builds use previously cached gems.

这篇关于CircleCI宝石缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆