tky529
@tky529 (タクタク)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Rails自動デプロイ中のSSHKit::Runner::ExecuteError

○期待する動作

http://www.onseo.info/articles/11
の記事をそのままコピー&ペーストして自動デブロイのやり方を学んでいます。
 

○エラーの内容(抜粋)

macuser@mac-no-MacBook-Air blog-app % bundle exec cap production deploy

を実施後EC2のElasticIPを開くと
502 Bad Gateway(nginx/1.16.1)と表示されます.
以下ターミナル上のエラー内容です。(AWSへのSSH接続は問題なくできています。)
(途中省略)
00:11 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
 terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from /Users/macuser/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/macuser/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@AMAZONEEC2のアドレス: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: Nothing written
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@MAZONEEC2のアドレス: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as ec2-user@AMAZONEEC2のアドレス: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
INFO [9e1dfe41] Running $HOME/.rbenv/bin/rbenv exec bundle config --local path /var/www/blog-app/shared/bundle as ec2-user@AMAZONEEC2のアドレス

 DEBUG [9e1dfe41] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle config --local path /var/www/blog-app/shared/bundle )
  INFO [9e1dfe41] Finished in 0.293 seconds with exit status 0 (successful).
  INFO [3b1fed01] Running $HOME/.rbenv/bin/rbenv exec bundle config --local without development:test as ec2-user@AMAZONEEC2のアドレス
 DEBUG [3b1fed01] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle config --local without development:test )
  INFO [3b1fed01] Finished in 0.299 seconds with exit status 0 (successful).
 DEBUG [825050c9] Running if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi as ec2-user@52.193.111.3
 DEBUG [825050c9] Command: if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi
 DEBUG [825050c9] Finished in 0.103 seconds with exit status 0 (successful).
 DEBUG [526cdd54] Running $HOME/.rbenv/bin/rbenv exec bundle check as ec2-user@AMAZONEEC2のアドレス
 DEBUG [526cdd54] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle check )
 DEBUG [526cdd54]       The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
 DEBUG [526cdd54]       The Gemfile's dependencies are satisfied
 DEBUG [526cdd54] Finished in 0.428 seconds with exit status 0 (successful).
  INFO The Gemfile's dependencies are satisfied, skipping installation
 DEBUG [2ef0f040] Running if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi as ec2-user@AMAZONEEC2のアドレス
 DEBUG [2ef0f040] Command: if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi
 DEBUG [2ef0f040] Finished in 0.100 seconds with exit status 0 (successful).
  INFO [60b7bf95] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as ec2-user@52.193.111.3
 DEBUG [60b7bf95] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
○該当箇所
require 'thread'
module SSHKit
  module Runner
    class Parallel < Abstract
      def execute
        threads = hosts.map do |host|
          Thread.new(host) do |h|
            begin
              backend(h, &block).run
            rescue ::StandardError => e
              e2 = ExecuteError.new e
              raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
            end
          end
        end
        threads.each(&:join)
      end
    end
  end
end

 

○試したこと

サーバーの再起動(参考https://qiita.com/aoitrain/items/90036ec9c24f0566711e)
GitHubへの再PUSH
AWSへSSH接続後、rake secretを再実行

見づらい文章ですみません。
その他足りないところがありましたら追記させていただきます。
一日調べても解決策が見つからず困っております。
どうぞよろしくお願いいたします。

0

2Answer

リモートサーバで rake assets:precompile の実行に失敗したことを SSHKit が報告しているようです。正確には、ログの最後に出ているとおり

cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

が失敗しています。リモートサーバに手動で SSH して上記のコマンドを入力すればエラーメッセージを確認できると思います。

3Like

Comments

  1. @tky529

    Questioner

    ありがとうございます。rake assets:precompileをすると以下のエラーがでました。
    調べてみたいと思います。原因がわかってきて嬉しいです。
    (省略)
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_utils_ext.rb:17: warning: previous definition of DEFAULT was here
    WARNING: Possible conflict with Rake extension: String#ext already exists
    WARNING: Possible conflict with Rake extension: String#pathmap already exists
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:44: warning: already initialized constant Rake::FileList::ARRAY_METHODS
    (省略)
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake.rb:71: warning: previous definition of RakeFileUtils was here
    rake aborted!
    LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    (省略)
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'

    Caused by:
    LoadError: cannot load such file -- listen
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    (省略)
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
    Tasks: TOP => environment
    (See full trace by running task with --trace)
  2. listen gem がインストールされていないエラーですね。質問文の Capistrano の実行ログを見ると `bundle config --local without development:test` が実行されています。これは Gemfile の development グループと test グループに含まれる gem をインストールしないようにする設定です。 listen gem も development グループに含まれるのでインストールされなくなります。 bundle config を実行しないようにすればよさそうです。(そうすると Gemfile の gem がすべてインストールされます)
  3. いや、 Gemfile 内の `gem 'listen', ...` 行を development グループの外に出して常にインストールされるようにするだけでいいかも。 production 環境で必要な gem が development グループに入っているほうがおかしいので。
  4. @tky529

    Questioner

    何度もありがとうございます。 Gemfile内の`gem 'listen'を外に出して見るとLoadErrorは無くなったのですがまだ同様のところでデプロイが止まってしまいます。他のdevelopment グループと test グループに含まれる gem をインストールしても同様でした(gem 'web-console', '>= 3.3.0'はmistakeと言われてしまうのでdevelopmentグループの外に出してあります)
    再度 exec rake assets:precompileを実行すると下記のようなエラーになります。大変申し訳ないのですが対応の仕方が分からないので初めだけでも対応の仕方を教えていただけたら幸いです。
    [ec2-user@ip-000-000-000-000 20200910123618]$ exec rake assets:precompile
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_utils.rb:10: warning: already initialized constant FileUtils::RUBY
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_utils.rb:10: warning: previous definition of RUBY was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_utils.rb:108: warning: already initialized constant FileUtils::LN_SUPPORTED
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_utils.rb:108: warning: previous definition of LN_SUPPORTED was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_utils_ext.rb:17: warning: already initialized constant Rake::FileUtilsExt::DEFAULT
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_utils_ext.rb:17: warning: previous definition of DEFAULT was here
    WARNING: Possible conflict with Rake extension: String#ext already exists
    WARNING: Possible conflict with Rake extension: String#pathmap already exists
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:44: warning: already initialized constant Rake::FileList::ARRAY_METHODS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:44: warning: previous definition of ARRAY_METHODS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:47: warning: already initialized constant Rake::FileList::MUST_DEFINE
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:47: warning: previous definition of MUST_DEFINE was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:51: warning: already initialized constant Rake::FileList::MUST_NOT_DEFINE
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:51: warning: previous definition of MUST_NOT_DEFINE was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:55: warning: already initialized constant Rake::FileList::SPECIAL_RETURN
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:55: warning: previous definition of SPECIAL_RETURN was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:61: warning: already initialized constant Rake::FileList::DELEGATING_METHODS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:61: warning: previous definition of DELEGATING_METHODS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:86: warning: already initialized constant Rake::FileList::GLOB_PATTERN
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:86: warning: previous definition of GLOB_PATTERN was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:381: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PATTERNS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:381: warning: previous definition of DEFAULT_IGNORE_PATTERNS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:387: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PROCS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/file_list.rb:387: warning: previous definition of DEFAULT_IGNORE_PROCS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:3: warning: already initialized constant Rake::VERSION
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:3: warning: previous definition of VERSION was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MAJOR
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: previous definition of MAJOR was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MINOR
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: previous definition of MINOR was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::BUILD
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: previous definition of BUILD was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::OTHER
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:6: warning: previous definition of OTHER was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:8: warning: already initialized constant Rake::Version::NUMBERS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/version.rb:8: warning: previous definition of NUMBERS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/linked_list.rb:110: warning: already initialized constant Rake::LinkedList::EMPTY
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/linked_list.rb:110: warning: previous definition of EMPTY was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/scope.rb:41: warning: already initialized constant Rake::Scope::EMPTY
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/scope.rb:41: warning: previous definition of EMPTY was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/promise.rb:12: warning: already initialized constant Rake::Promise::NOT_SET
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/promise.rb:12: warning: previous definition of NOT_SET was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/application.rb:13: warning: already initialized constant Rake::CommandLineOptionError
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/application.rb:13: warning: previous definition of CommandLineOptionError was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/application.rb:41: warning: already initialized constant Rake::Application::DEFAULT_RAKEFILES
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/application.rb:41: warning: previous definition of DEFAULT_RAKEFILES was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/task_arguments.rb:108: warning: already initialized constant Rake::EMPTY_TASK_ARGS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/task_arguments.rb:108: warning: previous definition of EMPTY_TASK_ARGS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/invocation_chain.rb:55: warning: already initialized constant Rake::InvocationChain::EMPTY
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/invocation_chain.rb:55: warning: previous definition of EMPTY was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/early_time.rb:21: warning: already initialized constant Rake::EARLY
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/early_time.rb:21: warning: previous definition of EARLY was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/late_time.rb:17: warning: already initialized constant Rake::LATE
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/late_time.rb:17: warning: previous definition of LATE was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:4: warning: already initialized constant Rake::Backtrace::SYS_KEYS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:4: warning: previous definition of SYS_KEYS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:5: warning: already initialized constant Rake::Backtrace::SYS_PATHS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:5: warning: previous definition of SYS_PATHS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:8: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:8: warning: previous definition of SUPPRESSED_PATHS was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:12: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS_RE
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:12: warning: previous definition of SUPPRESSED_PATHS_RE was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:16: warning: already initialized constant Rake::Backtrace::SUPPRESS_PATTERN
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake/backtrace.rb:16: warning: previous definition of SUPPRESS_PATTERN was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake.rb:70: warning: already initialized constant FileList
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake.rb:70: warning: previous definition of FileList was here
    /var/www/blog-app/shared/bundle/ruby/2.5.0/gems/rake-13.0.1/lib/rake.rb:71: warning: already initialized constant RakeFileUtils
    /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-13.0.1/lib/rake.rb:71: warning: previous definition of RakeFileUtils was here
  5. なぜか Rake を2回読み込んでいるようで警告がたくさん出ていますがエラーはないですね。ログはそれで全部でしょうか?どこかに rake aborted! と出ていればそれ以降の出力を貼ってください。
  6. @tky529

    Questioner

    はい。ログは全てになります。
    探してみたのですがそのようなエラーはありませんでした。
    一応Gemfileのログになります。こちらで何かわかりますでしょうか?
    development グループと test グループはコメントアウトして全て実行してもコメントアウトせずグループ内に入れても同じでした。
    source 'https://rubygems.org'
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }

    ruby '2.5.1'

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
    # Use mysql as the database for Active Record
    gem 'mysql2', '>= 0.4.4'
    # Use Puma as the app server
    gem 'puma', '~> 4.1'
    # Use SCSS for stylesheets
    gem 'sass-rails', '>= 6'
    # 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]
    #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'
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    end
    gem 'listen', '~> 3.2'
    gem 'spring'
    gem 'spring-watcher-listen', '~> 2.0.0'

    #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'
    #end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

    group :production do
    gem 'unicorn', '5.4.1'
    end

    #group :development, :test do
    gem 'capistrano'
    gem 'capistrano-rbenv'
    gem 'capistrano-bundler'
    gem 'capistrano-rails'
    gem 'capistrano3-unicorn'
    gem 'pry-rails'
    #end
  7. Gemfile は問題なさそうです。リモートで実行したコマンドが exec rake assets:precompile だとするとうまくいかないかもしれません。

    ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

    これでどうですか?
  8. @tky529

    Questioner

    大変助かります。加えて素人な質問申し訳ありません。
    デプロイ時にexec rake assets:precompileを実行させるにはどのファイルを変えれば良いのでしょうか?
    HOME/.rbenv/bin/rbenvにもそれらしい記述がなかったです。「rake assets:」の記述をローカルのファイル又はAWS上のファイルも検索をかけたりしたのですが該当するものがありませんでした。
  9. - ローカルで bundle exec cap production deploy を実行するとデプロイタスクの一部としてリモートで $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile が実行されます。手動で設定する必要はありません。

    - この設定は capistrano-rails gem が提供しています。 https://github.com/capistrano/rails/search?q=precompile&unscoped_q=precompile

    - exec rake assets:precompile と $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile は意味が違います。手動でコマンドを実行するときは正確に書いてください。
  10. 補足しますと、 rbenv は Ruby 環境を複数インストールして切り替えられるようにするソフトウェアです。 `rbenv exec ...` は現在有効な Ruby で ... 以降のコマンドを実行します。 `bundle exec ...` は Gemfile で設定された gem をロードしたうえで ... 以降のコマンドを実行します。

    合わせると、 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile は現在有効な Ruby で Gemfile の gem をロードして rake assets:precompile を実行します。

    一方で、 exec rake assets:precompile はシステムにプリインストールされた Ruby と gem
    で rake assets:precompile を実行します。(rbenv をロードするシェル設定が済ませてあれば別ですが)
  11. @tky529

    Questioner

    大変失礼しました。また勉強不足で申し訳ありません。詳しくありがとうございます。
    改めてAWSへSSH接続(リモート接続)をしてcd /var/www/blog-app/releases/20200913033842 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile ) を実行してみたら何もエラーがなく終わりました。
    [ec2-user@ip-172-00-00-00 ~]$ cd /var/www/blog-app/releases/20200913033842 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile)
    [ec2-user@ip-172-00-00-00 20200913033842]$

    ただやはりリモート接続せずローカルのフォルダ(~/projects/blog-app/)で「sudo bundle exec cap production deploy 」をすると質問文と変わらないエラーが出てしまいます、、
    すみませんがなぜローカルからやるとダメなのかわかりません。逆ならなんとくイメージできそうですが
  12. うーん、一応確認ですが、 Gemfile はローカルのものも書き換えましたか? リモートで書き換えただけだと次のデプロイには反映されないので。

    それとローカルで bundle exec するとき sudo は必要ないはずです。
  13. @tky529

    Questioner

    ありがとうございます。はい。ローカルも書き換えた上でsudo なしのbundle exec cap production deployでやっても同様のエラーでした。
    ここまで教えていただいて大変申し訳ないのですが、これ以上@usai様の貴重なお時間を奪ってしまうのは申し訳ないので一旦ここで本作業は中止いたしと思います。
    もっと勉強してから再度挑戦したいと思います。再挑戦して完了した場合はこちらにご報告させていただきたいと思います。
    貴重なお時間いただきまして本当にありがとうございます。

Comments

  1. @tky529

    Questioner

    ありがとうございます。
    bundle update net-sshを入力したのですが
    Bundler attempted to update net-ssh but its version stayed the same
    Bundle updated!
    となり変わらずエラーになってしまいました。記事の方もしっかり読んで見たいと思います。

Your answer might help someone💌