RubyGems proxy
RubyGems 好像不能支持 socks5h 协议,所以我在 Colima镜像 构建时, mise 使用了 socks5h 代理:
RUN --mount=type=bind,source=mise_proxy.env,target=/home/admin/mise_proxy.env \
set -a && . /home/admin/mise_proxy.env && set +a && \
mise use --global cmake@latest && \
mise use --global rust@stable && \
mise use --global go@1.26 && \
mise use --global python@3.14 && \
mise use --global ruby@3 && \
gem install --no-document rails && \
mise use --global neovim@stable
执行 gem install rails 如果继续采用 mise代理 代理配置会报错
采用
socks5h 协议时gem install报错...
723.5 mise ruby@3.4.9 ✓ installed
723.6 mise ~/.config/mise/config.toml tools: ruby@3.4.9
724.5 ERROR: Could not find a valid gem 'rails' (>= 0), here is why:
724.5 Unable to download data from https://rubygems.org/ - Socket::ResolutionError: Failed to open TCP connection to socks5h:80 (getaddrinfo(3): Name or service not known) (https://rubygems.org/specs.4.8.gz)
------
Dockerfile:99
--------------------
98 | # 采用动态挂载
99 | >>> RUN --mount=type=bind,source=mise_proxy.env,target=/home/admin/mise_proxy.env \
100 | >>> set -a && . /home/admin/mise_proxy.env && set +a && \
101 | >>> mise use --global cmake@latest && \
102 | >>> mise use --global rust@stable && \
103 | >>> mise use --global go@1.26 && \
104 | >>> mise use --global python@3.14 && \
105 | >>> mise use --global ruby@3 && \
106 | >>> gem install --no-document rails && \
107 | >>> mise use --global neovim@stable
108 |
--------------------
error: failed to solve: process "/bin/sh -c set -a && . /home/admin/mise_proxy.env && set +a && mise use --global cmake@latest && mise use --global rust@stable && mise use --global go@1.26 && mise use --global python@3.14 && mise use --global ruby@3 && gem install --no-document rails && mise use --global neovim@stable" did not complete successfully: exit code: 2
FATA[0910] no image was built
当需要gem支持代理时,可以使用 --http-proxy 参数来传递 http / https 等代理参数,但是这里的协议不支持 socks5 / socks5h 协议
采用http代理来使用gem install
gem install --http-proxy http://127.0.0.1:3128 --no-document rails
我尝试过采用 SSH Tunneling: 动态端口转发 构建的 socks 代理,但是出现报错:
gem install 不支持 socks 协议报错941.4 mise ~/.config/mise/config.toml tools: ruby@3.4.9
942.4 ERROR: While executing gem ... (ArgumentError)
942.4 Invalid uri scheme for socks://192.168.5.2:1080
942.4 Preface URLs with one of ["http://", "https://", "file://", "s3://"]
942.4
942.4 raise ArgumentError, msg
942.4 ^^^^^^^^^^^^^^^^^^
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/local_remote_options.rb:30:in 'block in Gem::LocalRemoteOptions#accept_uri_http'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:587:in 'Gem::OptionParser::Switch#conv_arg'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:789:in 'Gem::OptionParser::Switch::PlacedArgument#parse'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1732:in 'block in Gem::OptionParser#parse_in_order'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1709:in 'Kernel#catch'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1709:in 'Gem::OptionParser#parse_in_order'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1703:in 'Gem::OptionParser#order!'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1830:in 'Gem::OptionParser#permute!'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/vendor/optparse/lib/optparse.rb:1855:in 'Gem::OptionParser#parse!'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/command.rb:444:in 'Gem::Command#handle_options'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/command.rb:312:in 'Gem::Command#invoke_with_build_args'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/command_manager.rb:253:in 'Gem::CommandManager#invoke_command'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/command_manager.rb:194:in 'Gem::CommandManager#process_args'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/command_manager.rb:152:in 'Gem::CommandManager#run'
942.4 /home/admin/.local/share/mise/installs/ruby/3.4.9/lib/ruby/3.4.0/rubygems/gem_runner.rb:57:in 'Gem::GemRunner#run'
942.4 /home/admin/.local/share/mise/installs/ruby/3/bin/gem:12:in '<main>'
------
Dockerfile:99
--------------------
如果确实无法构建良好的http代理,那么可以尝试使用国内的gem CDN加速,能够解决GFW阻塞问题:
使用国内提供的CDN加速源
# ========================================================
# 临时切换到国内顶级 CDN 加速源,绕过任何 SOCKS5 限制
# ========================================================
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ && \
# 此时不需要传任何 --http-proxy 参数,肉身直接无痛秒杀 rails 的下载
gem install --no-document rails && \
# 恢复原厂设置(可选,为了保持镜像分发后在海外等其他环境的通用性)
gem sources --add https://rubygems.org/ --remove https://gems.ruby-china.com/