実現したいこと前提
現在railsアプリをdocker開発環境で頑張って作成しています。
本番環境のデータベース はRDSです。
bundle exec cap production deploy
を実行したら以下のようなエラーに
なりました。
RDSのMySQLは8系でdocker開発環境は5.7なのでそこら辺も関係あるかもしれません。
[追記]
db: image: mysql:8.0.21 environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_HOST: db ports: - '3306:3306' volumes: - ./tmp/db:/var/lib/mysql command: --default-authentication-plugin=mysql_native_password
こんな感じでdocker-compose.ymlを編集して、buildし直したら上手く立ち上がって、その後、再度bundle exec cap production deployを実行しましたが、エラー内容変わりませんでした。
エラー内容
/Users/soichirohara/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/sshkit-1.21.2/lib/sshkit/command.rb:97:in `exit_status=': rake exit status: 1 (SSHKit::Command::Failed) rake stdout: Nothing written rake stderr: rake aborted! LoadError: libmysqlclient.so.18: cannot open shared object file: No such file or directory - /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.so /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<main>' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /var/www/coffee_passport/releases/20210511045750/config/application.rb:7:in `<top (required)>' /var/www/coffee_passport/releases/20210511045750/Rakefile:4:in `require_relative' /var/www/coffee_passport/releases/20210511045750/Rakefile:4:in `<top (required)>' /var/www/coffee_passport/shared/bundle/ruby/2.6.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>' /home/ec2-user/.rbenv/versions/2.6.5/bin/bundle:23:in `load' /home/ec2-user/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
capistrano.log
のエラーログもこんな感じだったので、teratailは1000字以内で入力しなければならないので、必要であれば共有したいと思います。
該当のソースコード
database.yml
default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: <%= ENV['MYSQL_ROOT_PASSWORD'] %> socket: /tmp/mysql.sock host: <%= ENV['MYSQL_HOST'] || 'localhost' %> development: <<: *default database: coffee_passport_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: coffee_passport_test # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: coffee_passport_production username: root password: <%= ENV['MYSQL_ROOT_PASSWORD'] %> host: cp-mysql.c3sv1rwobfad.ap-northeast-1.rds.amazonaws.com
Gemfile
source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.5' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '6.1.3.1' # Use mysql as the database for Active Record gem 'mysql2', '>= 0.4.4' # Use Puma as the app server gem 'puma', '~> 3.11' # Use SCSS for stylesheets gem 'sass-rails', '~> 5' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 4.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'rspec-rails' gem 'factory_bot_rails' gem 'faker' gem 'capistrano' gem 'capistrano-rbenv' gem 'capistrano-bundler' gem 'capistrano-rails' gem 'capistrano3-unicorn' end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' gem 'rubocop', require: false end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 2.15' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' gem 'launchy' end group :production do gem 'unicorn', '5.4.1' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'pry-rails' gem "mimemagic" gem 'image_processing', '~> 1.2' gem 'active_hash' gem 'payjp' gem 'ransack' gem 'will_paginate', '3.1.8' gem 'bootstrap-will_paginate', '1.0.0' gem "jquery-rails" gem 'omniauth-twitter' gem 'omniauth-facebook' gem 'omniauth-google-oauth2' gem 'omniauth-rails_csrf_protection' gem 'oauth2' gem "aws-sdk-s3", require: false gem 'faker' gem 'dotenv-rails' # rack のアップデートのバグで画像が上手く開いてくれない見たいなので、グレードダウン(近々修正くるらしい) gem 'rails-i18n'
試したこと
私の行った手順は以下です。
(1)
sudo yum install libmysqlclient.so.18
を実行したら
sudo: yum: command not found
とエラーが出たので
brew install yum
を実行。
==> Searching for similarly named formulae... Error: No similarly named formulae found. Error: No available formula or cask with the name "yum". ==> Searching for a previously deleted formula (in the last month)... Error: No previously deleted formula found. ==> Searching taps on GitHub... Error: No formulae found in taps.
docker-compose exec web apt-get install libmysqlclient.so.18
を実行したら
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libmysqlclient.so.18 E: Couldn't find any package by glob 'libmysqlclient.so.18' E: Couldn't find any package by regex 'libmysqlclient.so.18'
このようなエラーが返ってきました。
(2)
bundle update
を実行しましたがエラー内容は変わらずでした。
(3)
dokcer-compose exec web gem uninstall mysql2
gem uninstall mysql2
gem install
どっちも行いましたが、エラー内容は変わりませんでした。
soichirohara@SoichironoMacBook-Pro coffee_passport % docker-compose exec web apt-get install mysql-devel Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package mysql-devel
yum installができないので、このようなコマンドを実行しましたが上手く行っていないように思えます。
そもそも、本番環境のデータベース はRDSなので、自分のアプローチが何か間違ってるかもしれません。。。
環境
各環境は
このアプリのGithub
お手数ですが、こちらのreadMeをご確認お願い申し上げます。