How to make the gem installation in discourse-ai use the gem image source modified in web.china.template.yml?

problem

When I was in China, I wanted to change the gem mirror source. At discourse-ai of fork, I modified the gem mirror source information in Gemfile and gemfile. lock, but the log display was still downloaded from https://rubygems.org/. How to make the gem installation in discourse-ai use the gem image source modified in web.china.template.yml

Inevitable errors

sudo ./launcher rebuild app

I, [2023-11-10T04:40:17.388494 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    IOError: HTTP session not yet started (Gem::RemoteFetcher::FetchError)
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/remote_fetcher.rb:266:in `rescue in fetch_path'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/remote_fetcher.rb:246:in `fetch_path'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/remote_fetcher.rb:294:in `cache_update_path'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/remote_fetcher.rb:161:in `rescue in download'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/remote_fetcher.rb:146:in `download'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/source.rb:212:in `download'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/resolver/specification.rb:113:in `download'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/resolver/specification.rb:99:in `install'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/request_set.rb:281:in `block in install_into'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/request_set.rb:273:in `each'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/request_set.rb:273:in `install_into'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/request_set.rb:148:in `install'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/commands/install_command.rb:215:in `install_gem'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/commands/install_command.rb:231:in `block in install_gems'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/commands/install_command.rb:224:in `each'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/commands/install_command.rb:224:in `install_gems'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/commands/install_command.rb:170:in `execute'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/command.rb:328:in `invoke_with_build_args'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/command_manager.rb:253:in `invoke_command'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/command_manager.rb:193:in `process_args'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/command_manager.rb:151:in `run'
        /usr/local/lib/ruby/site_ruby/3.2.0/rubygems/gem_runner.rb:56:in `run'
        /usr/local/bin/gem:12:in `<main>'
I, [2023-11-10T04:49:21.015453 #1]  INFO -- : gem install tokenizers -v 0.3.3 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install

You are specifying the gem tokenizers in /var/www/discourse/plugins/discourse-ai/plugin.rb, however it does not exist!
Looked for:
- /var/www/discourse/plugins/discourse-ai/gems/3.2.2/specifications/tokenizers-0.3.3.gemspec
- /var/www/discourse/plugins/discourse-ai/gems/3.2.2/specifications/tokenizers-0.3.3-x86_64-linux.gemspec
- /var/www/discourse/plugins/discourse-ai/gems/3.2.2/specifications/tokenizers-0.3.3-x86_64-linux.gemspec



FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 885 exit 255>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 255
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
7d6d7efb62fe5cd8f1d85af89fb43a28089d4d91449fec274758f1c5ba2a589d

sudo ./launcher bootstrap web_only,This error is often encountered

Are you in China by any chance?

Yes, is there any solution

I found a solution, the plugin downloaded after the conversion gem image to install the plugin dependent library

          - gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
          - su discourse -c 'bundle config mirror.https://rubygems.org https://gems.ruby-china.com/'
          - gem install tokenizers -v 0.3.3 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
          - gem install tiktoken_ruby -v 0.0.5 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
          - gem install aws-eventstream -v 1.2.0 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
1 Like

最好换台外网的服务器Orz,国内服务器各种连不上

如果你着急建站,时间比金钱更重要,如果你不着急,可以自己随意折腾

1 Like

感谢提供的方案,已经解决了,*.yml配置中加入这个,还集成解决了registry.yarnpkg.com库网站无有效ssl证书导致无法下载相关库的问题

    - exec:
        cd: $home
        cmd:
          - gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
          - bundle config mirror.https://rubygems.org https://gems.ruby-china.com/
          - gem install tokenizers -v 0.3.3 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
          - gem install tiktoken_ruby -v 0.0.5 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
          - gem install aws-eventstream -v 1.2.0 -i /var/www/discourse/plugins/discourse-ai/gems/3.2.2 --no-document --ignore-dependencies --no-user-install
          - yarn config set registry https://registry.npmmirror.com/ --global
          - grep -rl "registry.yarnpkg.com" . | tee ./find_cache.txt | xargs sed -i "s/registry.yarnpkg.com/registry.npmmirror.com/g" && cat ./find_cache.txt && rm ./find_cache.txt

ruby-china.com并不万能,之后你可能还会遇到其他问题(我就碰到了,好像是ruby-china.com没有更新相关依赖,结果出了问题,但相关记录没做笔记,具体想不起来了)
到时候再说吧 :no_mouth:

1 Like

确实存在加速镜像源的依赖库和官方的版本存在差异,切换个加速源,中科大、清华、阿里,清华的版本差异化比较小,中科大的速度最快,我的服务器在私域,公网服务器只做数据转发,综合成本小,服务器成本一月14元,2核(vCPU) 512 MB,20GB存储,带宽80Mbps/s(按量付费)

看你做的论坛不错,像是医学相关的,我们做的是计算机技术论坛,打通了chatgpt在中国使用,有兴趣可以授权给你使用。

https://www.zeppos.tech/t/topic/7