cuon-araki / personal_memo

0 stars 0 forks source link

DockerのRailsコンテナでbundle installするとエラー発生 #1

Open cuon-araki opened 6 months ago

cuon-araki commented 6 months ago

障害原因

以下を実施した ※システムイメージのビルド

docker-compose up --build -d

すると、以下のエラー

docker-compose run --rm rails sh -c "bundle install && yarn install && yarn build"
[+] Creating 2/0
 ✔ Container busikul_tmnf-redis-1  Running                                                                                                                                                         0.0s 
 ✔ Container busikul_tmnf-db-1     Running                                                                                                                                                         0.0s 
Ignoring psych-5.1.2 because its extensions are not built. Try: gem pristine psych --version 5.1.2
Ignoring stringio-3.1.0 because its extensions are not built. Try: gem pristine stringio --version 3.1.0
--- ERROR REPORT TEMPLATE -------------------------------------------------------
LoadError: /usr/local/bundle/gems/psych-5.1.2/lib/psych.so: cannot open shared object file: No such file or directory - /usr/local/bundle/gems/psych-5.1.2/lib/psych.so
--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error:
https://github.com/rubygems/rubygems/search?q=%2Fusr%2Flocal%2Fbundle%2Fgems%2Fpsych-5.1.2%2Flib%2Fpsych.so++cannot+open+shared+object+file++No+such+file+or+directory+-+%2Fusr%2Flocal%2Fbundle%2Fgems%2Fpsych-5.1.2%2Flib%2Fpsych.so&type=Issues

If there aren't any reports for this error yet, please fill in the new issue form located at https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md, and copy and paste the report template above in there.
make: *** [up] Error 1
cuon-araki commented 6 months ago

解決方法

以下に記述がある もしかして、localのgemとの競合??(後で検証) https://github.com/rubygems/rubygems/issues/7523

Railsコンテナに入り、必要な処理をしてbundle installしたい

docker-compose up -d rails

起動しない

docker-compose logs rails
 busikul_tmnf git:(feature/426-1) docker-compose logs rails
rails-1  | Ignoring psych-5.1.2 because its extensions are not built. Try: gem pristine psych --version 5.1.2
rails-1  | Ignoring stringio-3.1.0 because its extensions are not built. Try: gem pristine stringio --version 3.1.0
rails-1  | /usr/local/lib/ruby/3.2.0/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
rails-1  | To eliminate this warning, please install libyaml and reinstall your ruby.
rails-1  | <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:151:in `require': /usr/local/bundle/gems/psych-5.1.2/lib/psych.so: cannot open shared object file: No such file or directory - /usr/local/bundle/gems/psych-5.1.2/lib/psych.so (LoadError)

コンテナに入った

docker-compose run --rm rails bash

コンテナで実行

root@bf239a059c3b:/busikul# ls
Dockerfile.dev  Makefile      README.md  babel.config.js  config.ru  docker-compose.yml  lib            log             ops           playwright.config.ts  redoc-static.html  storage        udcs
Gemfile         Procfile      Rakefile   bin              coverage   docs                locust         login-setup.ts  package.json  postcss.config.js     renovate.json      test_saml_idp  vendor
Gemfile.lock    Procfile.dev  app        config           db         images              locustfile.py  node_modules    playwright    public                spec               tmp            yarn.lock
root@bf239a059c3b:/busikul# rm -rf /path/lib/ruby/gems/3.3.0/
root@bf239a059c3b:/busikul# gem install bundler -v 2.5.6
Ignoring psych-5.1.2 because its extensions are not built. Try: gem pristine psych --version 5.1.2
Ignoring stringio-3.1.0 because its extensions are not built. Try: gem pristine stringio --version 3.1.0

以下の実行でもダメ

gem pristine psych --version 5.1.2
gem pristine stringio --version 3.1.0

以下で削除してみる

rm -rf /usr/local/bundle/gems/psych-5.1.2
rm -rf /usr/local/lib/ruby/gems/3.2.0/gems/psych-5.1.2

これが消せているわけではない、、

bundle exec gem uninstall psych -v 5.1.2
Could not find

むしろ bundle installを実行。できてそう、、

Installing stringio 3.1.0 with native extensions
Installing psych 5.1.2 with native extensions

できた。gemを指定せずに、bundle installすればよかった。。

cuon-araki commented 6 months ago

以下で対応できた

docker-compose run --rm rails bash  (コンテナに入る)
rm -rf /usr/local/bundle/gems/psych-5.1.2
rm -rf /usr/local/lib/ruby/gems/3.2.0/gems/psych-5.1.2
bundle install
cuon-araki commented 6 months ago

/usr/local/bundle/gems 全てのRubyバージョンにインストールされた RubyGems のローカル キャッシュ /usr/local/lib/ruby/gems/3.2.0/gems/ Ruby3.2.0にインストールされている RubyGems のローカル キャッシュ

cuon-araki commented 6 months ago

新たにimage buildし、compose upすると、以下のエラー。

LoadError: /usr/local/bundle/gems/stringio-3.1.0/lib/stringio.so: cannot open shared object file: No such file or directory - /usr/local/bundle/gems/stringio-3.1.0/lib/stringio.so

以下で解決 rm -rf /usr/local/bundle/gems/stringio-3.1.0

cuon-araki commented 6 months ago

上記のようにディレクトリを消すのではなく、uninstallコマンドを使うのが良い。

今回は、volumeを消すことで解決。 container 作るときにbindされていたようだ。