【问题标题】:Gitlab CI: bundle could not find in locally installed gemsGitlab CI:在本地安装的宝石中找不到捆绑包
【发布时间】:2022-11-10 17:28:39
【问题描述】:

我有一个非常简单的 GitLab CI 设置:

  1. 每个分支运行一次作业,为我的测试创建backoffice image。这个想法是通过创建自定义 docker-image 来做一次重复的工作以节省资源。这包含使用aptgembundle 安装库。
  2. 有了backoffice image,我执行了所有的测试。这运行得非常快,因为所有库都已安装在我的自定义映像中。没有下载。好的。

    当我建造它时,它工作得很好。

    现在,几周后,我回到它,它坏了。测试抱怨缺少宝石:

    /usr/local/bundle/gems/bundler-2.3.23/lib/bundler/definition.rb:508:in `materialize': 
    Could not find
     passenger-6.0.14,
     sinatra-2.2.1,
     sinatra-contrib-2.2.1,
     haml-5.2.2,
     mustermann-1.1.2,
     rack-protection-2.2.1,
     tilt-2.0.10 
    in locally installed gems (Bundler::GemNotFound)
    

    虽然我的自定义 backoffice image 显示一切都已正确安装:

    + bundle install
    Fetching gem metadata from https://rubygems.org/............
    Resolving dependencies...
    [... stuff removed]
    Installing passenger 6.0.15 with native extensions
    Fetching rack-protection 3.0.2
    Installing rack-protection 3.0.2
    Fetching sinatra 3.0.2
    Installing sinatra 3.0.2
    Fetching sinatra-contrib 3.0.2
    Installing sinatra-contrib 3.0.2
    Bundle complete! 6 Gemfile dependencies, 16 gems now installed.
    

    什么破了?

【问题讨论】:

    标签: ruby-on-rails ruby continuous-integration rubygems bundler


    【解决方案1】:

    tl;博士:

    安装和运行必须使用相同的Gemfile.lock - 或者根本不使用。

    原因

    你们中的鹰眼可能马上就发现了问题。版本不同:

    passenger-6.0.15 已安装与 passenger-6.0.14 需要。

    问题的根源是Gemfile.lock 在不同的上下文中建议here

    创建backoffice image 时,我复制了Gemfile,但没有复制Gemfile.lock。如果没有锁定文件,bundle 将安装与Gemfile 中相当宽松的说明匹配的最新版本。

    但是用于测试的执行环境有一个Gemfile.lock,它请求所有已安装gem 的特定版本。

    的背景

    当设置是新的时,安装了最新最好的。然后bundle 将创建锁定文件。因此,即使没有锁定文件的严格说明,简单的Gemfile 也将采用相同的设置——目前。

    几周后,gem 出现了更新版本,最新最好的版本与包含的Gemfile.lock 锁定的版本不同。这导致 CI​​ 管道失败,并出现这个相当通用的错误消息。因果相距甚远让我很头疼,我想通过写这篇具体的文章来拯救你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多