【问题标题】:Why/how `gem fetch -s $source` differs from Bundler's `source` statement?为什么/如何`gem fetch -s $source`与Bundler的`source`语句不同?
【发布时间】:2021-10-08 13:41:15
【问题描述】:

我有一个 Bundler 设置,其中一个 gem 是从一个私有源(存储库)下载的,它通过一个环境变量进行身份验证。

这是宝石准备工作流程:

$ export MYKEY=key

$ cat >> Gemfile <<EOF
source "https://private.repository.com/" do
  gem 'mygem'
end
EOF

$ bundle package

这将获取 Gemfile 的所有 gem,并将它们存储在 vendor/cache 下;这包括宝石mygem

我想直接通过gem 工具实现这一点,而不需要 Bundler。但是,当我运行时:

$ export MYKEY=key

$ gem fetch --clear-sources -s "https://private.repository.com/" mygem

我明白了:

ERROR:  Could not find a valid gem 'mygem' (>= 0), here is why:
          Unable to download data from https://private.repository.com/ - bad response Unauthorized 401 (https://private.repository.com/other/stuff)

为什么以及如何不同?如何通过gem 工具获取 gem?

【问题讨论】:

  • 您是否设置了~/.gemrc 与您的私人仓库的凭据? Bundler 使用其配置机制来存储私有源凭据,这与 gem 使用的不同。
  • 花了我一段时间才弄明白 :) 我已经添加了解决方案。

标签: ruby rubygems bundler


【解决方案1】:

原因是gem命令没有使用环境变量进行授权;相反,身份验证令牌是 URL 的一部分:

$ gem fetch --clear-sources -s "https://token@private.repository.com/" mygem

以上方法都可以。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2017-02-27
    • 2020-01-15
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 2011-09-06
    相关资源
    最近更新 更多