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

It’s best to switch to an overseas server Orz, domestic servers are all inaccessible

Like

If you are in a hurry to build a website, time is more important than money. If you are not in a hurry, you can fiddle with it as you please.

1 Like

Thanks for the solution. It has been resolved. Adding this to the *.yml configuration also solved the issue of not being able to download related libraries due to the registry.yarnpkg.com website having an invalid SSL certificate.

    - 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 isn’t a panacea, and you might encounter other issues later (I did, it seemed like ruby-china.com didn’t update relevant dependencies, which caused problems, but I didn’t take notes on the specific records and can’t recall them clearly).
We’ll cross that bridge when we come to it :no_mouth:

1 Like

There is indeed a difference between the dependency libraries of accelerated mirror sources and the official version. Switching to an accelerated source, such as USTC, Tsinghua, or Alibaba, Tsinghua has a smaller version difference, and USTC is the fastest. My server is in a private domain, and the public network server only forwards data, resulting in lower overall costs. The server cost is 14 yuan per month, with 2 cores (vCPU), 512 MB RAM, 20GB storage, and 80Mbps/s bandwidth (pay-as-you-go).

Your forum looks good, it seems to be related to medicine. We run a computer technology forum that enables ChatGPT usage in China. We are interested in licensing it to you for use.

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